Help with timer.
#1

Im making a casino and after they type a command i want it to wait 10 seconds then it will give them a random ammount of money. Im not very knowledge about timers, so doing the casino will probally get me a little better understanding of how they work. But, for know can someone show me how i would do this?
Reply
#2

pawn Код:
#define MAX_CASH 100000
forward Trolo( playerid ) ;

SetTimer("Trolo",10000,false);

public Trolo ( playerid ) {
     new randomcash = random(MAX_CASH);
     GivePlayerMoney(playerid,randomcash);
     return 1;
}
Reply
#3

Quote:
Originally Posted by Kitten
Посмотреть сообщение
pawn Код:
#define MAX_CASH 100000
forward Trolo( playerid ) ;

SetTimer("Trolo",10000,false);

public Trolo ( playerid ) {
     new randomcash = random(MAX_CASH);
     GivePlayerMoney(playerid,randomcash);
     return 1;
}
Thank you Kitten, but it crashes my server
Reply
#4

Quote:
Originally Posted by Kitten
Посмотреть сообщение
pawn Код:
#define MAX_CASH 100000
forward Trolo( playerid ) ;

SetTimer("Trolo",10000,false);

public Trolo ( playerid ) {
     new randomcash = random(MAX_CASH);
     GivePlayerMoney(playerid,randomcash);
     return 1;
}
That piece of code is a bit off, you're calling a callback but without giving it the parameter it looks for? That means this timer will only work for a single person (id 0), because the value of playerid will default to 0 since you're not passing another value to it.

Instead of using SetTimer for this example, you would need to use SetTimerEx and pass an ID along to the callback, like it's expecting you to! For example:

pawn Код:
SetTimerEx("Trolo", 10000, false, "i", playerid);
Depending on what you wish to send of course this could be modified.

Please make sure you're posting proper examples in this section when responding to threads, otherwise people will be mis-lead by in-correct information!

As for the original poster, I recommend instead of waiting for help here, that you use the SA-MP Wiki which has absolutely tons of extremely detailed information on all of the functions you can make use of.

https://sampwiki.blast.hk/wiki/SetTimerEx

That's one you should be looking at right now
Reply
#5

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
That piece of code is a bit off, you're calling a callback but without giving it the parameter it looks for? That means this timer will only work for a single person (id 0), because the value of playerid will default to 0 since you're not passing another value to it.

Instead of using SetTimer for this example, you would need to use SetTimerEx and pass an ID along to the callback, like it's expecting you to! For example:

pawn Код:
SetTimerEx("Trolo", 10000, false, "i", playerid);
Depending on what you wish to send of course this could be modified.

Please make sure you're posting proper examples in this section when responding to threads, otherwise people will be mis-lead by in-correct information!

As for the original poster, I recommend instead of waiting for help here, that you use the SA-MP Wiki which has absolutely tons of extremely detailed information on all of the functions you can make use of.

https://sampwiki.blast.hk/wiki/SetTimerEx

That's one you should be looking at right now
Haha okay, will take my time to look at this info :]

EDIT:

Looking over it, im understanding that except one part,

public message(second, msg[])

I know i would replace "message" with my timer's name but what about "second, msg"? i dont think i see anything about it.

Also, activating the timer, when the command is activated. Would the timer still go under OnGameModeInt?
Reply
#6

Quote:
Originally Posted by Shockey HD
Посмотреть сообщение
Haha okay, will take my time to look at this info :]

EDIT:

Looking over it, im understanding that except one part,

public message(second, msg[])

I know i would replace "message" with my timer's name but what about "second, msg"? i dont think i see anything about it.

Also, activating the timer, when the command is activated. Would the timer still go under OnGameModeInt?
The name "message" is the name of the callback, it's the name you need to use in the timer function in order to execute the callback in a set amount of time. "second" and "msg[]" are parameters, second is an integer and msg is a string. These are the parameters that the user passes to the callback in order to define the message to be sent and the amount of seconds it took, it's actually a strange example, but it does explain things.

Activating the timer should be done wherever you are planning on activating it, it doesn't have to be done under OnGameModeInit or any other callback. If you want it to be activated when someone writes a command, then put it under the command in OnPlayerCommandText!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)