BTNX Posted July 22, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Share 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 Link to comment Share on other sites More sharing options...
Jasc Posted July 22, 2013 Group: Members Topic Count: 29 Topics Per Day: 0.01 Content Count: 270 Reputation: 20 Joined: 12/10/11 Last Seen: June 28, 2022 Share Posted July 22, 2013 There are OnPCLoginEvent and OnPCLogoutEvent labels. 1 Quote Link to comment Share on other sites More sharing options...
BTNX Posted July 23, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share 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 Link to comment Share on other sites More sharing options...
KoolKat29 Posted July 23, 2013 Group: Members Topic Count: 2 Topics Per Day: 0.00 Content Count: 90 Reputation: 5 Joined: 06/17/12 Last Seen: September 6, 2013 Share Posted July 23, 2013 ^ Would it also have the same effect if the player got disconnected instead of logging out? Yes. 2 Quote Link to comment Share on other sites More sharing options...
Brian Posted July 23, 2013 Group: Members Topic Count: 75 Topics Per Day: 0.02 Content Count: 2223 Reputation: 593 Joined: 10/26/11 Last Seen: June 2, 2018 Share 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 Link to comment Share on other sites More sharing options...
BTNX Posted July 23, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share 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 Link to comment Share on other sites More sharing options...
Brian Posted July 23, 2013 Group: Members Topic Count: 75 Topics Per Day: 0.02 Content Count: 2223 Reputation: 593 Joined: 10/26/11 Last Seen: June 2, 2018 Share 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 Link to comment Share on other sites More sharing options...
Xynvaroth Posted July 23, 2013 Group: Members Topic Count: 39 Topics Per Day: 0.01 Content Count: 254 Reputation: 72 Joined: 07/10/13 Last Seen: October 9, 2017 Share Posted July 23, 2013 You mean sleep rather than sleep2, or? 1 Quote Link to comment Share on other sites More sharing options...
Brian Posted July 23, 2013 Group: Members Topic Count: 75 Topics Per Day: 0.02 Content Count: 2223 Reputation: 593 Joined: 10/26/11 Last Seen: June 2, 2018 Share Posted July 23, 2013 oh yea, sleep. Thanks. 1 Quote Link to comment Share on other sites More sharing options...
BTNX Posted July 24, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share 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 Link to comment Share on other sites More sharing options...
KoolKat29 Posted July 26, 2013 Group: Members Topic Count: 2 Topics Per Day: 0.00 Content Count: 90 Reputation: 5 Joined: 06/17/12 Last Seen: September 6, 2013 Share Posted July 26, 2013 ^You want every players below group id lvl 99 to have a temporary group of 99 upon login? Quote Link to comment Share on other sites More sharing options...
BTNX Posted July 29, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share Posted July 29, 2013 ^ yes so that I can easily remove it if needed. Quote Link to comment Share on other sites More sharing options...
Xynvaroth Posted July 29, 2013 Group: Members Topic Count: 39 Topics Per Day: 0.01 Content Count: 254 Reputation: 72 Joined: 07/10/13 Last Seen: October 9, 2017 Share 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 Link to comment Share on other sites More sharing options...
BTNX Posted July 30, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share 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 Link to comment Share on other sites More sharing options...
BTNX Posted July 31, 2013 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share Posted July 31, 2013 Disregard my last, the script works... it was just a minor grammatical error... I mixed up on and off. Quote Link to comment Share on other sites More sharing options...
Question
BTNX
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.