How To Send Only 1 Message
#1

Hi Guys When In The Speed Radar Area It Send Me Like 100 Message's How I Make It To Send Only 1 Message
My Code :
pawn Код:
#include <a_samp>

#include <zcmd>

#define CreatRadar CreateObject
#define Radar 18880

new Str[256];

#if defined FILTERSCRIPT

#endif

stock SpeedCapture(playerid)
{
    new Car, Float:x, Float:y, Float:z, Float:Speed, Init;
    Car = GetPlayerVehicleID(playerid);
    GetVehicleVelocity(Car, x, y, z);
    Speed = floatsqroot(((x*x))+((y*y))+((z*z)))*178.275;
    Init = floatround(Speed, floatround_round);
    format(Str, sizeof(Str), "{FFFFFF}Speed : {FFFF00}%i", Init);
    return Str;
}

forward Message(playerid);

public Message(playerid)
{
   PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
   SendClientMessage(playerid, 0xFFFFFFFF, SpeedCapture(playerid));
   return 1;
}

public OnPlayerUpdate(playerid)
{
    new State;
    State = GetPlayerState(playerid);
    if(State == PLAYER_STATE_DRIVER)
    {
       if(IsPlayerInRangeOfPoint(playerid, 50.0, 2048.6465,1343.9629,10.6719))
       {
          SetTimer("Message", 1000, false);
       }
    }
    return 1;
}
Thx For Helping !.
Reply
#2

Because OnPlayerUpdate gets called LOTS of times each second!
Reply
#3

Kyance is right, I was wonderd how ofter it would be called so I just tested it:

pawn Код:
new updates;

public OnPlayerUpdate(playerid)
{
    updates++;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    printf("Updates: %d" , updates);
    return 1;
}
Result: in just 10 seconds of walking around OnPlayerUpdate was called 235 times.
Reply
#4

OnPlayerUpdate is called every 30 ms as far as I remember.
Reply
#5

Add a new variable named whatever you want somewhere on top of the script.
Let's say it's:
pawn Код:
new speedcapmsggiven[MAX_PLAYERS]
Then like this:
pawn Код:
public OnPlayerUpdate(playerid)
{
    new State;
    State = GetPlayerState(playerid);
    if(State == PLAYER_STATE_DRIVER)
    {
        if(IsPlayerInRangeOfPoint(playerid, 50.0, 2048.6465,1343.9629,10.6719) && speedcapmsggiven[playerid] == 0)
        {
            SetTimer("Message", 1000, false);
            speedcapmsggiven[playerid] = 1;
        }
        else if(!IsPlayerInRangeOfPoint(playerid, 50.0, 2048.6465,1343.9629,10.6719)
        {
            speedcapmsggiven[playerid] = 0;
        }
    }
    return 1;
}
So now if player is in range of the camera and speedcapmsggiven variable is 0, it'll send the message and speedcapmsggiven variable will be set to 1. The message won't come up unless you leave the zone and come back.

You're welcome
Reply
#6

You could keep a variable with a delay. When you get the message, the delay will be turned to true. Whilst it is true you won't recieve the message, after x amount of seconds you could turn the variable back to false.
Reply
#7

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
OnPlayerUpdate is called every 30 ms as far as I remember.
No!

OnPlayerUpdate called with every update packet (player sync, vehicle sync, passenger sync, spectaror sync(?)), so the calling frequency depends on how much packets are you sending to the server. Try to put SendClientMessage under OnPlayerUpdate, then try to move and press a lot of keys, then try to stay and don't do anything.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)