BTNX Posted July 22, 2013 Posted July 22, 2013 How do I automatically load a script when ever a character logs in or out without using loadevent on every map? Quote
Jasc Posted July 22, 2013 Posted July 22, 2013 There are OnPCLoginEvent and OnPCLogoutEvent labels. 1 Quote
BTNX Posted July 23, 2013 Author Posted July 23, 2013 (edited) ^ 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 July 23, 2013 by BTNX Quote
KoolKat29 Posted July 23, 2013 Posted July 23, 2013 ^ Would it also have the same effect if the player got disconnected instead of logging out? Yes. 2 Quote
Brian Posted July 23, 2013 Posted July 23, 2013 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. 2 Quote
BTNX Posted July 23, 2013 Author Posted July 23, 2013 (edited) ^ 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 July 23, 2013 by BTNX Quote
Brian Posted July 23, 2013 Posted July 23, 2013 (edited) 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 July 23, 2013 by Brian 1 Quote
BTNX Posted July 24, 2013 Author Posted July 24, 2013 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(.@atcmd_parameters$[0] == "") {dispbottom reset$;end;} else if(.@atcmd_parameters$[0] == "on"){ set reset$,"on"; dispbottom reset$; end;} else if(.@atcmd_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. Quote
KoolKat29 Posted July 26, 2013 Posted July 26, 2013 ^You want every players below group id lvl 99 to have a temporary group of 99 upon login? Quote
BTNX Posted July 29, 2013 Author Posted July 29, 2013 ^ yes so that I can easily remove it if needed. Quote
Xynvaroth Posted July 29, 2013 Posted July 29, 2013 (edited) 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(.@atcmd_parameters$[0] == "") {dispbottom reset$;end;} else if(.@atcmd_parameters$[0] == "on"){ set reset$,"on"; dispbottom reset$; end;} else if(.@atcmd_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 July 29, 2013 by Xynvaroth Quote
BTNX Posted July 30, 2013 Author Posted July 30, 2013 ^ 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? Quote
BTNX Posted July 31, 2013 Author Posted July 31, 2013 Disregard my last, the script works... it was just a minor grammatical error... I mixed up on and off. Quote
Question
BTNX
How do I automatically load a script when ever a character logs in or out without using loadevent on every map?
14 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.