Jump to content
  • 0

Issue with this script based on timing.


ToiletMaster

Question


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hi there guys and girls,

I'm currently having a small issue with this script of mine.

Here's the catch.

I wanna make this npc disabled on certain days and enabled on certain days.

I've managed to do that however, even though the npc becomes disabled, the npctalk is still there.

prontera,97,153,5	script	Clemy	703,{  
  	 if (gettime(4)==1){
	OnClock0001:
	mes "Hello!";
	disablenpc strnpcinfo(0);
	close;
	}
	if (gettime(4)==2){
	mes "LOL";
	close2;
	end;
	OnInit:
	.@interval = 5;
	.@step = 5;
	while (1) {
	sleep .@interval * 1000;
	getmapxy .@map$, .@x, .@y, 1;
	while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
	npcwalkto .@npc_x, .@npc_y;
	npctalk callfunc( "F_RandMes", 2,
	"Heloo!!!", // 1
	"Goodbye~!" // 2
	);		
	}
	}
	}

Here are the current issues.

1. NPC stilll talks even after disabled.

2. As you can see, today is monday which gettime suppose to be (4)==1, however it still moves around following the the (4)==2 stating the random npc messages. Should it be standing still and not moving since it's monday and no commands have been placed on monday except disable?

[note] i'm aware of enabling the npc back, this script is not yet fully done however, this is the main issue currently.

Thanks for the assistance!

Edited by ToiletMaster
Link to comment
Share on other sites

17 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

prontera,97,153,5	script	Clemy	703,{  

mes "If you can speak with me, I'm enabled!!!";
close;


//I've used On<weekdays><hour><minute>: event label.
//Weekdays are Sun,Mon,Tue,Wed,Thu,Fri,Sat.

//Days you want to ENABLE the NPC (NPC will last enabled until next disable)
OnSun0000:
OnTue0000:
enablenpc strnpcinfo(0);
end;

//Days you want to DISABLE the NPC (NPC will last disabled until next enable)
OnMon0000:
OnWed0000:
disblenpc strnpcinfo(0);
end;

OnInit:
.@interval = 5;
.@step = 5;
while (1) {
	sleep .@interval * 1000;
	getmapxy .@map$, .@x, .@y, 1;
	while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
	npcwalkto .@npc_x, .@npc_y;
	npctalk callfunc( "F_RandMes", 2,
		"Heloo!!!", // 1
		"Goodbye~!" // 2
	);		
}
}

Edited by AnnieRuru
use [codebox] if the script > 10 lines
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hi there ryokem!

Thanks for editing the script! i've tested it, but once the npc is disabled, it still talks the random messages.

is there any way to disable that and make it work only on the day that i want it to ?

Edited by ToiletMaster
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

Of course it talks the random messages.

Disable the npc means that players CANNOT interact with it in any way, but all the other script triggers (event labels) still works.

As the npctalk and the npcwalkto are called through the event label OnInit, it will keep doing it.

You will have to set a variable to record if the npc is disabled or not.

OnSun0000:
OnTue0000:
enablenpc strnpcinfo(0);
.is_enable = 1;
end;

OnMon0000:
OnWed0000:
disblenpc strnpcinfo(0);
.is_enable = 0;
 end; 

while (1) {
sleep .@interval * 1000;
if( .is_enable ) {
	getmapxy .@map$, .@x, .@y, 1;
	while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
	npcwalkto .@npc_x, .@npc_y;  npctalk callfunc( "F_RandMes", 2,
		"Heloo!!!", // 1
		"Goodbye~!" // 2
    );
}
}

Edited by Ryokem
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

yeah can do that ... but waste server resources ...

prontera,157,178,5    script    Clemy    703,{
   end;
OnMon0000:
OnWed0000:
   disablenpc strnpcinfo(0);
   end;
OnSun0000:
OnTue0000:
   enablenpc strnpcinfo(0);
   // continute read on
OnInit:
   if ( gettime(4) != 0 && gettime(4) != 2 ) { // add this...
       disablenpc strnpcinfo(0);
       end;
   }
   .@interval = 2;
   .@step = 5;
   while (1) {
       sleep .@interval * 1000;
           if ( gettime(4) != 0 && gettime(4) != 2 ) { // add this....
               disablenpc strnpcinfo(0);
               end;
           }
       getmapxy .@map$, .@x, .@y, 1;
       while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
       npcwalkto .@npc_x, .@npc_y;
       npctalk callfunc( "F_RandMes", 2,
           "Heloo!!!", // 1
           "Goodbye~!" // 2
       );        
   }
}

refer to this woe time explanation and learn its trick

this is event script trick ..............

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

Npc variables are not a waste of "server resources" at all. The while() loop is a waste when it does nothing, that's for sure, but i was just editing the script depending on what he needed trying to leave his script untouched if possible. I just gave a brief explanation on how to do it in a general case, not on how to optimize a full script.

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

how about assign a variable to check whether the WHILE-LOOP should run or not ?

http://pastebin.com/raw.php?i=KpT5xW5z

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

@emistry

hmm ... can also

but before the end of npc, need to add disablenpc strnpcinfo(0); though

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

@Annie..

i think it's okay..

OnMon0000:
OnWed0000:
.unhide = 0;
disablenpc strnpcinfo(0);
end;

the WHILE-LOOP only stop working after this part is triggered

so it will also hide the npc...and stop the loop ~

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

hmm ... just tested your script doesn't run

more like this

