06.06.2008, 10:28
RPName
Returns first and last name of an RP style name (e.g. John_Bortch will return John and Bortch). It returns 0 if the RP Name isnt validCode:
RPName(name[],ret_first[],ret_last[]) { new len = strlen(name), point = -1, bool:done = false; for(new i = 0; i < len; i++) { if(name[i] == '_') { if(point != -1) return 0; else { if(i == 0) return 0; point = i + 1; } } else if(point == -1) ret_first[i] = name[i]; else { ret_last[i - point] = name[i]; done = true; } } if(!done) return 0; return 1; }
Code:
public OnPlayerConnect(playerid) { new name[MAX_PLAYER_NAME], first[MAX_PLAYER_NAME], last[MAX_PLAYER_NAME], ret; GetPlayerName(playerid,name,sizeof(name)); if(RPName(name,first,last)) { // Valid name, player is called first_last } else { // Invalid name, deal accordingly } return 1; }
strtok
Code:
strtok(string[],&idx,seperator = ' ') { new ret[128], i = 0, len = strlen(string); while(string[idx] == seperator && idx < len) idx++; while(string[idx] != seperator && idx < len) { ret[i] = string[idx]; i++; idx++; } while(string[idx] == seperator && idx < len) idx++; return ret; }
rand
An exact copy of the function "rand" in PHP.pawn Code:
rand(minnum = cellmin,maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;
GetVehicleName
Returns the vehicle name from a modelid.http://boylett.pastebin.com/f3a9a059c
Float:GetPointDistanceToPoint
pawn Code:
Float:GetPointDistanceToPoint(Float:x1,Float:y1,Float:x2,Float:y2)
{
new Float:x, Float:y;
x = x1-x2;
y = y1-y2;
return floatsqroot(x*x+y*y);
}
Float:GetPointDistanceToPointEx
pawn Code:
Float:GetPointDistanceToPointEx(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
new Float:x, Float:y, Float:z;
x = x1-x2;
y = y1-y2;
z = z1-z2;
return floatsqroot(x*x+y*y+z*z);
}