From SA-MP
Useful Functions (uf.inc)
Here you can find useful functions for your pawno scripts. They are mostly copied from this topic from SA-MP Forums, these can all be implemented with the Useful Functions include file.
Allows the saving of models, types and pickup positions, it is essential for OnPlayerPickupItem
(model, type, Float:X, Float:Y, Float:Z)
| model | The modelid of the pickup to spawn |
| type | The typeid of the pickup to spawn |
| Float:X | The x value of the spawn position |
| Float:Y | The y value of the spawn position |
| Float:Z | The z value of the spawn position |
AddStaticPickup2(50,2,29.5,36.5,49.8);
By: Sacky
Enables saving of vehicleclasses to a script (Alot of vehicle functions rely on this)
(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2)
| modelid | The modelid of the vehicle to spawn |
| Float:spawn_x | The x value of the spawn position |
| Float:spawn_y | The y value of the spawn position |
| Float:spawn_z | The z value of the spawn position |
| Float:z_angle | The angle value of the spawn position |
| color1 | The first colour of the vehicle |
| color1 | The second colour of the vehicle |
AddStaticVehicle2(50,2.6,29.5,36.5,49.8,6,7);
By: Sacky
Allows the saving of models to the AddStaticVehicleEx function, for people who prefer this function to AddStaticVehicle
(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2,respawn_delay)
| modelid | The modelid of the vehicle to spawn |
| Float:spawn_x | The x value of the spawn position |
| Float:spawn_y | The y value of the spawn position |
| Float:spawn_z | The z value of the spawn position |
| Float:z_angle | The angle value of the spawn position |
| color1 | The first colour of the vehicle |
| color1 | The second colour of the vehicle |
| respawn_delay | The amount of time in miliseconds the vehicle will wait before respawning when it dies |
AddStaticVehicleEx2(50,2.6,29.5,36.5,49.8,6,7,7000);
By: Sacky
Makes a line of vehicle's
(Modelid, Float:Start[2], Float:Rate[2], Float:Z, Float:Z_Angle, MaxAmount)
| Modelid | The modelid of the vehicles to spawn |
| Float:Start[2] | The x value of the starting position |
| Float:Rate[2] | The y value of the starting position |
| Float:Z | The z value of the starting position |
| Float:Z_Angle | The angle value of the spawn position for the cars in the line |
| MaxAmount | The amount of cars in the line |
AddStaticVehicleLine(50,2.6,3.8,7.4,270.0,5);
By: Sacky
Bans all the players in an entire team
(team)
BanTeam(1);
By: dyraXon
Converts an integer of seconds into a string that will display hours,minutes and seconds
(time)
| time | The amount of seconds as an integer |
| Returns | The converted amount of seconds into hours, minutes, and seconds (Displays like: x hours, x minutes and x seconds |
ConvertSeconds(12000);
By: El Presy
Converts degree's to radians
(Float:degrees)
| Float:degrees | The degree you want to convert |
| Returns | The conversion of the degree to a radian |
DegreesToRadians(270);
By: Sacky
This function allows you to encrypt strings, very useful for storing passwords without fear of someone cracking them
(string[])
| string[] | The string you want to encrypt |
| Returns | The encrypted string |
encrypt("User Password");
Note: This function requires you to set a unique key to use with it. This is so no-one elses use of the function generates the same hashes as you. This key must contain ALL the letters and digits you want to make valid in a password or it will produce wierd results. They don't have to be listed only once but must be listed at least once, in any random order. The location of the key is clearly documented within the function. Don't change your key or no-one will be able to log in.
There is also a PHP version here.
By: Y_Less
Generates a random number with 2 decimal places
(Float:min, Float:max)
| Float:min | The minimum the random float can be |
| Float:max | The maximum the random float can be |
| Returns | The random float between the minimum and maximum values |
floatrand(1.2,5.6);
By: Y_Less
Returns 1 if the text won't crash your server, 0 if it will
(string[])
| string[] | The string to be checked |
| Returns | The 1 if the text is ok, 0 if it isn't |
GameTextCheck("Hello World");
By: Kamazy
Sends GameText to all the players in the specified team, the same as GameTextForPlayer except you can specify the team
(team, text[], time, style)
| team | The team you want the message sent to |
| text[] | The text to be sent |
| time | The time for the text to remain on the screen |
| style | The style of the text |
GameTextForTeam(1,"Hello",1000,3);
By: Y_Less
Returns the ID of the closest car
(playerid)
| playerid | The first playerid to parse into the function |
| Returns | The closest vehicle to the player |
GetClosestCar(1);
By: Darkrealm
Returns the ID of the closest player
(playerid)
| playerid | The first playerid to parse into the function |
| Returns | The closest player to the specified player |
GetClosestPlayer(1);
By: Slick
Returns the current position as a string
(playerid)
| playerid | The playerid to get the position from |
| Returns | The current position in string format |
GetCurrentPosition(1);
By: Sacky
Returns the distance between players as an integer
(playerid,playerid2)
| playerid | The first playerid to parse into the function |
| playerid2 | The second playerid to parse into the function |
| Returns | The distance between the players in meters as an integer |
GetDistanceBetweenPlayers(1,2);
By: Slick
Returns the distance between the player and the car as an integer (Note: This doesnt fully work properly due to the GetVehiclePos not working properly, instead it will give you the distance to the car spawn)
(playerid,carid)
| playerid | The player to parse |
| carid | The vehicleid to parse |
| Returns | The distance between the player and the vehicle |
GetDistanceToCar(1,2);
By: Darkrealm
Returns the number of pickups on the server
| Returns | The number of pickups present on the server |
GetPickups();
By: Sacky
Returns the player accelaration in MPH as an integer, it requires the uftimer to be implemented in the gamemode
(playerid)
| playerid | The player you want to get the speed from |
| Returns | The acceleration of the player |
GetPlayerAcceleration(5);
By: Sacky
Returns the player distance to a 2D point
(playerid,Float:x,Float:y)
| playerid | The player you wish to query |
| Float:x | The x value of the point |
| Float:y | The y value of the point |
| Returns | The distance to the point |
GetPlayerDistanceToPoint(1,1.9,8.5);
By: Sacky
Returns the player distance to a 3D point
(playerid, Float:x, Float:y, Float:z)
| playerid | The player you wish to query |
| Float:x | The x value of the point |
| Float:y | The y value of the point |
| Float:z | The z value of the point |
| Returns | The distance to the point |
GetPlayerDistanceToPoint(1,1.9,8.5,9.5);
By: Sacky
Returns the player ID from a playername
(playername[])
| playername[] | The name you want to get the playerid from |
| Returns | The playerid (if none then returns -1) |
GetPlayerId("Y_Less");
By: Y_Less
Returns the number of players on the server
| Returns | The number of players on the server |
GetPlayers();
By: rapidZ
Returns the class of the players skin
(playerid)
| playerid | The player you want to get the skin from |
| Returns | The skin id (0 if invalid) |
GetPlayerSkin(5);
By: Sacky
Returns the player speed in KMPH as an integer, it requires the uftimer to be implemented in the gamemode
(playerid)
| playerid | The player you want to get the speed from |
| Returns | The speed of the player |
GetPlayerSpeed(5);
By: Sacky
Returns the distance between 1 x and y value and another x and y value
(Float:x,Float:y,Float:x2,Float:y2)
| Float:x | The x value of the first point |
| Float:y | The y value of the first point |
| Float:x2 | The x value of the second point |
| Float:y2 | The y value of the second point |
| Returns | The distance between the 2 points |
GetPointDistanceToPoint(12.3,14.5,109.7,88.9);
By: Sacky
Returns the distance between 1 x,y and z value and another x,y and z value
(Float:x,Float:y,Float:z,Float:x2,Float:y2,Float:z2)
| Float:x | The x value of the first point |
| Float:y | The y value of the first point |
| Float:z | The z value of the first point |
| Float:x2 | The x value of the second point |
| Float:y2 | The y value of the second point |
| Float:z2 | The z value of the first point |
| Returns | The distance between the 2 points |
GetPointDistanceToPointEx(12.3,14.5,15.6,109.7,88.9,13.4);
By: Sacky
Returns the Vehicleclass/modelid (Needs AddStaticVehicle2 or AddStaticVehicleEx2)
(vehicleid)
| vehicleid | The id of the vehicle to return the class from |
| Returns | The vehicle class (0 if invalid vehicle) |
GetVehicleClass(1);
By: Sacky
Returns the name of a vehicle (Needs AddStaticVehicle2 or AddStaticVehicle2Ex)
(vehicleid)
| vehicleid | The id of the vehicle to return the class from |
| Returns | The name of a vehicle (by class) |
GetVehicleName(1);
By: Sacky
Returns the type of a vehicle (Needs AddStaticVehicle2 or AddStaticVehicle2Ex)
(vehicleid)
| vehicleid | The id of the vehicle to return the type from |
| Returns | The type of a vehicle (eg. CAR or BOAT) |
GetVehicleType(1);
By: Sacky
Returns the vehicles angle
(vehicleid)
| vehicleid | The id of the vehicle to return the angle from |
| Returns | The angle of the vehicle |
GetVehicleZAngle(1);
By: Sacky
Returns the number of vehicles on the server
| Returns | The number of vehicles present on the server |
GetVehicles();
By: Sacky
A version of GivePlayerWeapon, that displays an alert for weapon classes that cannot be given to players for some reason, then defaults to giving "Unarmed"
(playerid, weaponid, ammo)
| playerid | The playerid to give the weapon to |
| weaponid | The weaponid you want to give to the player |
| ammo | How much ammo to give to the player |
GivePlayerWeaponAlt(1,26,500);
By: Allan
Lets you specify an unlimited number of weapons and ammo to be given to a player
( playerid, ... )
| playerid | The playerid to give the weapon to |
| ... | The weaponid you want to give to the player, also specify the ammo |
GivePlayerWeaponEx(1,25,400,26,400);
By: Peter
Gives every payer on a team a certain amount of money
(team, amount)
| team | The team to give the money to |
| amount | The amount of money to give to the team |
GiveTeamMoney(1,500);
By: Hellomy
Converts Hexidecimal into RGBA
(colour, &r, &g, &b, &a)
| colour | The hexidecimal colour |
| &r | The red colour to store |
| &g | The green colour to store |
| &b | The blue colour to store |
| &a | The alpha colour to store |
HexToRGBA(0xAFAFAFAA,r,g,b,a);
By: Betamaster
Inverse Trigonomic Function (cosine)
(Float:adj,Float:hyp)
| Float:adj | The length of the adjacent side |
| Float:hyp | The length of the hypotenuse side |
| Returns | The processed inverse trigonomic equation (Float) |
icos(5.3,4.6);
By: Sacky
Inverse Trigonomic Function (sine)
(Float:opp,Float:hyp)
| Float:opp | The length of the opposite side |
| Float:hyp | The length of the hypotenuse side |
| Returns | The processed inverse trigonomic equation (Float) |
isin(5.3,4.6);
By: Sacky
Returns 1 if the string is numeric, 0 if not
(string[])
| string[] | The string you want to check |
| Returns | 1 if numeric, 0 if not numeric |
IsNumeric("12");
By: Mike
Returns 1 if the pickup is connected and 0 if it isn't, it requires you to use AddStaticPickup2 rather than AddStaticPickup
(pickupid)
| pickupid | The pickup id you want to query |
| Returns | 1 if it is connected, 0 if it isn't |
IsPickupConnected(254);
By: Sacky
Returns the 1 if they are, returns 0 if they arent (There are some interiors which escape this function, it will work on about 95% of interiors)
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in an interior, 0 if they aren't |
IsPlayerInAnyInterior(5);
By: Sacky
Returns 1 if the player is in the area and 0 if they aren't
(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
| playerid | The playerid you want to query |
| Float:minx | The minimum x value for the area |
| Float:miny | The minimum y value for the area |
| Float:maxx | The maximum x value for the area |
| Float:maxy | The maximum y value for the area |
| Returns | 1 if they are in the area, 0 if they aren't |
IsPlayerInArea(2, 2.0, 2.0, 4.0, 4.0);
By: Y_Less
Returns 1 if the player is in the area and 0 if they aren't
(playerid, ...)
| playerid | The playerid you want to query |
| ... | The x and y values for your area |
| Returns | 1 if they are in the area, 0 if they aren't |
IsPlayerInArea(2, 2.0, 2.0, 4.0, 4.0);
By: kool
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a boat, 0 if they aren't |
IsPlayerInBoat(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a car, 0 if they aren't |
IsPlayerInCar(5);
By: Sacky
Returns 1 if the player is in the circle and 0 if they aren't
(playerid, Float:x, Float:y, radius)
| playerid | The playerid you want to query |
| Float:x | The x value of the center of the circle |
| Float:y | The y value of the center of the circle |
| radius | The radius of the circle |
| Returns | 1 if they are in the area, 0 if they aren't |
IsPlayerInCircle(2,13.9,14.8,5);
By: Sacky
Returns 1 if the player is in the cube and 0 if they aren't
(playerid, xmin, ymin, zmin, xmax, ymax, zmax)
| playerid | The playerid you want to query |
| xmin | The minimum x value of the cube |
| ymin | The minimum y value of the cube |
| zmin | The minimum z value of the cube |
| xmax | The maximum x value of the cube |
| ymax | The maximum y value of the cube |
| zmax | The maximum z value of the cube |
| Returns | 1 if they are in the area, 0 if they aren't |
IsPlayerInCube(2,2,3,4,1,2,3);
By: 50p
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a helicopter, 0 if they aren't |
IsPlayerInHelicopter(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a monster truck, 0 if they aren't |
IsPlayerInMonsterTruck(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a plane, 0 if they aren't |
IsPlayerInPlane(5);
By: Sacky
Returns 1 if the player is in the sphere and 0 if they aren't
(playerid, Float:x, Float:y, Float:z, radius)
| playerid | The playerid you want to query |
| Float:x | The x value of the center of the sphere |
| Float:y | The y value of the center of the sphere |
| Float:z | The z value of the center of the sphere |
| radius | The radius of the circle |
| Returns | 1 if they are in the spherer, 0 if they aren't |
IsPlayerInCircle(2,13.9,14.8,5,9.7);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are in a quad, 0 if they aren't |
IsPlayerInQuad(5);
By: Sacky
Returns 1 if if they are, 0 if they aren't
(playerid, Float: Range, Float: Z_Range, Float:tar_x, Float:tar_y, Float:tar_z)
| playerid | The playerid you want to query |
| Float:Range | The range the player can be in |
| Float:Z_Range | The height range the player can be in |
| Float:tar_x | The x value for the point |
| Float:tar_y | The y value for the point |
| Float:tar_z | The z value for the point |
| Returns | 1 if they are in the range, 0 if they aren't |
IsPlayerInRange(2, 2.0, 2.0, 4.0, 4.0, 4.0);
By: Simon
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are a driver, 0 if they aren't |
IsPlayerDriver(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent (Needs AddStaticVehicle2 or AddStaticVehicle2Ex)
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are on a bicycle, 0 if they aren't |
IsPlayerOnBicycle(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent (Needs AddStaticVehicle2 or AddStaticVehicle2Ex)
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are on a bike, 0 if they aren't |
IsPlayerOnBike(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are on foot, 0 if they aren't |
IsPlayerOnFoot(5);
By: Sacky
Returns the 1 if they are, returns 0 if they arent
(playerid)
| playerid | The playerid you want to query |
| Returns | 1 if they are a passenger, 0 if they aren't |
IsPlayerPassenger(5);
By: Sacky
Returns 1 if the team is in the area and 0 if they aren't
(team, Float:minx, Float:maxx, Float:miny, Float:maxy)
| team | The teamid you want to query |
| Float:minx | The minimum x value for the area |
| Float:miny | The minimum y value for the area |
| Float:maxx | The maximum x value for the area |
| Float:maxy | The maximum y value for the area |
| Returns | 1 if they are in the area, 0 if they aren't |
IsTeamInArea(2, 2.0, 2.0, 4.0, 4.0);
By: dyraXon
Returns 1 if the vehicle is connected and 0 if it isn't
(vehicleid)
| vehicleid | The vehicle's id you want to query |
| Returns | 1 if it is connected, 0 if it isn't |
IsVehicleConnected(254);
By: Sacky
Returns 1 if the vehicle is in use and 0 if it isn't
(vehicleid)
| vehicleid | The vehicle's id you want to query |
| Returns | 1 if it is in use, 0 if it isn't |
IsVehicleInUse(254);
By: Sacky
Inverse Trigonomic Function (tangent)
(Float:opp,Float:adj)
| Float:opp | The length of the opposite side |
| Float:adj | The length of the adjacent side |
| Returns | The processed inverse trigonomic equation (Float) |
itan(5.3,4.6);
By: Sacky
Kicks all the players in an entire team
(team)
KickTeam(1);
By: Sacky
Returns the first characters in the string, it will return how many you set in the len
(source[], len)
| source[] | The string you want to take the left characters from |
| len | The number of characters from the left you want to return |
| Returns | The number of characters from the left specified in the len |
left("Hello",1);
By: Y_Less
Returns the position relative to the current position taking angle and distance as the arguments
(Float:length,Float:angle)
| Float:length | How long the line is |
| Float:angle | The angle in which to draw the virtual line |
| Returns | The length of the line |
lengthdir_x(32.4,170.9);
By: Slick
Returns the position relative to the current position taking angle and distance as the arguments
(Float:length,Float:angle)
| Float:length | How long the line is |
| Float:angle | The angle in which to draw the virtual line |
| Returns | The length of the line |
lengthdir_y(32.4,170.9);
By: Slick
Generates a random integer between the minimum and maximum numbers set
(min, max)
| min | The minimum number the random integer can be |
| max | The maximum number the random integer can be |
| Returns | The random number between the min and max as an integer |
minrand(1,5);
By: Y_Less
Returns the unix-timestamp of a date/time, equivalent to PHP's one:
mktime on php.net
(hour,minute,second,day,month,year)
| hour | The hour integer to pass |
| minute | The minute integer to pass |
| second | The second integer to pass |
| day | The day integer to pass |
| month | The month integer to pass |
| year | The year integer to pass |
| Returns | seconds since the beginning of unix time/timestamp |
mktime(1,1,1,1,1,2005);
By: mabako