Jump to content
  • 0
Ink

[Request] command to check playtime

Question

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 Ink

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

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 *

Share this post


Link to post
Share on other sites
  • 0

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 :D

Edited by Ink

Share this post


Link to post
Share on other sites
  • 0

"Last Time Online: "+ .@login$ +";

that last " should be double ""

Alternately , one can just vanish that last quote, ex:

mes "Last Time Online: "+ .@login$;

Share this post


Link to post
Share on other sites
  • 0

 

"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 "("

 

6zr5p1.jpg

Share this post


Link to post
Share on other sites
  • 0

 

 

 

"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 "("6zr5p1.jpg
Hmmm,, I was giving example

Just replace that line by

"Last Time Online: "+ .@login$;

Share this post


Link to post
Share on other sites
  • 0

 

 

 

 

"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 "("6zr5p1.jpg
Hmmm,, I was giving example

Just replace that line by

"Last Time Online: "+ .@login$;

thanks sir for the reply but seems same error occured

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

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