[Include] svAddons - Useful Scripting Addons
#1

Introduction

This script adds some useful functions that the SA:MP team decided to not include in the default server package. This include requires your server to be running on 0.3e.


Functions

FunctionActionReturns
SetPlayerSpecialAction(playerid, actionid)If the special action is USECELLPHONE or STOPUSECELLPHONE, it will automatically attach/detach the phone1
IsPlayerInWater(playerid) or IsPlayerSwimming(playerid)Checks if a player is swimming1 if the player is swimming, otherwise 0
SetPlayerPosEx(playerid, Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0, Float: angle = 0.0)Sets a player's position, virtual world, interior, and angle1
GetPlayersName(playerid)Gets the player's nameThe player's name
GetPlayersNameEx(playerid)Gets the player's name and removes the underscoresThe player's name without underscores
CrashPlayer(playerid)Crashes the player1
GetPlayersIP(playerid)Gets the player's IPThe player's IP
ExplodePlayer(playerid)Explodes a player1
ExplodeVehicle(vehicleid)Explodes a vehicle1
SetPlayerMoney(playerid, amount)Sets the players money1
GivePlayerJetpack(playerid)Gives the player a jetpack1
IsPlayerSpawned(playerid)Checks if the player is spawned1 if the player is spawned, otherwise 0
GetVehicleInfo(vehicleid, infoType)Gets the status of one of the vehicle parameters (for infoType you can use VEHICLE_INFO_PARAMNAME)The status of the vehicle parameter
SetVehicleInfo(vehicleid, infoType, value)Sets the status of one of the vehicle paramters (for infoType you can use VEHICLE_INFO_PARAMNAME)1
IsPlayerInVehicleFireMode(playerid)Checks if the player is drivebying as a passenger1 if the player is drivebying as a passenger, otherwise 0
GetVehicleDriver(vehicleid)Gets the driver of the vehicleThe driver's ID
GetVehiclePassengers(vehicleid, &passengerOne = INVALID_PLAYER_ID, &passengerTwo = INVALID_PLAYER_ID, &passengerThree = INVALID_PLAYER_ID)Gets the vehicle's passengers (will not retrieve more than the first 3 passengers for bus/coach)The vehicle's passengers for each seat
GetVehicleNumberPlate(vehicleid)Gets the vehicle's license plateThe vehicle's license plate
IsPlayerSpectating(playerid)Checks if the player is spectating1 if the player is spectating, otherwise 0
GetPlayerObjectEditingState(playerid)Gets the player's object editing state (OBJECT_EDITING_STATE_NONE, NORMAL, PLAYER, ATTACHED)The player's object editing state
GetPlayerEditingObject(playerid)Gets the object the player is editing (attached object index if editing attached object)The object the player is editing
RemovePlayerWeapon(playerid, weaponid)Removes a weapon from a player1
ClosePlayerDialog(playerid)Closes a player's dialog1
SetPlayerDeathEffect(playerid, deffid)Sets the player's death effect (DEATH_EFFECT_NONE, REDGAS, SMOKE, EXPLODE, MINIEXPLODE, FIRE)1
GetPlayerDeathEffect(playerid)Gets the player's death effectThe player's death effect
DisableSprunkMachines()Used in OnGameModeInit to remove all sprunk machines from the map1
ChangeServerPassword(password[])Changes the server password1
LoadFilterscript(scriptName[], bool: reload = false)Loads a filterscript1
UnloadFilterscript(scriptName[])Unloads a filterscript1
ChangeServerName(serverName[])Changes the server name1
SendServerRCONMessage(message[])Sends a message to the server via RCON 'say' command1
SendMessageToRCONAdmins(color, message[])Sends a message to all in-game RCON admins1
ChangeServerWebsite(url[])Changes the server's website URL1
ChangeMapName(mName[])Changes the server's map name1
IsValidSkin(skinID)Checks if the skin is valid1 is the skin is valid, otherwise 0
ClearPlayersChat(playerid, bool: includeScrollingChat = false)Clears the player's currently displayed chat or all chat1
ClearAllPlayersChat(bool: includeScrollingChat = false)Clears all of the player's currently displayed chat or all chat1
TeleportPlayerToPlayer(playerid, giveplayerid, Float: offsetX = 1.0, Float: offsetY = 0.0, Float: offsetZ = 0.0)Teleports a player to another player1
StopVehicleMovement(vehicleid)Smoothly stops a vehicle's movement1
GetVehicleSpeed(vehicleid)Gets the vehicle's speedThe vehicle's speed
GetVehicleModelName(modelID)Gets the name of the vehicle model IDThe vehicle model ID's name
GetVehicleIDFromName(string[], bool: useFind = false)Gets a vehicle's model ID from a nameThe vehicle's model ID
GetWeaponID(weaponName[], bool: ignoreCase = true, bool: useFind = false)Gets a weapon's ID from a weapon's nameThe weapon's ID
GetPlayerIDFromIP(ip[], bool: useFind = false)Gets the player ID that has specified IPThe player's ID
CountTotalPlayers()Gets the amount of connected playersThe amount of connected players
CountTotalRCONAdmins()Gets the amount of connected RCON adminsThe amount of connected RCON admins
CountTotalNPCs()Gets the amount of connected NPCsThe amount of connected NPCs
CountTotalPausedPlayers()Gets the amount of connected paused playersThe amount of connected paused players
GetVehiclesAngle(vehicleid)Gets the vehicle's angleThe vehicle's angle
GetVehiclesHealth(vehicleid)Gets the vehicle's healthThe vehicle's health
GetPlayersHealth(playerid)Gets the player's healthThe player's health
GetPlayersArmour(playerid)Gets the player's armorThe player's armor
EnableWhitelist(mode = WHITELIST_MODE_ALLOWPLAYER, ip[] = "")Enables RCON whitelisting with several modes (WHITELIST_MODE_NONE, ALLOWPLAYER, SPECIFICIP, IP_FIND)1
GetWhitelistMode()Gets the server's RCON whitelist modeThe server's RCON whitelist mode
AddPlayerToWhitelist(playerid)Adds a player to the RCON whitelist1
IsPlayerWhitelisted(playerid)Checks if a player is on the RCON whitelist1 if the player is on the RCON whitelist, otherwise 0
GetVehicleInterior(vehicleid)Gets a vehicle's interiorThe vehicle's interior
IsPlayerBehindVehicle(playerid, vehicleid)Checks if a player is behind a vehicle1 if the player is behind the vehicle, otherwise 0
ShakePlayerScreen(playerid, duration = 1250)Shakes a player's screen1
ReconnectPlayer(playerid)Reconnects a player to the server without closing their game1
GetVehicleTrailerCount(vehicleid)Gets the amount of trailers attached to the vehicleThe amount of trailers attached to the vehicle
GetFreeVehicleSeat(vehicleid)Gets the next free seat in a vehicleIf a seat is available, the seat id, otherwise INVALID_VEHICLE_ID
GetVehicleSpawnInfo(vehicleid, &Float: spawnX, &Float: spawnY, &Float: spawnZ, &Float: spawnR, &color1, &color2, &respawndelay)Gets the information the vehicle was spawned withThe information the vehicle was spawned with
CapitalizePlayerName(playerid)Capitalizes a player's name (including letters after underscores)1
GetPlayerTemporaryName(playerid)Gets a temporary name for the player if you need to use their name for somethingThe player's temporary name
GetStringCharacterCount(string[], character)Gets the amount of the specified character in a stringThe amount of the specified character in the string
SetVehiclePosEx(vehicleid, Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0, Float: angle = 0.0)Sets a vehicle's position, rotation, interior, and virtual world1
SendNearbyClientMessage(color, message[], Float: distance = 30.0, Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0)Sends a client message to players near the specified point1
GameTextForNearbyPlayers(text[], time, style, Float: distance = 30.0, Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0)Displays game text on the screen of players that are near the specified point1
ToggleNearbyPlayersControllable(bool: controllable, Float: distance = 30.0, Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0)Toggles weather players near the point can move and turn their camera1
TogglePlayerKickImmunity(playerid, bool: immune)Decides weather the player can be kicked or not1
GetPlayerKickImmunity(playerid)Gets the player's kick immunity statusThe player's kick immunity status
TogglePlayerBanImmunity(playerid, bool: immune)Decides weather the player can be banned or not1
GetPlayerBanImmunity(playerid)Gets the player's ban immunity statusThe player's ban immunity status
CreateTriggerPoint(Float: posX, Float: posY, Float: posZ, interior = 0, virtualworld = 0)Creates an invisible trigger point at the specified location which calls OnPlayerTouchTrigger when a player touches itThe trigger's ID
StartCountdown(from = 3)Starts a countdown for all playersThe timer's ID
SendClientAudioMessage(playerid, message[], bool: withClientMessage = false, color = -1, language[] = "en")Sends a message to the player in an audio stream (****** Translator)1
DealPlayerDamage(playerid, damage)Deals a certain amount of damage to a player (checks weather to take health, armor, or both)1
TeleportPlayers(Float: posX, Float: posY, Float: posZ, interior, virtualworld, Float: angle, ...)Teleports an unlimited amount of players to a location - Untested1
CountTotalVehicles()Gets the amount of vehicles createdThe amount of vehicles created
IsVehicleOccupied(vehicleid)Checks if the vehicle is occupied0 if no, otherwise 1
IsPlayerDrivingVehicle(playerid, vehicleid = INVALID_VEHICLE_ID)Checks if a player is driving a vehicle0 if no, otherwise 1
TeleportPlayerToVehicle(playerid, vehicleid, Float: offsetX = 1.0, Float: offsetY = 0.0, Float: offsetZ = 0.0)Teleports a player to a vehicle1
GetPickupPos(pickupid, &Float: X, &Float: Y, &Float: Z)Gets a pickup's position1
GetPickupVirtualWorld(pickupid)Gets a pickup's virtual world1
HideAllTextDraws()Hides all text draws for all players1
HideAllTextDrawsForPlayer(playerid)Hides all text draws for the specified player1
GetSkinGender(skinid)Get's the specified skin's genderThe skin's gender (SKIN_GENDER_NONE, SKIN_GENDER_MALE, SKIN_GENDER_FEMALE)
TogglePlayerWeaponSwitch(playerid, bool: togws)Toggles weather the player can switch weapons or not1
IsMeleeWeapon(weaponid)Checks if the specified weapon is a melee weapon1 if the weapon is a melee weapon, otherwise 0
IsPlayerPaused(playerid) or IsPlayerTabbed(playerid)Checks if a player is paused1 if the player is paused, otherwise 0
GetPlayerControllable(playerid)Checks if a player can control himself1 if the player can control himself, otherwise 0
divideRem(a, b, &answer, &remainder)Divides two numbers and retrieves the answer with the remainder1
CountTotalObjects()Counts the total objects currently created on the serverThe total objects currently created on the server
GetServerStats(&connections, &kicks, &vehicles, &objects, &players, &totalvehicles, &totalobjects, &kills, &deaths, &totaldamage, mode = SERVER_STATS_UPTIME, bool: errorContinue = true)Retrieves the server's stats1

