how give random player weapon? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: how give random player weapon? (
/showthread.php?tid=456348)
how give random player weapon? -
EitayEliyahu - 05.08.2013
how can i give for random player which the system choosing auto?
Re: how give random player weapon? -
Sliceofdeath - 05.08.2013
You got any system to give any player a weapon ?
If not then take this
pawn Код:
dcmd_giveweapon(playerid,params[])
{
new Index;
new tmp[256]; tmp = strtok(params,Index);
new tmp2[256]; tmp2 = strtok(params,Index);
new tmp3[256]; tmp3 = strtok(params,Index);
if(!strlen(tmp) || !strlen(tmp2)) return
SendClientMessage(playerid, COLOR, "Usage: /giveweapon [PlayerID] [Weapon ID/Name] [Ammo]") &&
SendClientMessage(playerid, COLOR, "Function: Will give a weapon to a specified player");
new player1 = strval(tmp);
new weap, ammo, WeapName[32];
new string[128];
if(!strlen(tmp3) || !IsNumeric(tmp3) || strval(tmp3) <= 0 || strval(tmp3) > 99999) ammo = 500;
else ammo = strval(tmp3);
if(!IsNumeric(tmp2)) weap = GetWeaponIDFromName(tmp2);
else weap = strval(tmp2);
if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID)
{
if(!IsValidWeapon(weap))
return SendClientMessage(playerid,red,"ERROR: Invalid Weapon ID");
GetWeaponName(weap,WeapName,32);
format(string, sizeof(string), "== You have given \"%s\" a %s (%d) with %d rounds of Ammo ", PlayerName2(player1), WeapName, weap, ammo);
SendClientMessage(playerid,COLOR,string);
if(player1 != playerid)
{
format(string,sizeof(string),"== \"%s\" has given you a %s (%d) with %d rounds of Ammo ", PlayerName2(playerid), WeapName, weap, ammo);
SendClientMessage(player1,COLOR,string);
}
return GivePlayerWeapon(player1, weap, ammo);
}
return 1;
}
Add it in your Admin filterscript.
Re: how give random player weapon? -
Konstantinos - 05.08.2013
http://forum.sa-mp.com/showpost.php?...22&postcount=6
@Sliceofdeath Read this;
Why you should not use 256
Re: how give random player weapon? -
EitayEliyahu - 05.08.2013
i need to random player..
Re: how give random player weapon? -
Sliceofdeath - 05.08.2013
Quote:
Originally Posted by EitayEliyahu
i need to random player..
|
You just have to write /giveweapon [player id] [weapon id]
Re: how give random player weapon? -
EitayEliyahu - 05.08.2013
Quote:
Originally Posted by Sliceofdeath
You just have to write /giveweapon [player id] [weapon id]
|
but i want random player!
no specifiec player
Re: how give random player weapon? -
Jefff - 05.08.2013
pawn Код:
RandomPlayerID()
{
new
RandomID[MAX_PLAYERS],
Players = 0;
for(new i=0; i != MAX_PLAYERS; i++)
if(IsPlayerConnected(i))
RandomID[Players++] = i;
if(!Players)
return INVALID_PLAYER_ID;
return RandomID[random(Players)];
}
new WinnerID = RandomPlayerID();
if(WinnerID != INVALID_PLAYER_ID)
{
GivePlayerWeapon(WinnerID,WeaponID,Ammo);
}
Re: how give random player weapon? -
RajatPawar - 05.08.2013
pawn Код:
stock choose_random_player()
{
new random_player = random(MAX_PLAYERS);
if(!IsPlayerConnected( random_player ) )
{
choose_random_player();
}
else return random_player;
}
Now use this to give weapon:
pawn Код:
GivePlayerWeapon(choose_random_player(), WEAPONID, AMMO);