[Include] New SA-MP callbacks!
#1

New SA-MP callbacks

Here is a collection of useful callbacks for scripters to use. Ideas for new callbacks are welcome!

Callback list
pawn Code:
OnPlayerPause(playerid)
Description: Called when a player is paused.

OnPlayerResume(playerid, time)
Description: Called when a player has resumed.

OnPlayerHoldingKey(playerid, keys)
Description: Called when a player begins holding a specific key.

OnPlayerReleaseKey(playerid, keys)
Description: Called when a player releases a key.

OnPlayerFall(playerid, Float:damage)
Description: Called when a player falls and loses damage.

OnPlayerPacketLoss(playerid, Float:newpacket, Float:oldpacket)
Description: Called when a player experiences packet loss.

OnPlayerUseVending(playerid, type)
Description: Called when a player uses a vending machine.

OnPlayerCrashVehicle(playerid, vehicleid, Float:damage)
Description: Called when a player crashes a vehicle.

OnPlayerFPSChange(playerid, oldfps, newfps)
Description: Called when a player's FPS rate changes.

OnPlayerJackVehicle(playerid, targetid, vehicleid)
Description: Called when a player jacks another player'
s vehicle.

OnPlayerEmptyWeapon(playerid, weaponid)
Description: Called when a player depletes all ammo in a weapon.

OnPlayerFriendlyFire(playerid, targetid, weaponid)
Description: Called when a player shoots at a teammate.

OnPlayerTargetPlayer(playerid, targetid, weaponid)
Description: Called when a player targets a player with their weapon.

OnPlayerHideCursor(playerid, hovercolor)
Description: Called when a player cancels textdraw selection.

OnPlayerAntiReload(playerid, weaponid)
Description: Called when a player shoots without reloading their weapon.

OnPlayerAnimationPlay(playerid, animlib[], animname[])
Description: Called when an animation is played.

OnPlayerReloadWeapon(playerid, weaponid, ammo)
Description: Called when a player reloads their weapon.

OnPlayerActionChange(playerid, oldaction, newaction)
Description: Called when a player's action change (see action list).

OnPlayerRamPlayer(playerid, driverid, vehicleid, Float:damage)
Description: Called when a player rams another player.

OnPlayerSprayAtVehicle(playerid, vehicleid)
Description: Called wehn a player is spraying at a vehicle.

OnPlayerStartBurn(playerid)
Description: Called when a player is burning from fire.

OnPlayerStopBurn(playerid)
Description: Called when a player stops burning.

OnPlayerStartAim(playerid, weaponid)
Description: Called when a player is aiming a weapon.

OnPlayerStopAim(playerid)
Description: Called when a player stops aiming.

OnPlayerUseCamera(playerid)
Description: Called when a player snaps a picture with a camera (weapon ID: 43).

OnPlayerJump(playerid)
Description: Called when a player jumps (SHIFT key).

OnPlayerUseGarage(playerid, vehicleid, type)
Description: Called when a player uses a Pay'
n'Spray or bomb shop.

OnVehicleCreated(vehicleid, color1, color2)
Description: Called when a vehicle is created by the server.
Function list
Code:
IsPlayerPaused(playerid)
Description: Returns 1 if the player is paused.

IsPlayerSkydiving(playerid);
Description: Returns 1 if the player is skydiving.

IsPlayerSwimming(playerid)
Description: Returns 1 if the player is swimming.

IsPlayerBurning(playerid)
Description: Returns 1 if the player is burning.

IsPlayerAiming(playerid)
Description: Returns 1 if the player is aiming a weapon.

IsPlayerJumping(playerid)
Description: Returns 1 if the player is jumping.

IsPlayerNearVending(playerid, type)
Description: Returns 1 if the player is near the specified vending machine type.

IsPlayerSprayingVehicle(playerid, vehicleid)
Description: Returns 1 if the player is spraying the specified vehicle with a spraycan (weapon ID: 41).

IsPlayerNearGarage(playerid, type)
Description: Returns 1 if the player is near the specified garage type.

GetPlayerAction(playerid)
Description: Returns the player's current action.

Float:GetPlayerPacketLoss(playerid)
Description: Returns the player's packet loss.

GetPlayerPausedTime(playerid)
Description: Returns the time the player has been paused (in milliseconds).

GetPlayerFPS(playerid)
Description: Returns the player's FPS.
Action types for GetPlayerAction and OnPlayerActionChange:

pawn Code:
#define PLAYER_ACTION_NONE      0
#define PLAYER_ACTION_SHOOTING  1
#define PLAYER_ACTION_SWIMMING  2
#define PLAYER_ACTION_SKYDIVING 3
Garage types for OnPlayerUseGarage and IsPlayerNearGarage:

