Jump to content
  • 0
Sign in to follow this  
snowflake1963

Need a @sleep script for Hercules

Question

Hello All ^^

 

I have a script for @sleep that I used with rAthena and tried it here and failed :(

I really like this command and would like to use it still.

 

Here is my script:

 


/*
*===================================
* Sleep (@sleep)
*-----------------------------------
*/

ACMD_FUNC(sleep){

  if (agit_flag) // skill not useable in WOE [A17kaliva]
  {
clif_displaymessage(fd, "Cannot use this command during WOE.");
return -1;
  }
  if(!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > 10) {
  if(sd->sc.opt1 != 0 && sd->sc.opt1 != OPT1_SLEEP){
clif_displaymessage(fd, msg_txt(sd,807));
  return -1;
  }
  if(sd->sc.opt1 != OPT1_SLEEP){
sc_start(NULL,&sd->bl, SC_TRICKDEAD, 100, 1, 1000);
sd->sc.opt1 = OPT1_SLEEP;
//sc_start(NULL,&sd->bl, SC_COMA,100,1,skill_get_time2(185,1));
clif_displaymessage(fd, msg_txt(sd,805)); // sleeping
  } else {
sd->sc.opt1 = 0;
clif_emotion(&sd->bl,45);
status_change_end(&sd->bl, SC_TRICKDEAD, -1);
//sc_start(NULL,&sd->bl, SC_COMA,100,1,skill_get_time2(185,1));
clif_displaymessage(fd, msg_txt(sd,806)); // awake
  }

clif_changeoption(&sd->bl);
  return 0;
  }
clif_displaymessage(fd, msg_txt(sd,807));
  return -1;
}
 

 

Can anyone PLEASE help me to make this work?

Share this post


Link to post
Share on other sites

36 answers to this question

Recommended Posts

  • 0

 

Hello Annie, its me again :)

 

I updated my server around the 10th of August 2014 and got this error messages from my compiler

3>  at_sleep.c3>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(30): warning C4013: 'DIFF_TICK' undefiniert; Annahme: extern mit Rückgabetyp int3>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(30): error C2065: 'timer': nichtdeklarierter Bezeichner3>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(30): error C2223: Der linke Teil von '->gettick' muss auf eine Struktur/Union zeigen3>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(57): error C2065: 'timer': nichtdeklarierter Bezeichner3>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(57): warning C4047: '=': Anzahl der Dereferenzierungen bei 'int' und 'void *' unterschiedlich

Sorry for the german text, its just what my compiler gives me, cause my computer has a german windows.

 

How can I fix this problem ?

 

I am using the plugin you gave me.

 

Thanks in advance

 

Snowflake

try to add a line  #include "../common/timer.h"  on the header

Will try it and tell the result.

 

Thank You :D

Share this post


Link to post
Share on other sites
  • 0

Here the result, sadly its an error again:

1>------ Neues Erstellen gestartet: Projekt: at_sleep, Konfiguration: Debug Win32 ------1>  at_sleep.c1>     Bibliothek "..pluginsat_sleep.lib" und Objekt "..pluginsat_sleep.exp" werden erstellt.1>at_sleep.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_battle_config".1>..pluginsat_sleep.dll : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.========== Alles neu erstellen: 0 erfolgreich, Fehler bei 1, 0 übersprungen ==========

I can not find _battle_config in the @sleep script. There is only a !battle_config. This confuses me a bit.

 

Thanks in advance

 

Snowflake :)

Share this post


Link to post
Share on other sites
  • 0

Here the result, sadly its an error again:

1>------ Neues Erstellen gestartet: Projekt: at_sleep, Konfiguration: Debug Win32 ------1>  at_sleep.c1>     Bibliothek "..pluginsat_sleep.lib" und Objekt "..pluginsat_sleep.exp" werden erstellt.1>at_sleep.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_battle_config".1>..pluginsat_sleep.dll : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.========== Alles neu erstellen: 0 erfolgreich, Fehler bei 1, 0 übersprungen ==========

I can not find _battle_config in the @sleep script. There is only a !battle_config. This confuses me a bit.

 

Thanks in advance

 

Snowflake :)

coz  you had patched wrong file

 

here is the plugin file

plugin

http://upaste.me/6611107511ac763ee

Share this post


Link to post
Share on other sites
  • 0

Hello Angelmelody,

 

all I did was adding #include "../common/timer.h" to the existing C++ code for the plugin.

 

I will try the plugin you posted now. Results will follow.

 

Mfg

Snowflake

 


 

Hello Angelmelody,

 

here the result of the script you posted.

1>------ Neues Erstellen gestartet: Projekt: at_sleep, Konfiguration: Debug Win32 ------1>  at_sleep.c1>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(27): warning C4013: 'DIFF_TICK' undefiniert; Annahme: extern mit Rückgabetyp int1>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(27): error C2065: 'timer': nichtdeklarierter Bezeichner1>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(27): error C2223: Der linke Teil von '->gettick' muss auf eine Struktur/Union zeigen1>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(54): error C2065: 'timer': nichtdeklarierter Bezeichner1>c:transfersnowhercules serverhercules trunksrcpluginsat_sleep.c(54): warning C4047: '=': Anzahl der Dereferenzierungen bei 'int' und 'void *' unterschiedlich========== Alles neu erstellen: 0 erfolgreich, Fehler bei 1, 0 übersprungen ==========

Mfg

Snowflake

 


 

Hello :) ,

 