prontera,157,178,5	script	Clemy	703,{
end;
OnMon0000:
OnWed0000:
.unhide = 0;
disablenpc strnpcinfo(0);
end;
OnSun0000:
OnTue0000:
enablenpc strnpcinfo(0);
.unhide = 1;
goto L_start;
OnInit:
if ( gettime(4) != 0 && gettime(4) != 2 ) { // add this...
	disablenpc strnpcinfo(0);
	end;
}
else
	.unhide = 1;
L_start:
.@interval = 2;
.@step = 5;
while ( .unhide ) {
	sleep .@interval * 1000;
	getmapxy .@map$, .@x, .@y, 1;
	while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
	npcwalkto .@npc_x, .@npc_y;
	npctalk callfunc( "F_RandMes", 2,
		"Heloo!!!", // 1
		"Goodbye~!" // 2
	);		
}
end;
}

suddenly feels my method without disablenpc in while-loop is more efficient ... dunno...

well as long it works ...

Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

Oh god no quit that goto please! xD

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hi there guys,

I tried the scripts and finally

AnnieRuru's Script works great! 100% the way i intended it to work!

Thanks AnnieRuru for your great help!

I appreciate Ryokem and Emistry for the assistance as well!

Thanks again!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

Oh god no quit that goto please! xD

http://www.eathena.ws/board/index.php?s=&showtopic=262582&view=findpost&p=1436182

well-placed goto will speed up optimization ... just like in this example ...

without a goto in this script, I need to use callfunc,

because On<starttime>: and OnInit: having repeated feature inside

it looks even uglier with callfunc

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

Oh god no quit that goto please! xD

http://www.eathena.w...dpost&p=1436182

well-placed goto will speed up optimization ... just like in this example ...

without a goto in this script, I need to use callfunc,

because On<starttime>: and OnInit: having repeated feature inside

it looks even uglier with callfunc

I meant, the previous script you did was way looking better and more efficient, quit that script with goto.

(Refering to this post.)

Just you did an useless check at the very beginning after OnInit label. As the check is already in the while(1) loop, meanless to check it there too, just leave the sleep interval to drop and wait for that check.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

I meant, the previous script you did was way looking better and more efficient, quit that script with goto.

(Refering to this post.)

yeah I already said in that post, my method is more efficient already ... :ani_swt3:

Just you did an useless check at the very beginning after OnInit label. As the check is already in the while(1) loop, meanless to check it there too, just leave the sleep interval to drop and wait for that check.

please get a test server and test it before you post ... because without that check, the script doesn't want to run

unless you can post up a solution that's better than mine and emistry

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

Just you did an useless check at the very beginning after OnInit label. As the check is already in the while(1) loop, meanless to check it there too, just leave the sleep interval to drop and wait for that check.

please get a test server and test it before you post ... because without that check, the script doesn't want to run

unless you can post up a solution that's better than mine and emistry

First, I can't get a server test, I can browse rAthena only from university or work, and I can't install a server test there, I apologize if my scripts can contain errors because of that but it can't be helped, if you prefer i will stop posting helping thread, so you may be happy.

OnInit:
   if ( gettime(4) != 0 && gettime(4) != 2 ) { //useless chck in my opinion, let the script enter the while loop and after the sleep interval, this check will be done itself.
    disablenpc strnpcinfo(0);
    end;
   }
   .@interval = 2;
   .@step = 5;
   while (1) {
    sleep .@interval * 1000;
    if ( gettime(4) != 0 && gettime(4) != 2 ) { // add this....
	    disablenpc strnpcinfo(0);
	    end;
    }
    getmapxy .@map$, .@x, .@y, 1;
    //[...]

THIS is what I meant. Really.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

your script there if let the script enter while loop

that sleep .@interval * 1000; will pause the script for several seconds, then only disablenpc

prontera,157,178,5    script    Clemy    703,{
   end;
OnMon0000:
OnWed0000:
   disablenpc strnpcinfo(0);
   end;
OnSun0000:
OnTue0000:
OnSat0000:
   enablenpc strnpcinfo(0);
OnInit:
   .@interval = 2;
   .@step = 5;
   while (1) {
       if ( gettime(4) != 0 && gettime(4) != 2 && gettime(4) != 6 ) {
//        if ( gettime(4) != 0 && gettime(4) != 2 ) {
           disablenpc strnpcinfo(0); // OnInit doesn't run disablenpc by itself now, and depends on this one to disablenpc itself
           end;
       }
       sleep .@interval * 1000;
       getmapxy .@map$, .@x, .@y, 1;
       while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
       npcwalkto .@npc_x, .@npc_y;
       npctalk callfunc( "F_RandMes", 2,
           "Heloo!!!", // 1
           "Goodbye~!" // 2
       );        
   }
}

hmm ... just need to reorganize the code

Edited by AnnieRuru
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

your script there if let the script enter while loop

that sleep .@interval * 1000; will pause the script for several seconds, then only disablenpc

hmm ... just need to reorganize the code

Exactly, you need to reorganize of course. But that's not the best way about how to reorganize it.

I would procede as follow:

OnInit:
.@interval = 2;
.@step = 5;
while (1) {

	if ( gettime(4) != 0 && gettime(4) != 2 ) { // add this....
		disablenpc strnpcinfo(0);
		end;
	}

	getmapxy .@map$, .@x, .@y, 1;
	while ( checkcell( .@map$, .@npc_x = .@x + rand( -.@step, .@step ), .@npc_y = .@y + rand( -.@step, .@step ), cell_chknopass ) );
	npcwalkto .@npc_x, .@npc_y;
	npctalk callfunc( "F_RandMes", 2,
		"Heloo!!!", // 1
		"Goodbye~!" // 2
	);

	sleep .@interval * 1000;
}

Credits for code @Annie.

It's better to leave the check right after sleep ends, for obvious functional reason.

Edited by Ryokem
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...