SA-MP Forums Archive
help with /giveweapon command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: help with /giveweapon command (/showthread.php?tid=170804)



help with /giveweapon command - mrcoolballs - 24.08.2010

IN zcmd and sscanf2

okay im probebly way off but this is my current code

Код:
CMD:giveweapon(playerid, params[])
{
    if(Logged[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You are not logged in!");
    
	if(PlayerInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000FF,"You have to be Level 4 to use this command!!");
	
	new str[128],weap[128],ammo, id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME],weapon;
	
	if(sscanf(params, "usi[128]",id, weap, ammo))
	{
	    SendClientMessage(playerid, 0xFF0000FF, "Usage: /giveweapon [ID] [WEAPON] [AMMO]");
		return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
	if(!IsNumeric(weap))
	{
		weapon = GetWeaponIDFromName(weap);
		return 1;
	}


	GetPlayerName(playerid, Name1, sizeof(Name2));
	GetPlayerName(id, Name2, sizeof(Name2));
	
	format(str, sizeof(str), "Admin %s has given you a %s with %d's rounds of ammo", Name1, weapon, ammo);
	SendClientMessage(id, LIMEGREEN, str);
	
	format(str, sizeof(str), "You have given %s a %s with %d rounds of ammo", Name2, weapon,ammo);
	SendClientMessage(playerid, 0xFF0000FF, str);
	GivePlayerWeapon(id,weapon,ammo);
 	return 1;
}
it does not work when i type /giveweapon 0 minigun 1000... can anyone tell me why?


Re: help with /giveweapon command - Voldemort - 24.08.2010

Where you give ammo = ??


Re: help with /giveweapon command - Kyosaur - 24.08.2010

Change you're specifier list from "usi[128]" to "us[35]i".


Re: help with /giveweapon command - mrcoolballs - 24.08.2010

im still not sure if the second parameter to the command is suppose to be a string or an interval i just set it as s and hoped that one of you guys could help me out


Re: help with /giveweapon command - mrcoolballs - 24.08.2010

okay guys sorry for the double post but i solved it myself, and help from kyosaur heres the finished code it works great:

Код:
CMD:giveweapon(playerid, params[])
{
    if(Logged[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You are not logged in!");
	if(PlayerInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000FF,"You have to be Level 4 to use this command!!");
	
	new id, weap[128], ammo;
	
	if(sscanf(params, "us[35]i",id, weap, ammo))
	{
	    SendClientMessage(playerid, 0xFF0000FF, "Usage: /giveweapon [ID] [WEAPON] [AMMO]");
		return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
	GivePlayerWeapon(id,GetWeaponIDFromName(weap),ammo);
	return 1;
 }



Re: help with /giveweapon command - WackoX - 24.08.2010

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
okay guys sorry for the double post but i solved it myself, and help from kyosaur heres the finished code it works great:

Код:
CMD:giveweapon(playerid, params[])
{
    if(Logged[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You are not logged in!");
	if(PlayerInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000FF,"You have to be Level 4 to use this command!!");
	
	new id, weap[128], ammo;
	
	if(sscanf(params, "us[35]i",id, weap, ammo))
	{
	    SendClientMessage(playerid, 0xFF0000FF, "Usage: /giveweapon [ID] [WEAPON] [AMMO]");
		return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: That player is not connected!");
	GivePlayerWeapon(id,GetWeaponIDFromName(weap),ammo);
	return 1;
 }
Why are you doing stuff like [128] and [35] in sscanf? delete that.


Re: help with /giveweapon command - Kyosaur - 24.08.2010

Quote:
Originally Posted by WackoX
Посмотреть сообщение
Why are you doing stuff like [128] and [35] in sscanf? delete that.
Thats my fault, i forgot to tell him to change the variable size lol. I should've been more thorough (i blame lack of sleep :P).


Im glad to see you fix it though .


Re: help with /giveweapon command - mrcoolballs - 24.08.2010

wait so what variable size do i set it to in sscanf


Re: help with /giveweapon command - Kyosaur - 24.08.2010

Quote:
Originally Posted by mrcoolballs
Посмотреть сообщение
wait so what variable size do i set it to in sscanf
Put sscanf as 35, and set the variable to 36 (This way we have room for the terminating NULL character).