[Include] gLibrary 2.0 (An include with A LOT of useful functions)
#1

gLibrary 2.1
About:
gLibrary is an include with a lot of functions that will save you a lot of time!
It saves you from formatting strings in clientmessages,gametexts,rcon commands but it will also simplify
resetting the player's money, jailing, muting or even changing the vehicle's numberplate!

Functions since V2.1:
Код:
CenterString(string[],size) //Centers a string with spaces (size = length of string)
AngleToPoint(x1,y1,x2,y2) //Calculate an angle to a point 
Functions since V2.0:
Код:
TransportVehicleToPlayerByAir(playerid,vehicleid) //Transports the vehicle to the player by air! (Andromada)
GetVehicleType(vehicleid) //Returns 0 when its a car, 1 when its a boat and 2 when its a plane
GetVehicleSpeed(playerid,UseMPH = 0) //Returns playerspeed (i took it from hiddos's stalkercows, i just tought this was a must-have)
GetClosestVehicleForPlayer(playerid) //Returns closest vehicleid
GetClosestVehicleFromPoint(x,y,tx,ty) //Returns closest vehicleid
PutPlayerInObject(playerid,objectid) //Allows player to DRIVE/FLY a object! (Credits to hiddos for his turtle script)
RemovePlayerFromObject(playerid) //Removes player from object
IsPlayerInObject(playerid) //Returns 1 when player is flying an object
GetPlayerObjectID(playerid) //Returns objectid
GetVehicleNameByModelId(modelid) //Returns vehicle name
GetWeaponNameById(weaponid) //Returns weaponname
ToggleVehicleLights(vehicleid,toggle) //Toggle light on/off
AreVehicleLightsOn(vehicleid) //Returns 1 when the lights are on
ToggleVehicleAlarm(vehicleid,toggle) //Toggle alarm on/off
IsVehicleAlarmOn(vehicleid) //Returns 1 when the alarm is going off
SetVehicleToAlarm(vehicleid,time) //Start the vehicle's alarm and turn it off after the ammount of milisecconds you entered
GetDistanceBetweenPoints(Float:x,Float:y,Float:tx,Float:ty) //Returns distance between pts
Functions from 1.0:
Код:
GetWeaponIdByName(weaponname[]) //returns weaponid
GetVehicleIdByName(weaponname[]) //returns vehicleid
SetVehicleNumberPlateEx(vehicleid,numberplate[]) //will set the vehicle's licenseplate and respawn it at last known location
MutePlayer(playerid) //mutes player
UnMutePlayer(playerid) //unmutes player
JailPlayer(playerid) //jails player
UnJailPlayer(playerid) //unjails player
SetPlayerToReconnect(playerid) //Will let the player reconnect
SetPlayerMoney(playerid,ammount) //Resets and sets the given value of the players money
GivePlayerScore(playerid,ammount) //Gives player extra score
GetPlayerNameEx(playerid) //Returns name of player
GetPlayerIpEx(playerid) //Returns IP of player
KickEx(playerid,reason[]) //Kick player with reason
SendRconCommandEx(type[],{float,_}:...) //A combination of SendRconCommand & format
SendClientMessageEx(playerid,color,type[],{float,_}:...) //A combination of SendClientMessage & format
SendClientMessageToAllEx(color,type[],{float,_}:...) //A combination of SendClientMessageToAll & format
GameTextForPlayerEx(playerid,time,style,type[],{Float,_}:...) //A combination of GameTextGotPlayer & format
GameTextForAllEx(time,style,type[],{Float,_}:...) //A combination of GameTextForAll & format
Why do i need to use these shortcuts?
Well, its just easyer and faster to use!

Instead of this example:
pawn Код:
public OnPlayerConnect(playerid)
{
    new string[128],pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof pName);
    format(string,sizeof string,"Welcome %s",pName);
    SendClientMessageToAll(COLOR_GREEN,string);
}
you can use with this include this code to do the same:
pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessageToAllEx(COLOR_GREEN,"ss","Welcome ",GetPlayerNameEx(playerid));
}
Well that is much shorter isnt it!

