Vice City Multiplayer

VC:MP => mIRC/pawn Scripting => ShowRoom (pawn) => Topic started by: cycu on March 29, 2011, 05:52:04 PM

Title: Way around: SetTimerEx.
Post by: cycu on March 29, 2011, 05:52:04 PM
Hello everyone!

Today i decided to make a little tutorial about:

"How to live without SetTimerEx" ;)

Now i don't know if some of you played sa-mp where this function actually is added, that's why in the start i will explain biggest differences from SetTimer.

SetTimer(funcname[], interval, repeating);
SetTimerEx((funcname[], interval, repeating, const format[], {Float,_}:...);

Now, the most important difference is that SetTimerEx allows you to carry some data(integers, strings etc) from one place of the code to the other which SetTimer obviously can't.

However there is solution for this, it might not be perfect but I'm sure it will work out for most of you!

Let's say that after player spawns you want him to be spawned elsewhere 1 second after the first spawn.
Now, if you used only SetTimer it might work, but only for 1 person, if there is currently more then 1 player on the server it won't work, enough of chit chat - let's start.


On top of your map create 2 new variables which will save our playerid.

new GlobalID = 255;
new GlobalID2 = 255;


It depends on how popular the server is, so you might need to add more of them.

Why 255 ?
You will understand why in a second.

Now in OnPlayerSpawn:

if(GlobalID != 255)
{
SetTimer("SpawnPlayerAfterSpawn",1000,false);
GlobalID2 = playerid;
}
else
{
          SetTimer("SpawnPlayerAfterSpawn",1000,false);
GlobalID = playerid;
}


This little code will check if GlobalID is equal 255 which means that it's free(there is no playerid assigned to it)
and if it's not it will assign playerid to GlobalID2, as i said before if your server is populary you might need to add more of them.
And of course it starts timer.

Now at the end of your script you should add new public:

public SpawnPlayerAfterSpawn( )

Okay, grand finale  8)

In SpawnPlayerAfterSpawn( ) you add:

{
if(GlobalID != 255)
{
SetPlayerPos(GlobalID,5000.0,-5000.0,5000.0,-5000.0,6.0,0);
GlobalID = 255;
}
else if(GlobalID2 != 255)
{
SetPlayerPos(GlobalID2,5000.0,-5000.0,5000.0,-5000.06.0r,0);
GlobalID2 = 255;
}
}


And again this code will check which one of the variables are currently in use and prevents from reseting variable for player who is going to be spawned just right after the first one.

This method is not perfect but i think this is the only solution at the moment, i hope SetTimerEx will be in next release  ???.

If you have some problems/questions feel free to ask i will try to help/answer  :-*.
Title: Re: Way around: SetTimerEx.
Post by: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*
Title: Re: Way around: SetTimerEx.
Post by: cycu on March 29, 2011, 08:15:24 PM
Quote from: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*

Nah, it's too easy  ::).
Title: Re: Way around: SetTimerEx.
Post by: [AoD]NC on March 29, 2011, 08:59:44 PM
You don't have to cough Charley :).
/me gives him some medicine ;)
Title: Re: Way around: SetTimerEx.
Post by: tato on March 30, 2011, 04:45:29 AM
what is this for XD?
Title: Re: Way around: SetTimerEx.
Post by: yazeen on March 30, 2011, 05:58:49 AM
Quote from: tato on March 30, 2011, 04:45:29 AM
what is this for XD?

Twice of Normal Timer

Quote from: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*

Well Pawno is also good
*Cough* pawno *cough*
Title: Re: Way around: SetTimerEx.
Post by: Charleyutton on March 30, 2011, 08:07:41 PM
Quote from: cycu on March 29, 2011, 08:15:24 PM
Quote from: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*

Nah, it's too easy  ::).

I'm lost for words... literally.
Title: Re: Way around: SetTimerEx.
Post by: cycu on March 30, 2011, 09:12:26 PM
Quote from: Charleyutton on March 30, 2011, 08:07:41 PM
Quote from: cycu on March 29, 2011, 08:15:24 PM
Quote from: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*

Nah, it's too easy  ::).

I'm lost for words... literally.

You just can't take sarcasm can you  :D
Title: Re: Way around: SetTimerEx.
Post by: Robd on March 31, 2011, 12:13:39 AM
Why not just make an array? That way each player gets his own value.
Title: Re: Way around: SetTimerEx.
Post by: cycu on March 31, 2011, 11:25:54 AM
Quote from: Robd on March 31, 2011, 12:13:39 AM
Why not just make an array? That way each player gets his own value.

Great point! i did actually, however i have really bad habit from samp that I'm using arrays like this e.g:

Blalal[playerid] = blalala;

When i did this, it didn't work out, so instead of using the other method i used variables.
Great that you pointed out the easier way. :P I will rework the tutorial soon ;)





Title: Re: Way around: SetTimerEx.
Post by: Charleyutton on March 31, 2011, 11:34:19 AM
Quote from: cycu on March 30, 2011, 09:12:26 PM
Quote from: Charleyutton on March 30, 2011, 08:07:41 PM
Quote from: cycu on March 29, 2011, 08:15:24 PM
Quote from: Charleyutton on March 29, 2011, 08:07:16 PM
Or you could just use *cough* squirrel (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions/Timers/NewTimer) *cough*

Nah, it's too easy  ::).

I'm lost for words... literally.

You just can't take sarcasm can you  :D

Ah ha, I just don't expect it on this forum :p I didn't expect a single user of this scripting board to have even heard the word before to be perfectly honest.
Title: Re: Way around: SetTimerEx.
Post by: Robd on April 04, 2011, 05:20:55 PM
We may be dumb but we aren't stupid!