25.03.2011, 23:48
(
Последний раз редактировалось gamer931215; 14.07.2014 в 17:40.
)
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
Код:
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
Код:
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
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);
}
pawn Код:
public OnPlayerConnect(playerid)
{
SendClientMessageToAllEx(COLOR_GREEN,"ss","Welcome ",GetPlayerNameEx(playerid));
}
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);
pawn Код:
SendRconCommandEx("si","kick ",playerid);
Now if we take a look at the parameters, it will say this:
pawn Код:
SendRconCommandEx(type[],{float,_}:...)
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
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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));
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
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;
}
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
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
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
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
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
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
Код:
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)
[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!