Explaining the included formats:
Most of these functions are just like the regular functions, but then including formats.
Lets take SendRconCommand & SendRconCommandEx as example,

The normal SendRconCommand will use these parameters:
pawn Код:
new string[64];
format(string,sizeof string,"kick %i",playerid);
SendRconCommand(string);
The SendRconCommandEx will use these parameters:
pawn Код:
SendRconCommandEx("si","kick ",playerid);
This command can format AND execute the code in just one line!
Now if we take a look at the parameters, it will say this:

pawn Код:
SendRconCommandEx(type[],{float,_}:...)
type[]
At type you will declare the type of the string, in the example we have formatted an String and a Integer ("si").

Available types are:
String (s)
Integer (i)
Float (f)

for each extra comma & parameter you want to add, you need to set a type!
So possible types are: "sssif" or "sis" or "sf" or "ss", length doesnt matter!

{float,_}:...)
This parameter means that you can add an unlimited ammount of parameters.
So basicly: the type[] defines what kind of parameter you are using (string,float or int), and after a comma you will use the parameter itself.

Usage:
PutPlayerInObject(playerid,objectid)
Will put the player in a object and adds the ability to fly with the object!
pawn Код:
COMMAND:Fly(playerid,params)
{
    new object = CreateObject(yourobjectstuff);
    PutPlayerInObject(playerid,object);
}
//You also have just like vehicles the GetPlayerObjectId,IsPlayerInObject and RemovePlayerFromObject
Due me trying to avoid posting an HOW-TO so big that nobody will read, i decided to not explain the other new features that have been added. Just check the name & parameters of them and you will understand

