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 *