OnPlayerWeaponShot message
#1

Hello guys so I am scripting a system so when you fire for example a Shotgun then the police will get an automatic warning, you know like neighbours calls the police.

So the system works fine but I have one problem, when the players fires the gun they of course dont fire one shot. Its multiple shots and it spams the police officers chats..

So how can I make it so only one message is sent?
Reply
#2

Timestamps.

pawn Код:
new g_FiredTime[MAX_PLAYERS];
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if ((gettime() - g_FiredTime[playerid]) > 60)
    {
        // alert cops

        g_FiredTime[playerid] = gettime();
    }
    return 1;
}
Make sure you clear the variable upon connection:

pawn Код:
public OnPlayerConnect(playerid)
{
    g_FiredTime[playerid] = 0;
}
This will only send the warning every 60 seconds a player is shooting. Change "60" to your time.
Reply
#3

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Timestamps.

pawn Код:
new g_FiredTime[MAX_PLAYERS];
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if ((gettime() - g_FiredTime[playerid]) > 60)
    {
        // alert cops

        g_FiredTime[playerid] = gettime();
    }
    return 1;
}
Make sure you clear the variable upon connection:

pawn Код:
public OnPlayerConnect(playerid)
{
    g_FiredTime[playerid] = 0;
}
This will only send the warning every 60 seconds a player is shooting. Change "60" to your time.
Thanks man! I was thinking of something like this but I've never made a timestamp :3

+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)