GetWeaponIdByName(weaponname[])
Will convert weaponname to weaponid (returns -1 when theres no result)
pawn Код:
COMMAND:weapon(playerid,params[])
{
    new weapon = GetWeaponIdByName(params); //converts the weaponname to weaponmodel
    if(weapon == -1) return SendClientMessage(playerid,gCOLOR_RED,"Invalid weapon name!");
    GivePlayerWeapon(playerid,weapon,100);
    return 1;
}
GetVehicleIdByName(weaponname[])
Will convert vehiclename to vehiclemodelid (returns -1 when theres no result)
pawn Код:
COMMAND:veh(playerid,params[])
{
    new vehicle = GetVehicleIdByName(params); //converts the vehiclename to modelID
    if(vehicle == -1) return SendClientMessage(playerid,gCOLOR_RED,"Invalid vehicle name!");
    new Float:pos[3];GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    AddStaticVehicle(vehicle,pos[0],pos[1],pos[2]);
    return 1;
}
SetVehicleNumberPlateEx(vehicleid,numberplate[])
Will change the numberplate, respawn the vehicle and teleports it back to the player
pawn Код:
COMMAND:changeplate(playerid,params[])
{
    new vehicle = GetPlayerVehicleId(playerid);
    SetVehicleNumberPlateEx(vehicle,params); //sets the license plate, respawns the vehicle and teleports it back to the player
    return 1;
}
MutePlayer(playerid)
Will mute the player This will not say a clientmessage to everyone that this player has been muted! it will just notify the player that he cannot talk when he is muted after each time he tried to chat.
pawn Код:
COMMAND:mute(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id,reason[64];
    if(sscanf(params,"i",id)) return SendClientMessage(playerid,color_red,"USAGE: /mute [id] [reason]");
    sscanf(params,"is[64]",id,reason);
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,color_red,"Player not connected.");
    if(PlayerInfo[id][Muted] == 1) return SendClientMessage(playerid,color_red,"Player is already muted!");
    if(!strlen(reason))
    {
        SendClientMessageToAllEx(color_blue,"sssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} muted ",PlayerInfo[id][Username],".");
    } else {
        SendClientMessageToAllEx(color_blue,"sssssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} muted ",PlayerInfo[id][Username]," Reason:",reason,".");
    }
    MutePlayer(id); //mutes the player
    return 1;
}
UnMutePlayer(playerid)
Unmutes player
pawn Код:
COMMAND:unmute(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id;
    if(sscanf(params,"i",id))return SendClientMessage(playerid,color_red,"USAGE: /unmute [id]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,color_red,"Player not connected.");
    if(PlayerInfo[id][Muted] == 0) return SendClientMessage(playerid,color_red,"Player is not muted!");
    SendClientMessageToAllEx(color_blue,"sssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} unmuted ",PlayerInfo[id][Username],".");
    UnMute(id); //unmutes the player
    return 1;
}
JailPlayer(playerid)
Puts player in jail interior, position and freeze him. This will not send any client messages that the player has been jailed!
pawn Код:
COMMAND:jail(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id,reason[64];
    if(sscanf(params,"i",id)) return SendClientMessage(playerid,color_red,"USAGE: /jail [id] [reason]");
    sscanf(params,"is[64]",id,reason);
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,color_red,"Player not connected.");
    if(!strlen(reason))
    {
        SendClientMessageToAllEx(color_blue,"sssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} jailed ",PlayerInfo[id][Username],".");
    } else {
        SendClientMessageToAllEx(color_blue,"sssssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} jailed ",PlayerInfo[id][Username]," Reason:",reason,".");
    }
    JailPlayer(id); //puts the player in the jail interior, jail position and frozen
    return 1;
}
UnJailPlayer(playerid)
Unjails the player
pawn Код:
COMMAND:unjail(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id;
    if(sscanf(params,"i",id))return SendClientMessage(playerid,color_red,"USAGE: /unjail [id]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,color_red,"Player not connected.");
    if(PlayerInfo[id][Jailed] == 0) return SendClientMessage(playerid,color_red,"Player is not jailed!");
    SendClientMessageToAllEx(color_blue,"sssss","***Administrator ",PlayerInfo[playerid][Username],"{FFFFFF} unjailed ",PlayerInfo[id][Username],".");
    //released the player
    return 1;
}
SetPlayerToReconnect(playerid)
This will rcon ban the player's ip, and unban him when he leaves, this means that the serverside drops the connection with the client. However the clientside will not notify it and will try to reconnect. At the moment the player reconnects he will be unbanned again.
pawn Код:
COMMAND:iambugged(playerid,params[])
{
    SetPlayerToReconnect(playerid);
    return 1;
}
SetPlayerMoney(playerid,ammount)
Set the value of the player's money
pawn Код:
COMMAND:setmoney(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 2) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id,value;
    if(sscanf(params,"ii",id,value)) return SendClientMessage(playerid,color_red,"USAGE: /setmoney [playerid] [value]");
    SetPlayerMoney(id,value); //this instead of new string,GetPlayerMoney, string + ammount, ResetPlayerMoney and then GivePlayerMoney, just saved you 4 lines!
    SendClientMessageEx(id,color_green,"sssis","Administrator ",PlayerInfo[playerid][Username]," has changed your money to ",value," !");
    SendClientMessageEx(playerid,color_green,"sssis","You have succesfully changed ",PlayerInfo[id][Username],"'s money to ",value," .");
    return 1;
}
GivePlayerScore(playerid,ammount)
Increase the player's score with his current score + the given ammount of money
pawn Код:
COMMAND:givescore(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 2) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id,value;
    if(sscanf(params,"ii",id,value)) return SendClientMessage(playerid,color_red,"USAGE: /givescore [playerid] [value]");
    GivePlayerScore(id,value);
    SendClientMessageEx(id,color_green,"sssis","Administrator ",PlayerInfo[playerid][Username]," gave your ",value," extra points!");
    SendClientMessageEx(playerid,color_green,"sssis","You gave ",PlayerInfo[id][Username]," ",value," extra score!");
    return 1;
}
GetPlayerNameEx(playerid)
Gets the player's name
pawn Код:
//Just a shortcut, this will return the player's name instead of storing it into a string (usefull when formatting), example:
new file[64];
format(file,sizeof file,"Users\%s.ini",GetPlayerNameEx(playerid));
GetPlayerIpEx(playerid)
pawn Код:
//Just a shortcut, this will return the player's IP instead of storing it into a string (usefull when formatting), see GetPlayerNameEx for example
KickEx(playerid,reason[])
Kicks the player with reason, please note that this will only notify the player with the reason and that this doesnt notify other players that this player has been kicked!
pawn Код:
COMMAND:kick(playerid,params[])
{
    if(PlayerInfo[playerid][Level] < 1) return SendClientMessage(playerid,color_red,"You have no permission to use this command!");
    new id,reason[64];
    if(sscanf(params,"is",id,reason)) return SendClientMessage(playerid,color_red,"USAGE: /kick [id] [reason]");
    KickEx(id,reason); //kicks player with reason
    return 1;
}
SendRconCommandEx(type[],{float,_}:...)
Send a formatted rcon command via your gamemode/filterscript
pawn Код:
//Please check the formatting part , and the original command (wiki.sa-mp.com) to explain how this command works
SendClientMessageEx(playerid,color,type[],{float,_}:...)
Send a formatted client message to a player
pawn Код:
//Please check the formatting part , and the original command (wiki.sa-mp.com) to explain how this command works
SendClientMessageToAllEx(color,type[],{float,_}:...)
Send a formatted client message to everyone
pawn Код:
//Please check the formatting part , and the original command (wiki.sa-mp.com) to explain how this command works
GameTextForPlayerEx(playerid,time,style,type[],{Float,_}:...)
Show a formatted gametext to a player
pawn Код:
//Please check the formatting part , and the original command (wiki.sa-mp.com) to explain how this command works
GameTextForAllEx(time,style,type[],{Float,_}:...)
Show a formatted gametext for everyone
pawn Код:
//Please check the formatting part , and the original command (wiki.sa-mp.com) to explain how this command works
Colors:
This include will also define the most common colors!
The color defines are:
Код:
gCOLOR_RED
gCOLOR_GREEN
gCOLOR_BLUE
gCOLOR_YELLOW
gCOLOR_ORANGE
gCOLOR_GRAY
gCOLOR_BLACK
gCOLOR_MAGENTA
gCOLOR_DARKRED
gCOLOR_DARKGREEN
gCOLOR_DARKBLUE
Changelog:
Код:
1.1/1.1b:
Some warnings are fixed

