16.12.2010, 13:36
all you need first, is your (working) command to call a function which drops your weapon. this could look like this (including the playerid, its the only parameter it needs yet):
its the exact same like your command. now you need get this function be called when you type your command. so lets remove all that and just modify your onplayercommand a bit:
the DropGun(playerid); callback
replaced your command.
what changed? NOTHING. but you may use this in your OnPlayerDeath() aswell:
either you add a loop for all weapon slots (calls this callback 12 times then), this will need a second parameter, so its not worth it, or copy and modify this callback to contain this loop, dropping each weapon...
lets see what happens next ^^
Код:
forward DropGun(playerid); public DropGun(playerid){
new gunID = GetPlayerWeapon(playerid);
new gunAmmo = GetPlayerAmmo(playerid);
if(gunID != 0 && gunAmmo != 0)
{
new f = maxobj+1;
for(new a = 0; a < sizeof(ObjCoords); a++)
{
if(ObjCoords[a][0] == 0.0) f = a;
}
if(f == maxobj+1) return SendClientMessage(playerid, 0x33AA3300, "You can not throw weapons at the moment, try back later!!");
else
{
new gunname[100];
new buffer[512];
GetWeaponNameEx(gunID, gunname, sizeof(gunname));
format(buffer, sizeof(buffer), "You threw %s", gunname);
SendClientMessage(playerid, 0x33AA3300, buffer);
RemovePlayerWeapon(playerid, gunID);
ObjectID[f][0] = gunID;
ObjectID[f][1] = gunAmmo;
GetPlayerPos(playerid, ObjCoords[f][0], ObjCoords[f][1], ObjCoords[f][2]);
object[f] = CreateObject(GunObjects[gunID][0],ObjCoords[f][0],ObjCoords[f][1],ObjCoords[f][2]-1,93.7,120.0,120.0);
}
}
return 1;
}
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/dropgun", true) == 0 || strcmp(cmd, "/dropwep", true) == 0)
{
DropGun(playerid);
}
replaced your command.
what changed? NOTHING. but you may use this in your OnPlayerDeath() aswell:
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
DropGun(playerid);
return 1;
}
lets see what happens next ^^