Callbacks

CallbackCall Time
OnVehicleCreate(vehicleid)Called when a vehicle is created (not respawned)
OnPlayerPausedUpdate(playerid, bool: paused)Called when a player pauses or unpauses
OnPlayerWeaponUpdate(playerid, newgun, oldgun)Called when a player changes their weapon
OnReceiveClientMessage(playerid, color, message[])Called when a player receives a client message (includes audio stream message and does not include SendClientMessageToAll)
OnRconLoginBlocked(playerid, ip[], password[], success)Called when a player is blocked by the RCON whitelist feature
OnPlayerWaterStatusUpdate(playerid, bool: inWater)Called when a player enters or exits water
OnPlayerSpecialActionChange(playerid, oldaction, newaction)Called when a player's special action changes (not yet working for sprunk and cigars)
OnPlayerTouchTrigger(playerid, triggerid)Called when a player touches a trigger created with CreateTriggerPoint

Maximum Definitions

DefinitionValue
MAX_INTEGER_LENGTH12
MAX_IP_LENGTH17
MAX_WEAPON_NAME24
MAX_CLIENT_MESSAGE128
MAX_WEAPON_AMMO32767
MAX_INTEGER_VALUE2147483647

Preset Variable Sizes

You can now define variables using a couple of new macros I have created. They have preset sizes specifically for the function they'll be used for.