1.2:
-All warnings should be fixed now
-gCOLOR_ORANGE added

2.0:
-A lot of new commands added

2.1:
-Include is no more blocking OnPlayerDisconnect, and 2 new functions has been added:
 CenterString(string[],size)
 AngleToPoint(x1,y1,x2,y2)
Credits:

[03]Garsino for telling me how to reconnect
****** for teaching me how to use arguments
SA-MP team for te arrays for the weapons/vehicles at fsdebug.pwn
Hiddos for his turtle script (making PutPlayerInObject())

Download:
http://pastebin.com/RrLdcDnD

Pastebin link has been fixed & .zip download has been added!
Reply
#2

Useful.
Reply
#3

Basic yet useful stuff, good job!
Reply
#4

So useful, much appreciated.
Reply
#5

omfg thanks man i never learned how to use strings
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
I'm wondering why you didn't use one of the standard ways of doing advanced formatting? There has been functions for things like your "SendClientMessageEx" function for years which incorporate "format" and "SendClientMessage". The advantage of that method is the use of formats such as "%.2f" etc, which this way doesn't support.

Otherwise a nice range of convenience functions.
Well this is just for fast formatting in a clientmessage situation, it simplifies/fastens the process and i didnt know yet how to use that other method (hiddos just told me). If you are not really doing advanced coding like methods as "%.2f", then you can still use the regular format ofcourse.

Anyways thanks for the comments all
Reply
#7

Nice Work Gamer
Reply
#8

Nice, man, very useful functions, some thing like this could be implemented on a_samp by default.
Reply
#9

really really useful
Reply
#10

Quote:
Originally Posted by ElChapoGuzman
Посмотреть сообщение
omfg thanks man i never learned how to use strings
lol strings are easy!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)