help with /giveweapon command
#1

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?
Reply
#2

Where you give ammo = ??
Reply
#3

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

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
Reply
#5

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;
 }
Reply
#6

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.
Reply
#7

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 .
Reply
#8

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

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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)