added #include "../common/timer.h" to the script / plugin. => Compile was fine, no errors.

 

Server started without problems, but when using the command I get following message in the client:

Please refrain from trying to abuse this command@sleep failed

Mfg

Snowflake

 


 

Hello :) ,

 

I tested a bit, as far as my knowledge goes, and got this script now:

#include <stdio.h>#include <stdlib.h>#include <string.h>#include "../map/pc.h"#include "../common/timer.h"#include "../common/HPMi.h"#include "../common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time)HPExport struct hplugin_info pinfo = {	"sleep",		// Plugin name	SERVER_TYPE_MAP,// Which server types this plugin works with?	"0.1",			// Plugin version	HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)};/**===================================* Sleep (@sleep)*-----------------------------------*/ACMD(sleep) {	if ( map->agit_flag || map->agit2_flag ) { // skill not useable in WOE [A17kaliva]		clif->message( fd, "Cannot use this command during WOE." );		return false;	}	if ( !battle->bc->prevent_logout || DIFF_TICK( timer->gettick(), sd->canlog_tick) < battle->bc->prevent_logout ) {		if ( sd->sc.opt1 != 0 && sd->sc.opt1 != OPT1_SLEEP ) {			clif->message( fd, msg_txt(807) ); // abuse ?			return false;		}		if ( sd->sc.opt1 != OPT1_SLEEP) {			status->change_start( NULL, &sd->bl, SC_TRICKDEAD, 10000, 1, 0, 0, 0, 1000, 0);			sd->sc.opt1 = OPT1_SLEEP;			clif->message( fd, msg_txt(805) ); // sleeping		} else {			sd->sc.opt1 = 0;			clif->emotion(&sd->bl,45);			status_change_end(&sd->bl, SC_TRICKDEAD, -1);			clif->message( fd, msg_txt(806) ); // awake					}		clif->changeoption( &sd->bl );		return true;	}	clif->message( fd, msg_txt(808) );	return false;}HPExport void plugin_init (void) {	atcommand = GET_SYMBOL("atcommand");	clif = GET_SYMBOL("clif");	map = GET_SYMBOL("map");	timer = GET_SYMBOL("timer");	status = GET_SYMBOL("status");	battle = GET_SYMBOL("battle");	addAtcommand("sleep",sleep);}

I also added a line ( 808 ) to msg_conf.txt to see in which case the scripts shows up the abuse message:

//------------------------------------// More atcommands message//------------------------------------//@sleep805: You went to sleep now.806: You are waking up now.807: Please refrain from trying to abuse this command.808: You can not sleep during a battle.

I assume message 808 is displayed while fighting a monster.

 

My problem now is:

The character is in town, NOT FIGHTING anything and standig. Typing @sleep gives back the new message.

You can not sleep during a battle.@sleep failed

Based on my knowledge from BASIC and PHP I think the bug is somwehere in the line:

if ( !battle->bc->prevent_logout || DIFF_TICK( timer->gettick(), sd->canlog_tick) < battle->bc->prevent_logout ) {

At this point I need help, cause I don't understand what !battle->bc->prevent_logout and battle->bc->prevent_logout mean or do. Special those " -> "

 

Maybe the actual code uses an other way to read or store a variable ??? so this plugin cannot read that variable ???

Or a different variable ???

 

Mfg

Snowflake

Edited by AnnieRuru

Share this post


Link to post
Share on other sites
  • 0

srry, I dunno what happened..

 

Are there 2 sleep command existing at the same time(one in atcommand.c the other in plugin)?

Share this post


Link to post
Share on other sites
  • 0

Hello Annie,

 

the new plugin work fine. No errors when compiling and it works. Great Job :no1:

 

BTW: I would like to know what is different between the two scripts. The one I created out of Angelmelody's and yours.

I am just curious and like to learn a bit more about C/C++. :)

 

Is it really just the fact that this line

if ( battle->bc->prevent_logout && ( DIFF_TICK( timer->gettick(), sd->canlog_tick ) < battle->bc->prevent_logout ) ) ...

has 4 brackets more then Angelmelody's ? Is the logic really that "sensitive" ?

 

Mfg

 

Snowflake

Share this post


Link to post
Share on other sites
  • 0

srry, I dunno what happened..

 

Are there 2 sleep command existing at the same time(one in atcommand.c the other in plugin)?

 

Hello Angelmelody,

 

there is only one @sleep command and its in the plugin. IMO this plugin-thingy is really usefull. You don't have to mess with the original code in atcommand.c.

 

I think all this happened cause the code itself was changed. Maybe in Atcommand.c, maybe in an other file. All I know ( learned by comparing ) is that my old plugin was reading a variable called:

!battle_config.prevent_logout

and the new plugin ( yours and Annie's ) reads the variable:

 

battle->bc->prevent_logout

 

( If that are variable names :) )

 

Mfg

Snowflake

Edited by snowflake1963

Share this post


Link to post
Share on other sites
  • 0

battle->bc->prevent_logout and battle_config.prevent_logout issit ?

 

well ... I dunno how to really explain this either

I only know that 'battle_config.xxxxx' cannot be read in the plugin, always return 0

but then I noticed this line

https://github.com/HerculesWS/Hercules/blob/master/src/map/battle.c#L7107

battle->bc = &battle_config;
'battle_config.xxxxx' cannot be used, so has to use 'battle->bc->xxxxx'

 

hahaha ... sry I don't really know C stuffs either,

I just try and error

Edited by AnnieRuru

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.