Jump to content
  • 0
BTNX

Script load on login / logout

Question

How do I automatically load a script when ever a character logs in or out without using loadevent on every map?

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

^ Thanks, Can you give me an example on how to use that?  Would it also have the same effect if the player got disconnected instead of logging out?

Edited by BTNX
Link to comment
Share on other sites

Here's an example:

-	script	login_logout	-1,{

OnPCLoginEvent:

dispbottom "You just logged in.";

// do other stuff

end;

OnPCLogoutEvent:

// dispbottom won't be useful because they logged out

// ... but we could announce to everyone else:

announce strcharinfo(0) + " has just logged out.",bc_all;

// do other stuff

end;

}

And yes, disconnects are treated the same as logouts and will also trigger OnPCLogoutEvent.
  • Upvote 2
Link to comment
Share on other sites

^ thanks.

I'm trying to write a script that would reset characters upon log out.

 

The OnPCLogoutEvent scripts such as query_sql set variable,value; etc. will still carry on right?

Edited by BTNX
Link to comment
Share on other sites

This is how the workflow goes:

player logout/disconnect --> triggers OnPCLogoutEvent --> then server saves their data to SQL

You can use set and it will work, but if you want to manually edit data with query_sql, the trick is to use sleep 1000; (detach RID, and pause script) first. Detaching the RID completes the character logout and allows the server to save their data to SQL. Then you can edit with query_sql.

If you used 'query_sql' before they were completely logged out, anything you changed would just get overwritten when the server saves their data to SQL.

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

Can someone please look this over:

- script load_login -1,{

OnPCLoginEvent:

if(getgroupid() == 99) {dispbottom "Good day sir"; end;}

else {

set reset$,"off";

dispbottom "Auto reset "+reset$;

atcommand "@adjgroup 99";

dispbottom "You are now in Admin group";

end;}

}

- script autoreset -1,{

OnInit:

bindatcmd "autoreset",strnpcinfo(3)+"::OnAutoreset";

end;

OnAutoreset:

if([email protected]_parameters$[0] == "") {dispbottom reset$;end;}

else

if([email protected]_parameters$[0] == "on"){

set reset$,"on";

dispbottom reset$;

end;}

else

if([email protected]_parameters$[0] == "off"){

set reset$,"off";

dispbottom reset$;

end;}

}

- script load_logout -1,{

OnPClogoutEvent:

if(reset$ == "on") end;

savepoint "prontera",156,179;

atcommand "@return";

}

I'm talking about the last part of the script... I added everything so that you guys know what's going on... anyway, this script actually sends the player back to "prontera",156,179 everytime they log out ... The problem is... the script is supposed to not reset the player if their variable reset$ is = "on"... but it always reset the player anyway regardless of reset$ value

Btw... Putting the script into sleep will force it to detach rid and the script wouldn't know who to reset /query etc.

Link to comment
Share on other sites

Can someone please look this over:

- script load_login -1,{

OnPCLoginEvent:

if(getgroupid() == 99) {dispbottom "Good day sir"; end;}

else {

set reset$,"off";

dispbottom "Auto reset "+reset$;

atcommand "@adjgroup 99";

dispbottom "You are now in Admin group";

end;}

}

- script autoreset -1,{

OnInit:

bindatcmd "autoreset",strnpcinfo(3)+"::OnAutoreset";

end;

OnAutoreset:

if([email protected]_parameters$[0] == "") {dispbottom reset$;end;}

else

if([email protected]_parameters$[0] == "on"){

set reset$,"on";

dispbottom reset$;

end;}

else

if([email protected]_parameters$[0] == "off"){

set reset$,"off";

dispbottom reset$;

end;}

}

- script load_logout -1,{

OnPClogoutEvent:

if(reset$ == "on") end;

savepoint "prontera",156,179;

atcommand "@return";

}

I'm talking about the last part of the script... I added everything so that you guys know what's going on... anyway, this script actually sends the player back to "prontera",156,179 everytime they log out ... The problem is... the script is supposed to not reset the player if their variable reset$ is = "on"... but it always reset the player anyway regardless of reset$ value

Btw... Putting the script into sleep will force it to detach rid and the script wouldn't know who to reset /query etc.

As far as I can see, the script should work like this.

That said, for further debugging, try this

- script load_logout -1,{
OnPClogoutEvent:
debugmes "reset$ = " + reset$;
if(reset$ == "on") end;
savepoint "prontera",156,179;
atcommand "@return";
}
If you implement this, you should be able to see the actual value of reset$ in a debug message from your map-server when you log out.

In general, if you want to save a boolean state (on - off; true - false), it is better (only in rAthena, since rAthena's scripting engine does not feature boolean variables) to use an integer variable and set it to 0 or 1, because it is always good to keep the information saved as small as neccessary (to save strings like "on" and "off", more bytes are needed than to save integers with only one digit like 0 and 1).

Edited by Xynvaroth
Link to comment
Share on other sites

^ I will try that.  I already tested that by using dispbottom right after OnPCLoginEvent before though.
Also, I thought about using 0 and 1 but I wanted to dispbottom the rest$ value will display on or off instead of 1 or 0 without adding if(reset == 0) dispbottom blah blah on the bindatcmd script.

Which one is better anyway?
 

Link to comment
Share on other sites

Disregard my last, the script works... it was just a minor grammatical error... I mixed up on and off.

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...

Important Information

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