26.01.2014, 16:01
(
Last edited by Emmet_; 28/02/2016 at 12:45 PM.
)
New SA-MP callbacks
Here is a collection of useful callbacks for scripters to use. Ideas for new callbacks are welcome!
Callback list
Function list
Action types for GetPlayerAction and OnPlayerActionChange:
Garage types for OnPlayerUseGarage and IsPlayerNearGarage:
Vending machine types for OnPlayerUseVending and IsPlayerNearVending:
Code examples
Download
Pastebin
GitHub
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.
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.
pawn Code:
#define PLAYER_ACTION_NONE 0
#define PLAYER_ACTION_SHOOTING 1
#define PLAYER_ACTION_SWIMMING 2
#define PLAYER_ACTION_SKYDIVING 3
pawn Code:
#define GARAGE_BOMBSHOP 1
#define GARAGE_PAYNSPRAY 2
pawn Code:
#define VENDING_TYPE_SPRUNK 1
#define VENDING_TYPE_CANDY 2
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;
}
Pastebin
GitHub