Chosing a case starts a timer?
#1

When i choose an option it should start an timer, but it doesnt... anyone knows why?
Timer should every 2 seconds send a message "ROFLMAO BANANA!"

pawn Код:
forward banana(playerid)
pawn Код:
public banana(playerid)
{
SendClientMessage(playerid,0xFF9900AA,"ROFLMAO BANANA!");  // this never happens
}
pawn Код:
new Menu:CurrentMenu3 = GetPlayerMenu(playerid);
    if(CurrentMenu3 == flymenu)
{
    switch(row)
    {
  case 0:
        {
        SetTimer("banana",2000,true);
        SendClientMessage(playerid, 0xFFFF00AA, "banana");  // this works
        }
       
      }
      return 1;
}
pawn Код:
flymenu = CreateMenu("Banaaananaaaaaaaaa", 0, 200.0, 100.0, 400.0, 300.0);
    AddMenuItem(flymenu, 0, "Banana");
Reply
#2

You need to use SetTimerEx to pass the playerid argument to your 'banana' function (aka passing the correct playerid - the one which uses the menu)

https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

Could you please script an example of my case, cuz i realy dont get it what you mean... neither if i look on Wiki -.-
Reply
#4

The parameter you pass with bandana is playerid, like seen here:
pawn Код:
banana(playerid)
Parameters are values such as numbers or alphanumeric. While in programming numbers are considered integers(without dot/comma) or doubles(in most programming languages) which look similar to 0.0.
While pawn(the scripting language you are using) uses Float instead of double which is the same kind of. Anyway, enough about certain variable types. You are telling SetTimer to call the function
pawn Код:
banana(playerid)
Every x amount of time. Though while doing so, you give it no parameter. So what it basically does is asign playerid = null(Null in programming is not the number 0 but \1). So while you are sending a Client message to the Player, you have not defined what the player is nor who that might be.

SA-MP as such identifies players by their ID's. To see your ID while you are ingame(be advised these are dynamic) you can press TAB and you will see an ID infront of your name. The same way do you identify players within your script. You may not know the player by name, but the ID's are always within the same range and do not change "itself". Like ID 1 remains ID 1, only the player changes as such.

Now, when passing the parameter playerid to your function, you need to actually tell the script which one it is. To do that, there is certain events where samp calls your callbacks(which you can find in a_samp.inc) with the playerid who triggered this event.

There is a Event you might know which is "OnPlayerCommandText". When you check the parameters, it also tells who(as in what ID) typed a certain command. Now at these events you can pass through the actual playerID to your banana and the function will know what player to send a message to. Now to do this with timers as well, SetTimerEx was created.

With SetTimerEx(check the wiki for more info) you can pass extra parameters that it will call the function you specified with. So in your case, it would for example instead of only calling the function banana, also pass the playerID.

To do so, you would have to do something like:
pawn Код:
SetTimerEx("FunctionName",interval,repeat,TYPE*,PARAMS);
Types, as explained above can be i(integer), s(string), f(float) and so on.

Now that said, your SetTimerEx would look something similar to:
pawn Код:
SetTimerEx("banana",2000,true,"i",playerid);
Reply
#5

Whoa, this actualy works... ty xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)