pawn Code:
#define GARAGE_BOMBSHOP         1
#define GARAGE_PAYNSPRAY        2
Vending machine types for OnPlayerUseVending and IsPlayerNearVending:

pawn Code:
#define VENDING_TYPE_SPRUNK     1
#define VENDING_TYPE_CANDY      2
Code examples
pawn Code:
public OnPlayerUseGarage(playerid, type)
{
    if(type == GARAGE_PAYNSPRAY)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You have been charged $100 for respraying your vehicle.");
        PlayerInfo[playerid][pMoney] -= 100;
    }
    else if(type == GARAGE_BOMBSHOP)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You have been charged $500 for using the bomb shop.");
        PlayerInfo[playerid][pMoney] -= 500;
    }
    return 1;
}
pawn Code:
public OnPlayerResume(playerid, time)
{
    new
        string[48];

    format(string, sizeof(string), "You've been paused for %i milliseconds.", time);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
}
pawn Code:
public OnPlayerActionChange(playerid, oldaction, newaction)
{
    if (newaction == PLAYER_ACTION_SHOOTING)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You are now shooting a weapon.");
    }
    else if (newaction == PLAYER_ACTION_SKYDIVING)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You are now skydiving.");
    }
    else if (newaction == PLAYER_ACTION_SWIMMING)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You are now swimming.");
    }
}
pawn Code:
public OnPlayerStartBurn(playerid)
{
    // Attach a fire particle to this player so other players can see them burning!
    SetPlayerAttachedObject(playerid, 0, 18691, 1);
    return 1;
}

public OnPlayerStopBurn(playerid)
{
    RemovePlayerAttachedObject(playerid, 0);
    SendClientMessage(playerid, COLOR_WHITE, "You have stopped burning.");
    return 1;
}
Download
Pastebin
GitHub
Reply
#2

Looks very nice! I'll definately use some of these functions in my script.
Reply
#3

Emmet for Dev. Team 2014
Reply
#4

Quote:
Originally Posted by Abagail
View Post
Emmet for Dev. Team 2014
wat


Good work Emmet.
Reply
#5

Another good work.
keep going.!
Reply
#6

Those are very usefull, great job Emmet!
Reply
#7

....
Reply
#8

This is very usefull nice job Emmet
Reply
#9

The onplayerfall one, wouldn't that work for an anti airbreak?
Reply
#10

Suggestion:
pawn Code:
stock GetPlayerInactiveTime(playerid)
There is 'time' param in the OnPlayerResume so why not add this as a function. Anyway good include i will use it in my gamemode (Less work making AFK system )
Reply
#11

Cheers Emmet! I'll be using these.
Reply
#12

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Thanks, everyone.
Thanks for the suggestion, added (but I used "GetPlayerPausedTime" instead).
Thank you
Reply
#13

Why not add a poll update that will keep updating several times a seconds.
Reply
#14

Good work, Emmet_.
Seems interesting callback OnPlayerPause.
Reply
#15

Awesome work man, helped me out a lot.
Reply
#16

This function
pawn Код:
forward OnPlayerHoldingKey(playerid, keys);
I guess it's only for GetPlayerKey's avaible no?

Btw, very useful!
Reply
#17

Not bad. Might come useful.
Reply
#18

Thanks, everyone. I'm planning on adding some more callbacks in mind once my PC is fixed.

Quote:
Originally Posted by Edvin
Посмотреть сообщение
This function
pawn Код:
forward OnPlayerHoldingKey(playerid, keys);
I guess it's only for GetPlayerKey's avaible no?

Btw, very useful!
Yes, since that's how SA-MP handles keys.

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Why not add a poll update that will keep updating several times a seconds.
That's my next step! Unfortunately, I don't think I can add a poll to a thread that's created already.
Reply
#19

Quote:
Originally Posted by ******
Посмотреть сообщение
How is "OnPlayerHoldingKey" different to "OnPlayerKeyStateChange"?
I'd say nothihg, but this makes the job easier because there's a callback that has been made called OnPlayerReleaseKey instead of using the code below and I think it shortens the code up.

pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

#define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))

#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if( PRESSED( keys ) && HOLDING( keys ) )
    {

    }
    else if( RELEASED( keys ) )
    {

    }
    return true;
}
Reply
#20

Another great release EMMAAT. I'm expecting this include to have more cool features and I can assure that it would get updated with useful callbacks.

Btw, the pausing system's timer is being called every 600ms and detects if OPU is called or not. From my experience, OPU might get paused when a player is entering a vehicle, or is at dead state. It would be good if OPU is set to true under OnPlayerStateChange too. Sorry if I'm wrong, but I've experienced such things with 0.3x R1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)