Ink 1 Posted October 20, 2014 (edited) I'd like to request a script to check a players play time (i found some to check your own but not the one of others). Prefer this with bindatcmd. example: @playtime <playername> -----Playername---- 5 hours 30 minutes idle 16 hours 23 minutes active Last Time online: <date> Registered at: <date> Thank you for reading Edited October 20, 2014 by Ink Quote Share this post Link to post Share on other sites
0 GmOcean 92 Posted October 20, 2014 3 ways of doing this. 1. Use bindatcmd in combination with Sql table. ( Recommended & Permanent ). 2. Use bindatcmd in combination with NPC variables. ( Temporary & Not-Recommended ). 3. Use bindatcmd in combination with Per-Global variables. ( Permanent & Not-Recommended ). - script playtime -1,{OnInit:bindatcmd "playtime",strnpcinfo(3)+"::OnPlayTime";// 1 = TempVariable | 2 = PermVariable | 3 = PermSQL// Default: 3.mode = 3;end;OnPlayTime:switch( .mode ) { case 1: if( .@atcmd_parameters$[0] == "" ) { .@atcmd_parameters$[0] = strcharinfo(0); } if( (.@size = query_sql( "SELECT char_id FROM char WHERE name= "+ .@atcmd_parameters$[0] +"",.@char_id ) ) ) { query_sql "SELECT lastlogin FROM login WHERE char_id="+ .@char_id[0] +"",.@login$; mes "-------- "+ .@atcmd_parameters$[0] +" --------", ""+ getd(".idlehours"+.@atcmd_parameters$[0]+"") +"hours "+ getd(".idleminutes"+.@atcmd_parameters$[0]+"") +"minutes idle.", ""+ getd(".activehours"+.@atcmd_parameters$[0]+"") +"hours "+ getd(".activeminutes"+.@atcmd_parameters$[0]+"") +"minutes active.", "Last Time Online: "+ .@login$ +"; close; } case 2: if( .@atcmd_parameters$[0] == "" ) { .@atcmd_parameters$[0] = strcharinfo(0); } if( (.@size = query_sql( "SELECT name,char_id FROM char WHERE name= "+ .@atcmd_parameters$[0] +"",.@name$,.@char_id ) ) ) { query_sql "SELECT lastlogin FROM login WHERE char_id="+ .@char_id[0] +"",.@login$; mes "-------- "+ .@name$ +" --------", ""+ getd("$idlehours"+.@atcmd_parameters$[0]+"") +"hours "+ getd("$idleminutes"+.@atcmd_parameters$[0]+"") +"minutes idle.", ""+ getd("$activehours"+.@atcmd_parameters$[0]+"") +"hours "+ getd("$activeminutes"+.@atcmd_parameters$[0]+"") +"minutes active.", "Last Time Online: "+ .@login$[0] +""; close; } case 3: if( .@atcmd_parameters$[0] == "" ) { .@atcmd_parameters$[0] = strcharinfo(0); } if( (.@size = query_sql( "SELECT char_id,idle_hour,idle_minute,active_hour,active_minute FROM playtime WHERE name="+ .@atcmd_parameters$[0] +"", .@char_id, .@idleh, .@idem, .@activeh, .@activem ) ) ) { query_sql "SELECT lastlogin FROM login WHERE char_id="+ .@char_id[0] +"",.@login$; mes "-------- "+ .@atcmd_parameters$[0] +" --------", ""+ .@idelh[0] +"hours "+ .@idlem[0] +"minutes idle.", ""+ .@activeh[0] +"hours "+ .@activem[0] +"minutes active.", "Last Time Online: "+ .@login$[0] +""; close; }}end;OnPCLoginEvent: @login = gettimetick(2); freeloop(1); while(1) { if( checkidle ) { @idle++; } else { @active++; } sleep2 1000; }end;OnPCLogoutEvent:.@idleh = @idle / 3600;.@idlem = @idle % 3600;.@activeh = @active / 3600;.@activem = @active % 3600;switch( .mode ) { case 1: setd ".idleh"+strcharinfo(0)+"", getd(".idleh"+strcharinfo(0)+"") + .@idleh; setd ".idlem"+strcharinfo(0)+"", getd(".idlem"+strcharinfo(0)+"") + .@idlem; setd ".activeh"+strcharinfo(0)+"", getd(".activeh"+strcharinfo(0)+"") + .@activeh; setd ".activem"+strcharinfo(0)+"", getd(".activem"+strcharinfo(0)+"") + .@activem; end; case 2: setd "$idleh"+strcharinfo(0)+"", getd("$idleh"+strcharinfo(0)+"") + .@idleh; setd "$idlem"+strcharinfo(0)+"", getd("$idlem"+strcharinfo(0)+"") + .@idlem; setd "$activeh"+strcharinfo(0)+"", getd("$activeh"+strcharinfo(0)+"") + .@activeh; setd "$activem"+strcharinfo(0)+"", getd("$activem"+strcharinfo(0)+"") + .@activem; end; case 3: if( query_sql( "SELECT * FROM playtime WHERE char_id="+getcharid(0)+"",.@char_id,.@name$,.@ihours,.@imins,.@ahours,.@amins) ) { query_sql "UPDATE playtime SET(idle_hours,idle_minutes,active_hours,active_minutes) VALUES("+ (.@ihours + .@idleh) +","+ (.@iminutes + .@idlem) +","+ (.@ahours + .@activeh) +","+ (.@aminutes + .@activem) +")"; } else { query_sql "INSERT INTO playtime char_id="+getcharid(0)+",name="+strcharinfo(0)+",idle_hours="+.@idleh+",idle_minutes="+.@idlem+",active_hours="+.@activeh+",active_minutes="+.@activem+""; } end;}end;} *NOTE - Completely untested. Just going off of what I can remember. unfortunately I have work, so you may have to rely on someone else to help you if there are bugs * Quote Share this post Link to post Share on other sites
0 Ink 1 Posted October 20, 2014 (edited) awesome i test this out. still got my problems to understand how to use atcmd_paramters. If there are bugs, i think i can handle them Edited October 20, 2014 by Ink Quote Share this post Link to post Share on other sites
0 Yommy 265 Posted October 22, 2014 "Last Time Online: "+ .@login$ +";that last " should be double "" Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted October 22, 2014 "Last Time Online: "+ .@login$ +"; that last " should be double "" Alternately , one can just vanish that last quote, ex:mes "Last Time Online: "+ .@login$; Quote Share this post Link to post Share on other sites
0 Reins 3 Posted October 23, 2014 "Last Time Online: "+ .@login$ +"; that last " should be double "" Alternately , one can just vanish that last quote, ex:mes "Last Time Online: "+ .@login$; i got this lol i didn't know where to put "(" Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted October 23, 2014 "Last Time Online: "+ .@login$ +"; that last " should be double "" Alternately , one can just vanish that last quote, ex:mes "Last Time Online: "+ .@login$; i got this lol i didn't know where to put "("Hmmm,, I was giving exampleJust replace that line by "Last Time Online: "+ .@login$; Quote Share this post Link to post Share on other sites
0 Reins 3 Posted October 23, 2014 "Last Time Online: "+ .@login$ +"; that last " should be double "" Alternately , one can just vanish that last quote, ex:mes "Last Time Online: "+ .@login$; i got this lol i didn't know where to put "("Hmmm,, I was giving exampleJust replace that line by "Last Time Online: "+ .@login$; thanks sir for the reply but seems same error occured Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted October 23, 2014 You seem to be missing the ending semicolon ( at the end of line 17? Quote Share this post Link to post Share on other sites
I'd like to request a script to check a players play time (i found some to check your own but not the one of others). Prefer this with bindatcmd.
example: @playtime <playername>
-----Playername----
5 hours 30 minutes idle
16 hours 23 minutes active
Last Time online: <date>
Registered at: <date>
Thank you for reading
Edited by InkShare this post
Link to post
Share on other sites