OnPlayerUpdate or not
#1

Hey I have question, I want to make drug addiction system but lets say if player is addicted and if I put if statement under OnPlayerUpdate is this smart choice? Or should I make new call back and one timer that will be checking if player is addicted, how should I make that thing..?
Reply
#2

onplayerupdate is called very frequently per second per player. It's not a good idea to use it. I suggest making a timer instead. Maybe 0.5 to 1 second.
Reply
#3

you could set a variable like
pawn Код:
IsAddict[playerid]=1;
and then your always addicted.
If you want a player to be addicted for some ammount of time then use a timer
Reply
#4

No make a timer which checks each 1 Second
Reply
#5

Okay for example new callback and timer that will be checking that timer every 1 second:

new timer...

SetTimerEx..."Addicted" 1000

public Addicted
{
if(addicted... == 1)
{
Here?

Timer will be checking if player is addicted right? but I need to make some effect like loosing health every 5 minutes if player will be addicted, but that means if I will put timer under if statement that is checked every 1 second by timer it will start mulitply timers and it will fuck up my code?
Reply
#6

Yes, when that one thousand millisecond (1sec) is done it will call the function. If you want to reduce his HP start another timer inside that IF statement inside your Addiced time function which will reduce %d hp per 5 minutes..
pawn Код:
forward Addicted(playerid);

public Addicted(playerid);
{
    if(isAddict[playerid] == 1)
    {
        SetTimerEx(); // your new timer here.
    }
    else
    {
      return 0; // Return 0 aka nothing.
    }
}
Reply
#7

Yes I understand that but won't that 1 sec timer call other timer many times? because player is addicted and there is if statement about that if player is addicted it will call timers every second.. ? This is what I want to know and how to make it so it will call second timer only once
Reply
#8

Ah that's what you meant then assign a variable that says that the 5 minutes timer has started in your addicted check. Let me write you an example..
pawn Код:
new addictedtimercalled = 0; // dont assign this to MAX_PLAYERS because it's checking if the timer has been called or not
forward Addicted(playerid);
forward hpreduction(playerid);
public Addicted(playerid)
{
    if(addictedtimercalled == 1) return 0;
    if(isAddict[playerid] == 1)
    {
        SetTimerEx(); // your new timer here.
        addictedtimercalled = 1;
    }
}
public hpreduction(playerid)
{
    // your health decreasing code goes here(?)
    addictedtimercalled = 0;
}
Reply
#9

I think this code is exactly what I'm looking for, thank you rep for all of you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)