Page 1 of 1

Script Sample: A Simple Login Counter

Posted: Wed Sep 05, 2012 1:10 am
by zaroba
Since the page for samples hasn't yet been created

A simple login counter that I have used on zoric since scripting was made possible:

This script uses playervar2 and each time a player logs in, it adds one to that var to count the players total number of logins. If you use it on your world, the (world owner) text should be changed to your name and the (world name) should be changed to your worlds name. It should be easy to modify the script and change the messages for each login or even give out prizes based on the number of logins a player has (although this could be abused by constantly reloging so I wouldn't recommend it)

Code: Select all

Event( "PlayerLogin" 0 )
	{ 
	*effect %player% 2
	sleep(100)
	$playervar2=$playervar2+1
	*msg %player% Welcome to (world name) %player% !
	*msg %player% Type  .ignore playername   to block a player that is bothering you.
	*msg %player% To report bugs, cheaters, ideas, etc, please contact (world owner)
	If ($playervar2=1)
		{
		sleep(100)
		*say This is %player%'s first time on (world name)!
		*say Somebody should be nice and offer him some help at getting started.
		$playervar6=0
		}
	else
		{
		If ($playervar2<5)
			{
			*say %player% is still quite new to the world.
			*say somebody should offer him some help.
			}
		Else If ($playervar2=10)
			{
			*say %player% has logged on 10 times so far!
			}
		Else If ($playervar2=25)
			{
			*say %player% has logged on 25 times so far!
			}
		Else If ($playervar2=50)
			{
			*say %player% has logged on 50 times so far!
			}
		Else If ($playervar2=100)
			{
			*say %player% has logged on 100 times so far!
			}
		Else If ($playervar2=200)
			{
			*say %player% has logged on 200 times so far!
			}
		Else If ($playervar2=300)
			{
			*say %player% has logged on 300 times so far!
			}
		Else If ($playervar2=400)
			{
			*say %player% has logged on 400 times so far!
			}
		Else If ($playervar2=500)
			{
			*say %player% has logged on 500 times so far!
			}
		Else
			{
			*msg %player% Have a great time playing!
			}
		}
Image

Posted: Wed Sep 05, 2012 8:08 am
by Mit
thanks zar.. ill build up samples soon :)
Couple of notes from me:
1) $gPlayerVar (rather than $playervar) is preferred - both work, but I want to try to standardise the 'system' variables so they all begin with 'g'. Can help avoid clashes with system variables and user created ones, and can generally make it a bit clearer what the script is doing.

2) We need a MOD function (i'll add later), but meantime, if you want to optimise a little you could use..

Code: Select all

...
else 
{
  $loginCount = $gPlayerVar[2] / 100
  $loginCount = $loginCount * 100
  if ( $loginCount == $gPlayerVar[2] )
  { 
         *say %player% has logged on $gPlayerVar[2] times so far! 
   }
   else
   {
      *msg %player% Have a great time playing! 
   }
}
.. to replace the last 5 or 6 blocks of your elseifs.

Posted: Wed Sep 05, 2012 8:34 am
by Omni
Great stuff! It's really C-wise.

Posted: Wed Sep 05, 2012 9:45 pm
by zaroba
Ahh, very nice Mit. Didn't think of that.

And, in case anybody else is wondering how Mit's thing works:
Vars cannot yet handle decimal values.
So when $gPlayerVar2 is divided by 100 to to get $loginCount, it gets rounded to the nearest whole number. Then when it multiplies by 100 it becomes a whole 100 based number. If $gPlayerVar2 equals this number it responds with a congratulations message.

ie:
If $gPlayerVar2 = 200, then when divided by 100, $loginCount equals 2
then when $loginCount is multiplied by 100, it equals 200
since the 2 vars match, the script responds with a congratulations message for having 200 logins.

conversely,
If $gPlayerVar2 = 198, then when divided by 100, $loginCount would be 1.98, but it gets rounded to 2
then when $loginCount is multiplied by 100, it equals 200
since the 2 vars wont match ($PlayerVar2=198, $loginCount=200), it wont post a congratulations message and instead goes to the final else statement and just says welcome to the world.