• Welcome to Vice City Multiplayer.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - cycu

#1
ShowRoom (pawn) / Way around: SetTimerEx.
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  :-*.