SA-MP Forums Archive
How To Send Only 1 Message - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How To Send Only 1 Message (/showthread.php?tid=547840)



How To Send Only 1 Message - UltraScripter - 25.11.2014

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 !.


Re: How To Send Only 1 Message - Kyance - 25.11.2014

Because OnPlayerUpdate gets called LOTS of times each second!


Re: How To Send Only 1 Message - Schneider - 25.11.2014

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.


Re: How To Send Only 1 Message - Beckett - 25.11.2014

OnPlayerUpdate is called every 30 ms as far as I remember.


Re: How To Send Only 1 Message - Capua - 25.11.2014

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


Re: How To Send Only 1 Message - AnthonyTimmers - 25.11.2014

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.


Re: How To Send Only 1 Message - kurta999 - 25.11.2014

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.