Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- native IsValidVehicle(vehicleid);
- #pragma tabsize 0
- #if defined _S_USEFUL_INCLUDED
- #error Vous avez déjà inclut la bibliothèque s_useful.
- #endif
- #define _S_USEFUL_INCLUDED
- #if defined MAX_PLAYER_NAME
- #undef MAX_PLAYER_NAME
- #define MAX_PLAYER_NAME 25
- #endif
- /*****************************
- Fonctions
- *****************************/
- stock GetName(playerid)
- {
- new tszName[MAX_PLAYER_NAME+1];
- GetPlayerName(playerid, tszName, sizeof(tszName));
- return tszName;
- }
- // Exemple d'utilisation : new nom[MAX_PLAYER_NAME+1] = GetName(playerid);
- stock GameTextForPlayer1(playerid, const message[], temps)
- {
- new heure[4];
- gettime(heure[0], heure[1], heure[2]);
- heure[3] = heure[2]*1000+9000;
- do
- {
- GameTextForPlayer(playerid, message, temps, 0);
- }
- while(heure[3] < temps);
- return 1;
- }
- stock GetPlayerID(const name[])
- {
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(strcmp(name, GetName(p), false) == 0)
- {
- if(!IsPlayerConnected(p)) return INVALID_PLAYER_ID;
- else return p;
- }
- }
- return INVALID_PLAYER_ID;
- }
- stock GetNearestCar(playerid)
- {
- new resultID;
- new Float:rdist, Float:cdist;
- rdist = 10.0;
- resultID = -1;
- for(new v;v<=MAX_VEHICLES;v++)
- {
- cdist = GetPlayerDistanceFromVehicle(playerid, v);
- if(cdist < rdist)
- {
- rdist = cdist;
- resultID = v;
- }
- }
- return resultID;
- }
- stock Float:GetPlayerDistanceFromVehicle(playerid, vehicleid)
- {
- new Float:pos[6];
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- GetVehiclePos(vehicleid, pos[3], pos[4], pos[5]);
- return GetDistanceBetweenPoints(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
- }
- stock GetDistanceBetweenTwoPlayers(player1, player2)
- {
- new Float:pos[6];
- GetPlayerPos(player1, pos[0], pos[1], pos[2]);
- GetPlayerPos(player2, pos[3], pos[4], pos[5]);
- return GetDistanceBetweenPoints(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5])
- }
- stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
- {
- return VectorSize(x1-x2, y1-y2, z1-z2);
- }
- stock PlayAudioForPlayersInRange(sound_url[], Float:range, Float:x, Float:y, Float:z)
- {
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(!strfind(sound_url, "http://")) return SendClientMessage(p, -1, "Piste audio inaccessible (http:// ou extension invalide)");
- if(!strfind(sound_url, ".mp3") || !strfind(sound_url, ".ogg") || !strfind(sound_url, ".pls") || strfind(sound_url, ".m3u")) return SendClientMessage(p, -1, "Piste audio inaccessible (http:// ou extension invalide)");
- if(IsPlayerConnected(p))
- {
- PlayAudioStreamForPlayer(p, sound_url, x, y, z, range, 1);
- SendClientFormattedMessage(p, -1, "{9ACD32}[Audio]{FFFFFF} Vous écoutez maintenant %s !", sound_url);
- }
- }
- return 1;
- }
- stock StopAudioForPlayersInRange(Float:range, Float:x, Float:y, Float:z)
- {
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(!IsPlayerConnected(p)) continue;
- else
- {
- if(IsPlayerInRangeOfPoint(p, range, x, y, z))
- {
- StopAudioStreamForPlayer(p);
- }
- }
- }
- return 1;
- }
- stock SendErrorMessage(playerid, message[])
- {
- return SendClientFormattedMessage(playerid, -1, "{FF0000}[Erreur]{FFFFFF} %s", message);
- }
- stock SplitDateTime(datetime[], &annee, &mois, &jour, &heure, &minute, &seconde)
- {
- new tmp[20];
- strmid(tmp, datetime, 0, 4);
- strdel(datetime, 0, 5);
- annee = strval(tmp);
- //printf("[DEBUG] %d", annee);
- strmid(tmp, datetime, 0, 2);
- strdel(datetime, 0, 3);
- mois = strval(tmp);
- //printf("[DEBUG] %d", mois);
- strmid(tmp, datetime, 0, 2);
- strdel(datetime, 0, 3);
- jour = strval(tmp);
- //printf("[DEBUG] %d", jour);
- strmid(tmp, datetime, 0, 2);
- strdel(datetime, 0, 3);
- heure = strval(tmp);
- //printf("[DEBUG] %d", heure);
- strmid(tmp, datetime, 0, 2);
- strdel(datetime, 0, 3);
- minute = strval(tmp);
- //printf("[DEBUG] %d", minute);
- strmid(tmp, datetime, 0, 2);
- strdel(datetime, 0, 3);
- seconde = strval(tmp);
- //printf("[DEBUG] %d", seconde);
- }
- stock SplitDate(date[], &annee, &mois, &jour)
- {
- new tmp[20];
- strmid(tmp, date, 0, 4);
- strdel(date, 0, 5);
- annee = strval(tmp);
- strmid(tmp, date, 0, 2);
- strdel(date, 0, 3);
- mois = strval(tmp);
- strmid(tmp, date, 0, 2);
- strdel(date, 0, 3);
- jour = strval(tmp);
- }
- stock SplitTime(time[], &heure, &minute, &seconde)
- {
- new tmp[20];
- strmid(tmp, time, 0, 2);
- strdel(time, 0, 3);
- heure = strval(tmp);
- strmid(tmp, time, 0, 2);
- strdel(time, 0, 3);
- minute = strval(tmp);
- strmid(tmp, time, 0, 2);
- strdel(time, 0, 3);
- seconde = strval(tmp);
- }
- stock ExplodeAll(type, Float:radi)
- {
- new Float:pos[3];
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(!IsPlayerConnected(p)) continue;
- else
- {
- GetPlayerPos(p, pos[0], pos[1], pos[2]);
- CreateExplosion(pos[0], pos[1], pos[2], type, radi);
- }
- }
- return SendClientFormattedMessageToAll(-1, "{FF0000}[Explosion]{FFFFFF} Tous les joueurs ont été explosés avec une explosion de radius %f (type %d)", radi, type);
- }
- stock RemovePlayerHealth(playerid, Float:ret)
- {
- new Float:health;
- GetPlayerHealth(playerid, health);
- if(health < ret) return 0;
- else SetPlayerHealth(playerid, floatsub(health, ret));
- return 1;
- }
- stock RemovePlayerArmour(playerid, Float:ret)
- {
- new Float:arm;
- GetPlayerArmour(playerid, arm);
- if(arm < ret) return 0;
- else SetPlayerArmour(playerid, floatsub(arm, ret));
- return 1;
- }
- stock AddPlayerHealth(playerid, Float:add)
- {
- new Float:health;
- GetPlayerHealth(playerid, health);
- SetPlayerHealth(playerid, floatadd(health, add));
- return 1;
- }
- stock AddPlayerArmour(playerid, Float:add)
- {
- new Float:arm;
- GetPlayerArmour(playerid, arm);
- SetPlayerArmour(playerid, floatadd(arm, add));
- return 1;
- }
- stock Float:GetPlayerHealth1(playerid)
- {
- new Float:health;
- GetPlayerHealth(playerid, health);
- return health;
- }
- stock Float:GetPlayerArmour1(playerid)
- {
- new Float:arm;
- GetPlayerArmour(playerid, arm);
- return arm;
- }
- stock Float:GetPlayerxPos(playerid)
- {
- new Float:x, Float:upos[2];
- GetPlayerPos(playerid, x, upos[0], upos[1]);
- return x;
- }
- stock Float:GetPlayeryPos(playerid)
- {
- new Float:y, Float:upos[2];
- GetPlayerPos(playerid, upos[0], y, upos[1]);
- return y;
- }
- stock Float:GetPlayerzPos(playerid)
- {
- new Float:z, Float:upos[2];
- GetPlayerPos(playerid, upos[0], upos[1], z);
- return z;
- }
- stock ProxDetector(Float:radi, playerid, const message[], couleur)
- {
- new Float:pos[3]
- GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
- for(new p = 0; p < MAX_PLAYERS; p++)
- {
- if(IsPlayerConnected(p))
- {
- if(IsPlayerInRangeOfPoint(p, radi, pos[0], pos[1], pos[2]))
- {
- return SendClientMessage(p, couleur, message);
- }
- }
- }
- return 1;
- }
- // Crédits : Patrick_ , Vince
- #define STATIC_OBJECT (0)
- #define DYNAMIC_OBJECT (1)
- stock Float:GetDistanceBetweenPoints(Float:x1,Float:y1,Float:z1, Float:x2,Float:y2,Float:z2) //By Gabriel "Larcius" Cordes & Vince
- {
- return VectorSize(x1-x2, y1-y2, z1-z2);
- }
- stock IsPlayerInRangeOfObject(playerid, objectid, Float:radius, TYPE = DYNAMIC_OBJECT)
- {
- new Float:ObjectOffsets[ 3 ];
- if(TYPE == STATIC_OBJECT)
- {
- GetObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
- if(IsPlayerInRangeOfPoint(playerid, radius, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]))
- return true;
- }
- else if(TYPE == STATIC_OBJECT)
- {
- GetDynamicObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
- if(IsPlayerInRangeOfPoint(playerid, radius, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]))
- return true;
- }
- return false;
- }
- stock IsObjectInRangePoint(objectid, Float:radius, Float:X, Float:Y, Float:Z, TYPE = DYNAMIC_OBJECT)
- {
- new Float:ObjectOffsets[ 3 ];
- if(TYPE == STATIC_OBJECT)
- {
- GetObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
- if(GetDistanceBetweenPoints(ObjectOffsets[0], ObjectOffsets[1], ObjectOffsets[2], X, Y, Z) <= radius) return true;
- }
- else if(TYPE == STATIC_OBJECT)
- {
- GetDynamicObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
- if(GetDistanceBetweenPoints(ObjectOffsets[0], ObjectOffsets[1], ObjectOffsets[2], X, Y, Z) <= radius) return true;
- }
- return false;
- }
- // Crédits : MrFredo (SendClientFormattedMessage & SendClientFormattedMessageToAll)
- #define SendClientMessage SendClientFormattedMessage
- #define SendClientMessageToAll SendClientFormattedMessageToAll
- stock SendClientFormattedMessage(playerid, color, const msg[], {Float,_}:...)
- {
- new len = strlen(msg),d=0,posArg = 3;
- new dest[512];
- for(new i=0;i<len;i++)
- {
- if(msg[i] == '%')
- {
- switch (msg[i+1])
- {
- case 's':
- {
- new pos,arg,tmppos;
- new str[128];
- while(getarg(posArg,pos)!='\0')
- {
- arg=getarg(posArg,pos++);
- str[tmppos]=arg;
- tmppos++;
- }
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case 'i', 'd':
- {
- new str[128];
- format(str,sizeof(str),"%d",getarg(posArg));
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case 'f':
- {
- new str[128];
- format(str,sizeof(str),"%f",getarg(posArg));
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case '.':
- {
- new len2 = msg[i+2];
- if(len2 == 0)
- {
- dest[d] = msg[i];
- d++;
- }
- else
- {
- new str[32],formatting[5];
- formatting[0] = '%';
- formatting[1] = '.';
- formatting[2] = len2;
- formatting[3] = 'f';
- format(str,sizeof(str),formatting,getarg(posArg));
- strins(dest,str,d,len2);
- d+=len;
- posArg++;
- i+= 2;
- }
- }
- default:
- {
- dest[d] = msg[i];
- d++;
- }
- }
- }
- else
- {
- dest[d] = msg[i];
- d++;
- }
- }
- //printf("[DEBUG] %s",dest);
- return SendClientMessage(playerid,color,dest);
- }
- stock SendClientFormattedMessageToAll(color, const msg[], {Float,_}:...)
- {
- new len = strlen(msg),d=0,posArg = 2;
- new dest[128];
- for(new i=0;i<len;i++)
- {
- if(msg[i] == '%')
- {
- switch (msg[i+1])
- {
- case 's':
- {
- new pos,arg,tmppos;
- new str[128];
- while(getarg(posArg,pos)!='\0')
- {
- arg=getarg(posArg,pos++);
- str[tmppos]=arg;
- tmppos++;
- }
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case 'i', 'd':
- {
- new str[128];
- format(str,sizeof(str),"%d",getarg(posArg));
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case 'f':
- {
- new str[128];
- format(str,sizeof(str),"%f",getarg(posArg));
- strins(dest,str,d,strlen(str));
- d+=strlen(str);
- posArg++;
- i++;
- }
- case '.':
- {
- new len2 = msg[i+2];
- if(len2 == 0)
- {
- dest[d] = msg[i];
- d++;
- }
- else
- {
- new str[32],formatting[5];
- formatting[0] = '%';
- formatting[1] = '.';
- formatting[2] = len2;
- formatting[3] = 'f';
- format(str,sizeof(str),formatting,getarg(posArg));
- strins(dest,str,d,len2);
- d+=len;
- posArg++;
- i+= 2;
- }
- }
- default:
- {
- dest[d] = msg[i];
- d++;
- }
- }
- }
- else
- {
- dest[d] = msg[i];
- d++;
- }
- }
- //printf("[DEBUG] %s",dest);
- return SendClientMessageToAll(color,dest);
- }
- // gl_common.inc
- stock isNumeric(const string[])
- {
- new length=strlen(string);
- if (length==0) return false;
- for (new i = 0; i < length; i++)
- {
- if (
- (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
- || (string[i]=='-' && i!=0) // A '-' but not at first.
- || (string[i]=='+' && i!=0) // A '+' but not at first.
- ) return false;
- }
- if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
- return true;
- }
- /****************************
- Natives
- ****************************/
- native GetName(playerid);
- native GameTextForPlayer1(playerid, const message[], temps);
- native GetPlayerID(const name[]);
- native GetNearestCar(playerid);
- native GetDistanceBetweenTwoPlayers(player1, player2, &Float:x, &Float:y, &Float:z);
- native PlayAudioForPlayersInRange(sound_url[], Float:range, Float:x, Float:y, Float:z);
- native StopAudioForPlayersInRange(Float:range, Float:x, Float:y, Float:z);
- native SendErrorMessage(playerid, message[]);
- native SplitDateTime(datetime[], &annee, &mois, &jour, &heure, &minute, &seconde);
- native SplitDate(date[], &annee, &mois, &jour);
- native SplitTime(time[], &heure, &minute, &seconde);
- native ExplodeAll(type, Float:radi);
- native RemovePlayerHealth(playerid, Float:ret);
- native RemovePlayerArmour(playerid, Float:ret);
- native AddPlayerHealth(playerid, Float:add);
- native AddPlayerArmour(playerid, Float:add);
- native Float:GetPlayerHealth1(playerid);
- native Float:GetPlayerArmour1(playerid);
- native Float:GetPlayerxPos(playerid);
- native Float:GetPlayeryPos(playerid);
- native Float:GetPlayerzPos(playerid);
- native SendClientFormattedMessage(playerid, color, const msg[], {Float,_}:...);
- native SendClientFormattedToAllMessage(color, const msg[], {Float,_}:...);
- native IsNumeric(const string[]);
- native ProxDetector(Float:radi, playerid, const message[], couleur);
- native IsPlayerInRangeOfObject(playerid, objectid, Float:radius);
- native IsObjectInRangeOfPoint(objectid, Float:radius, Float:X, Float:Y, Float:Z);
- native GetDistanceBetweenToPoints(Float:x1,Float:y1,Float:z1, Float:x2,Float:y2,Float:z2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement