• Welcome to Vice City Multiplayer.
 

Way around: SetTimerEx.

Started by cycu, March 29, 2011, 04:52:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cycu

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  :-*.

Charleyutton

Or you could just use *cough* squirrel *cough*
Charleyutton, VU clan leader, VCDC co-creator, SvM Server Owner, Squirrel Scripter. http://vu.vrocker-hosting.co.uk http://svm.vrocker-hosting.co.uk XE Scripter

cycu

#2
Quote from: Charleyutton on March 29, 2011, 07:07:16 PM
Or you could just use *cough* squirrel *cough*

Nah, it's too easy  ::).

[AoD]NC

You don't have to cough Charley :).
* [AoD]NC gives him some medicine ;)

tato






<!-- Facebook Badge START --><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Eduardo Estrada">Eduardo Estrada</a><br/><a href="http://es-es.facebook.com/eduardoeslindo" target="_TOP" title="Eduardo Estrada"><img src="http://badge.facebook.com/badge/697470158.6069.1979465113.png" width="120" height="272" style="b

yazeen

Quote from: tato on March 30, 2011, 03:45:29 AM
what is this for XD?

Twice of Normal Timer

Quote from: Charleyutton on March 29, 2011, 07:07:16 PM
Or you could just use *cough* squirrel *cough*

Well Pawno is also good
*Cough* pawno *cough*

Charleyutton

Charleyutton, VU clan leader, VCDC co-creator, SvM Server Owner, Squirrel Scripter. http://vu.vrocker-hosting.co.uk http://svm.vrocker-hosting.co.uk XE Scripter

cycu

#7
Quote from: Charleyutton on March 30, 2011, 07:07:41 PM
Quote from: cycu on March 29, 2011, 07:15:24 PM
Quote from: Charleyutton on March 29, 2011, 07:07:16 PM
Or you could just use *cough* squirrel *cough*

Nah, it's too easy  ::).

I'm lost for words... literally.

You just can't take sarcasm can you  :D

Robd

Why not just make an array? That way each player gets his own value.
Hello, this is Robd from the past.
If you are seeing this I have either posted something stupid, forgotten something, started a stupid topic, or a combination of the three.

Please forgive us for this mistake.

Regards, management

cycu

Quote from: Robd on March 30, 2011, 11:13:39 PM
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 ;)






Charleyutton

Quote from: cycu on March 30, 2011, 08:12:26 PM
Quote from: Charleyutton on March 30, 2011, 07:07:41 PM
Quote from: cycu on March 29, 2011, 07:15:24 PM
Quote from: Charleyutton on March 29, 2011, 07:07:16 PM
Or you could just use *cough* squirrel *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.
Charleyutton, VU clan leader, VCDC co-creator, SvM Server Owner, Squirrel Scripter. http://vu.vrocker-hosting.co.uk http://svm.vrocker-hosting.co.uk XE Scripter

Robd

We may be dumb but we aren't stupid!
Hello, this is Robd from the past.
If you are seeing this I have either posted something stupid, forgotten something, started a stupid topic, or a combination of the three.

Please forgive us for this mistake.

Regards, management