22.03.2015, 11:23
pawn Код:
enum GunData
{
Object, //Stores the object ID of the weapon
Float:GunX, //Stores the X coordinate of the weapon
Float:GunY, //Stores the Y coordinate of the weapon
Float:GunZ //Stores the Z coordinate of the weapon
};
new Shotgundrop[MAX_PLAYERS][GunData]; //Used to access the 'GunData' array with respect to 'playerid'.
CMD:dropgun(playerid, params[])
{
if(IsValidDynamicObject(Shotgundrop[playerid][Object])) return SendClientMessage(playerid, -1, "You have already dropped a gun."); //If they have already used /dropgun
GetPlayerPos(playerid, Shotgundrop[playerid][GunX], Shotgundrop[playerid][GunY],Shotgundrop[playerid][GunZ]);
Shotgundrop[playerid][Object] = CreateDynamicObject(2034, Shotgundrop[playerid][GunX], Shotgundrop[playerid][GunY],Shotgundrop[playerid][GunZ] - 0.9, 0, 0, 0.00);
return 1;
}
CMD:pick(playerid, params[])
{
for(new i = 0; i < MAX_PLAYERS; i++) //Foreach is a better alternative
{
if(!IsPlayerConnected(i)) continue; //Remove if using Foreach.
if(!IsValidDynamicObject(Shotgundrop[i][Object])) continue;
if(!IsPlayerInRangeOfPoint(playerid, 2.0, Shotgundrop[i][GunX], Shotgundrop[i][GunY], Shotgundrop[i][GunZ])) continue;
DestroyDynamicObject(Shotgundrop[i][Object]);
Shotgundrop[i][Object] = -1;
return 1;
}
SendClientMessage(playerid, -1, "There are no guns nearby."); //If there are no guns within 2.0 units of the player
return 1;
}
https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
https://sampwiki.blast.hk/wiki/Keywords:Statements#for