DeclarationSize
S_IP[variable name]17
S_Player[variable name]MAX_PLAYER_NAME or 24
S_Weapon[variable name]MAX_WEAPON_NAME (custom definition) or 24
S_Chat[variable name]MAX_CLIENT_MESSAGE (custom definition) or 128

Bugs and Suggestions

Please reply to this thread with your bug report or suggestion for the include. All of these posts will be reviewed carefully and dealt with.


Versions

The download links and the include itself will be updated occasionally.

Version 1.4 - Pastebin | Mediafire | Assembla Direct Download
Version 1.3 - Pastebin | Mediafire | Assembla Direct Download
Version 1.2 - Pastebin | Mediafire | Assembla Direct Download
Version 1.1 - Pastebin | Mediafire | Assembla Direct Download
Version 1.0 - Pastebin | Mediafire | Assembla Direct Download



Don't want to wait for updates?

I'm currently uploading all of my changes to an Assembla account. Assembla will be updated before updates are released. If you wish to get the files directly from Assembla, use SVN Checkout with this URL: https://subversion.assembla.com/svn/sv-libraries/

My latest updates to Assembla are below:




Changelog

VersionChange
Version 1.4Added preset variable sizes (more information available above)
Version 1.4Added maximum value defines for several things (more information available above)
Version 1.4Added the structure for the soon to come DisableLagShooting function
Version 1.4Added GetServerStats function
Version 1.4Added CountTotalObjects function
Version 1.4Added divideRem function
Version 1.4Added GetPlayerControllable function
Version 1.4Added IsMeleeWeapon function
Version 1.4Added IsPlayerPaused or IsPlayerTabbed function
Version 1.4Added TogglePlayerWeaponSwitch function
Version 1.4Added GetSkinGender function
Version 1.4Added HideAllTextDrawsForPlayer function
Version 1.4Added HideAllTextDraws function
Version 1.3Added GetPickupVirtualWorld function
Version 1.3Added GetPickupPos function
Version 1.3Added TeleportPlayerToVehicle function
Version 1.3Added IsPlayerDrivingVehicle function
Version 1.3Added IsVehicleOccupied function
Version 1.3Added CountTotalVehicles function
Version 1.3Added TeleportPlayers function
Version 1.2Added DealPlayerDamage function
Version 1.2Added SendClientAudioMessage function
Version 1.2Added StartCountdown function
Version 1.2Added CreateTriggerPoint function
Version 1.2Added TogglePlayerBanImmunity and GetPlayerBanImmunity functions
Version 1.2Added TogglePlayerKickImmunity and GetPlayerKickImmunity functions
Version 1.2Added ToggleNearbyPlayersControllable function
Version 1.2Added GameTextForNearbyPlayers function
Version 1.2Added SendNearbyClientMessage function
Version 1.2Added SetVehiclePosEx function
Version 1.2Added GetStringCharacterCount function
Version 1.2Added GetPlayerTemporaryName function
Version 1.2Added CapitalizePlayerName function
Version 1.2Added GetVehicleSpawnInfo function
Version 1.2Added GetFreeVehicleSeat function
Version 1.2Added OnPlayerSpecialActionChange and OnPlayerTouchTrigger callbacks
Version 1.1Added OnPlayerWaterStatusUpdate callback
Version 1.1Added ReconnectPlayer and GetVehicleTrailerCount functions
Version 1.1Removed IsPlayerInSpray function due to issues with camera mode detection
Version 1.0Created the script

Using

To begin using this include, drag the file to your pawno > includes folder and put

pawn Код:
#include <svAddons>
at the top of your script.


Credits

SuperViper - Creating the script
Reply
#2

Well done, some really useful functions. Granted some have been posted before, but great all the same.
Reply
#3

omg nice functions, thanks a lot
Reply
#4

O: very userfull, tnx dude
Reply
#5

Код:
stock IsPlayerInSpray(playerid)
{
        return (GetPlayerCameraMode(playerid) == 15) ? 1 : 0;
}
Someone did not do his homework. This is very unreliable and the Wiki is quite wrong here. I regret that I can't change it, I don't have a Wiki account. (I have asked, no response.)

Yes, camera mode 15 is Pay & Spray. But Pay & Spray is not the only camera mode 15. I prefer calling camera mode 15 'scripted static camera'. It's used for a lot of different stuff, like:
  • Entering and exiting interiors through the normal enex, the small cutscene of the player walking through the door is camera mode 15.
  • The mod shops are camera mode 15.
  • Some of the chasing sequences are camera mode 15.
  • Buying food at fast food restaurants (Pizza shop, Burger Shot, Cluckin' Bell...) sets you in camera mode 15.
  • SetPlayerCameraPos is camera mode 15.
They have all one thing in common: the location where the camera itself is located, isn't moving at all. (Like following a player, or attached to a vehicle) It's as static as it can be. The direction the camera is looking does change in some cases, for example with the chasing cameras.
Reply
#6

Really useful, thanks
Reply
#7

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
Код:
stock IsPlayerInSpray(playerid)
{
        return (GetPlayerCameraMode(playerid) == 15) ? 1 : 0;
}
Someone did not do his homework. This is very unreliable and the Wiki is quite wrong here. I regret that I can't change it, I don't have a Wiki account. (I have asked, no response.)

Yes, camera mode 15 is Pay & Spray. But Pay & Spray is not the only camera mode 15. I prefer calling camera mode 15 'scripted static camera'. It's used for a lot of different stuff, like:
  • Entering and exiting interiors through the normal enex, the small cutscene of the player walking through the door is camera mode 15.
  • The mod shops are camera mode 15.
  • Some of the chasing sequences are camera mode 15.
  • Buying food at fast food restaurants (Pizza shop, Burger Shot, Cluckin' Bell...) sets you in camera mode 15.
  • SetPlayerCameraPos is camera mode 15.
They have all one thing in common: the location where the camera itself is located, isn't moving at all. (Like following a player, or attached to a vehicle) It's as static as it can be. The direction the camera is looking does change in some cases, for example with the chasing cameras.
I don't focus on any function specifically making sure that it works just like wiki stated. I assume the wiki is correct because it's an official SA:MP wiki listed with every function. If it doesn't work, simply don't use it.
Reply
#8

The SA:MP wiki is edited by anyone (that has an account) - so it's not OFFICIAL OFFICIAL.
Reply
#9

Nice man
Reply
#10

Wonderful! 'ShakePlayerScreen' seems great for drunk players.
Reply
#11

Very useful. Thanks for sharing.

Edit: Is possibile to Play 2 sounds at once? (Using AudioStream 0.3d function)
Reply
#12

Good work. I'm only not sure if you're allowed to release a code to crash players.
Reply
#13

Some of them are not even 'Useful' but anyway.
Nice job.
Reply
#14

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Good work. I'm only not sure if you're allowed to release a code to crash players.
Do you need any authorization to release a crash-player code? Since when? :/
Reply
#15

Thanks a lot for releasing this
Well done, this will surely help a lot of people and save a lot of time.


Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Good work. I'm only not sure if you're allowed to release a code to crash players.
I believe that code could be used to make a /reconnect command.
Reply
#16

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Very useful. Thanks for sharing.

Edit: Is possibile to Play 2 sounds at once? (Using AudioStream 0.3d function)
There are no custom audio functions at the moment. I was planning to have audio looping and other features for it, but it kept crashing so I had to remove it for now.

It's not possible to play 2 sounds at once.

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Good work. I'm only not sure if you're allowed to release a code to crash players.
It's a function used by the server, why wouldn't it be allowed?

Quote:
Originally Posted by Roperr
Посмотреть сообщение
I believe that code could be used to make a /reconnect command.
It actually crashes the game, it can't be used for a /reconnect command, but I'll be adding a reconnect feature in version 1.1.

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
Very good effort. Just one tiny minor point. The callback hooks should use "CallLocalFunction" not "CallRemoteFunction" or you could end up having callbacks being called multiple times if this include is used in multiple scripts.
I'll change that in version 1.1.

Quote:
Originally Posted by Littlehelper[MDZ]
Посмотреть сообщение
Some of them are not even 'Useful' but anyway.
Nice job.
They might not be useful to you but other people might find a use for them.
Reply
#17

SetPlayerDeathEffect(playerid, deffid) Sets the player's death effect (DEATH_EFFECT_NONE, REDGAS, SMOKE, EXPLODE, MINIEXPLODE, FIRE) The player's IP
(:
Fix that "The player's IP"
Reply
#18

good work.
Reply
#19

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Do you need any authorization to release a crash-player code? Since when? :/
Not sure, but in fact you are bugging the client. And why would you want to CRASH players? Just kick them.

The reconnect code is different; it bans the IP, and unbans it straight away.
Reply
#20

Feel free to post all the functions you wish to post that you think would be beneficial to others. Use the following format:

Код HTML:
Function: FunctionName(parameters)
Action: This function does something with the parameters
Returns: This function always returns 1.

[PAWN]FunctionName(parameters)
{
}[/PAWN]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)