giving out weapons in range
#1

hey i want this command to give weapons to all players in range of point and the limit range is 500. and i want to say you give an m4 to all players in rannge of 500m.(15 totals)< this is how many players are in range of 500m.
Quote:

CMD:giveallweapon(playerid, params[])
{
new weap, ammo, range, str[128], WeapName[32];
if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not logged in!");
if(PlayerAcc[playerid][Admin] >= 4)
{
if(sscanf(params, "ii", weap, ammo, range)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /giveallweapon (id) (weaponid) (range)");
if(weap == 19 || weap == 20 || weap == 21) return SendClientMessage(playerid, COLOR_RED, "Error: There is no weaponid for 19/20/21!");
if(weap < 1 || weap > 47) return SendClientMessage(playerid, COLOR_RED, "Weapon Maxium (Left): 1 - Maxium (Right): 47");
if(ammo < 1 || ammo > 500) return SendClientMessage(playerid, COLOR_RED, "Ammo Maxium (Left): 0 - Maxium (Right): 500 ***");
if(range< 5 || range> 500) return SendClientMessage(playerid, COLOR_RED, "range Maxium (Left): 5 - Maxium (Right): 500 ***");
GetWeaponName(weap, WeapName, 32);
format(str, sizeof(str), "~w~%s ~g~", WeapName, weap);
GameTextForAll(str, 4000, 3);
foreach(Player, i)
{
if(IsPlayerConnected(i))
{
GivePlayerWeapon(i,weap,ammo);
}
}
format(str, sizeof(str), "Admin %s(%d) gave you a %s", GetName(playerid), playerid, WeapName, weap, ammo);
SendClientMessageToAll(COLOR_LIGHTGREEN, str);
format(str, sizeof(str), "You given everyone a %s(%d) with %d ammo in range of %m ***", WeapName, weap, ammo, range);
SendClientMessage(playerid, COLOR_LIME, str);
}
else return ErrorMessages(playerid, 5);
return 1;
}

i need help with giving weapons in range of point
Reply
#2

Код:
CMD:giveallweapon(playerid, params[])
{
	new weap, ammo, range, str[128], WeapName[32];
	
	new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
	
	if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not logged in!");
	if(PlayerAcc[playerid][Admin] >= 4)
	{
		if(sscanf(params, "iii", weap, ammo, range)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /giveallweapon (weapid) (ammo) (range)");
		if(weap == 19 || weap == 20 || weap == 21) return SendClientMessage(playerid, COLOR_RED, "Error: There is no weaponid for 19/20/21!");
		if(weap < 1 || weap > 47) return SendClientMessage(playerid, COLOR_RED, "Weapon Maxium (Left): 1 - Maxium (Right): 47");
		if(ammo < 1 || ammo > 500) return SendClientMessage(playerid, COLOR_RED, "Ammo Maxium (Left): 0 - Maxium (Right): 500 ***");
		if(range< 5 || range> 500) return SendClientMessage(playerid, COLOR_RED, "range Maxium (Left): 5 - Maxium (Right): 500 ***");
		GetWeaponName(weap, WeapName, 32);
		format(str, sizeof(str), "~w~%s ~g~", WeapName, weap);
		GameTextForAll(str, 4000, 3);
		foreach(new i: Player)
		{
			if(IsPlayerConnected(i))
			{
				if (IsPlayerInRangeOfPoint(i,range,x,y,z))
	    		{
					GivePlayerWeapon(i,weap,ammo);
					format(str, sizeof(str), "Admin %s(%d) gave you a %s with %d ammo", GetName(playerid), playerid, WeapName, weap, ammo);
					SendClientMessage(i,COLOR_LIGHTGREEN, str);
				}
			}
		}
		format(str, sizeof(str), "You given everyone a %s(%d) with %d ammo in range of %d ***", WeapName, weap, ammo, range);
		SendClientMessage(playerid, COLOR_LIME, str);
	}
	else return ErrorMessages(playerid, 5);
	return 1;
}
try this
Reply
#3

Quote:
Originally Posted by Scott Zulkifli
Посмотреть сообщение
Код:
CMD:giveallweapon(playerid, params[])
{
	new weap, ammo, range, str[128], WeapName[32];
	
	new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
	
	if(PlayerAcc[playerid][Log] == 0) return SendClientMessage(playerid, COLOR_RED, "Error: You are not logged in!");
	if(PlayerAcc[playerid][Admin] >= 4)
	{
		if(sscanf(params, "iii", weap, ammo, range)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /giveallweapon (weapid) (ammo) (range)");
		if(weap == 19 || weap == 20 || weap == 21) return SendClientMessage(playerid, COLOR_RED, "Error: There is no weaponid for 19/20/21!");
		if(weap < 1 || weap > 47) return SendClientMessage(playerid, COLOR_RED, "Weapon Maxium (Left): 1 - Maxium (Right): 47");
		if(ammo < 1 || ammo > 500) return SendClientMessage(playerid, COLOR_RED, "Ammo Maxium (Left): 0 - Maxium (Right): 500 ***");
		if(range< 5 || range> 500) return SendClientMessage(playerid, COLOR_RED, "range Maxium (Left): 5 - Maxium (Right): 500 ***");
		GetWeaponName(weap, WeapName, 32);
		format(str, sizeof(str), "~w~%s ~g~", WeapName, weap);
		GameTextForAll(str, 4000, 3);
		foreach(Player, i)
		{
			if(IsPlayerConnected(i))
			{
				if (IsPlayerInRangeOfPoint(i,range,x,y,z))
	    		{
					GivePlayerWeapon(i,weap,ammo);
					format(str, sizeof(str), "Admin %s(%d) gave you a %s with %d ammo", GetName(playerid), playerid, WeapName, weap, ammo);
					SendClientMessage(i,COLOR_LIGHTGREEN, str);
				}
			}
		}
		format(str, sizeof(str), "You given everyone a %s(%d) with %d ammo in range of %d ***", WeapName, weap, ammo, range);
		SendClientMessage(playerid, COLOR_LIME, str);
	}
	else return ErrorMessages(playerid, 5);
	return 1;
}
try this
Foreach processes connected players only, there's no need to validate whether they are connected or not. And that's the old syntax, the new one is "foreach(new i: Player)".
Reply
#4

thx both of you. but how can i make it count how many players that received the weapon? like:
Quote:

You given everyone a %s(%d) with %d ammo in range of %d (%s players)**

and if there are no players in the range how to send a message saying they are no players close to you?
Reply
#5

Quote:
Originally Posted by suni
Посмотреть сообщение
thx both of you. but how can i make it count how many players that received the weapon? like:

and if there are no players in the range how to send a message saying they are no players close to you?
Use an accumulator and validate whether that variable is equal to 0; otherwise, use it as a count.
Reply
#6

im sorry but i dont know what's an accumulator.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)