[Help]How to use SetTimerEx
#1

Hi guys!

I just worked out to pass the "playerid" param, i need to use SetTimerEx... I read this wiki, but Im a beginner so I didnt understand most of it :S

If someone could explain it better for me plz?
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#2

Anyone?
Reply
#3

The whole point of SetTimerEx is for passing values from one function to another
https://sampwiki.blast.hk/wiki/SetTimerEx

SetTimerEx("message", 1000, false, "d", 1);
"message" is the string name of the function you will call
1000 is how much time it needs to pass for the function to be called (in miliseconds)
False (or true) is the type of timer. Being false it will only call "message" once, being true it will call it every interval
"d" is the type of variable to pass. In this case an integer. Check the wiki page for other types to send
The number 1 is what it will be passed. Because I used "d" or "%d" for the format to pass it will pass it as an integer

Example
pawn Код:
//somewhere in the script
SetTimerEx("message", 1000, false, "d", 1);

//on the bottom of the script
forward message(number);
public message(number)
{
  printf("The symbol 'number' is %d", number);
  //This will display "The symbol 'number' is 1"
  //That is because SetTimerEx passed the number 1 to the function
  //If it would be SetTimerEx("message", 1000, false, "d", 167); then the output would be
  //This will display "The symbol 'number' is 1"
}
Ingame example
pawn Код:
//under OnPlayerDeath(playerid, killerid, reason)
SetTimerEx("KillMessage", 1000, false, "dds", playerid, killerid, reason); //there are 2 'd' because I'm passing two integers. The 's' means string

//on the bottom of the script
forward KillMessage(playerid, killerid, string);
public KillMessage(playerid, killerid, string)
{
  printf("Playerid %d was killed by playerid %d. Reason: %s", playerid, killerid, string);
  //This will display "Playerid 0 was killed by playerid 1. Reason: blahblah" if playerid is really 0 and killerid 1
}
Reply
#4

Cheers! This really helped!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)