Screwed up DCMD cmd
#1

Hello,
This afternoon, ive made this code. It's a /giveweapon cmd with 3 parameters:
Код:
dcmd_giveweapon(playerid, params[]) {
 	if(adminlevel[playerid] == 0) {
    SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR,"You are not an Admin!"); return 1;
 	}
 	new giveplayerid, weaponID, ammo;
 	if(!strlen(params)) {
    SendClientMessage(playerid, 0xFF0000AA, "USAGE: /giveplayerweapon [id] [weaponid] [ammo]"); return 1;
 	}
 	giveplayerid = strval(params);

  if(!strlen(params)) {
    SendClientMessage(playerid, 0xFF0000AA, "USAGE: /giveplayerweapon [id] [weaponid] [ammo]"); return 1;
 	}
 	weaponID = strval(params);

	if(!strlen(params)) {
    SendClientMessage(playerid, 0xFF0000AA, "USAGE: /giveplayerweapon [id] [weaponid] [ammo]"); return 1;
	}
	ammo = strval(params);

	if(!IsPlayerConnected(giveplayerid)) {
    SendClientMessage(playerid, 0xFF0000AA, "That player is offline."); return 1;
	}
	if(weaponID < 1 || weaponID > 46) {
    SendClientMessage(playerid, 0xFF0000AA, "Use an correct weaponid! [0-46]"); return 1;
	}
	if(ammo < 1) {
		SendClientMessage(playerid, 0xFF0000AA, "You must give at least ammo 1."); return 1;
	}
	new string[256];
	new string2[256];
	GetPlayerName(giveplayerid, gname, sizeof (gname));
	GivePlayerWeapon(giveplayerid, weaponID, ammo);
	format(string,sizeof(string),"Admin %s has given you weapon %d with %d ammo!",pname,weaponID,ammo);
	format(string2,sizeof(string2),"You have given weapon %d to player %s",weaponID,gname);
	SendClientMessage(giveplayerid, ADMINFS_MESSAGE_COLOR, string);
	SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, string2);
	return 1;
}
If i execute this command, he show me the message "use a correct weaponid [0-46]". I think the parameters are screwed up by me, but i dont know how to fix it. Ive learned myself DCMD with a few tut's some days ago, and this is my first DCMD cmd with multiple parameters. Please help me,
Greetz,
sean5874
Reply
#2

strval has no Effect... use sscanf to extract all parameters

https://sampwiki.blast.hk/wiki/Sscanf

Код:
new giveplayer,weapon;

if(!sscanf(params,"ii",giveplayer,weapon))return SendClientMessage(...);
GivePlayerWeapon(giveplayer,weapon,30);
Reply
#3

Quote:
Originally Posted by BlackFoX_UD_
strval has no Effect... use sscanf to extract all parameters

https://sampwiki.blast.hk/wiki/Sscanf

Код:
new giveplayer,weapon;

if(!sscanf(params,"ii",giveplayer,weapon))return SendClientMessage(...);
GivePlayerWeapon(giveplayer,weapon,30);
well strval just gets the value of the string, strlen gets the length of the string . YES they do have effects but, sscanf will declare what all of your varibables mean . and check the length of it .
Reply
#4

Thanks all for the really quik response
I still have this message, what could i do?

Note: If i add one param, F.E: /giveweapon playerid, i get the message "Use a correct weaponid!"
But if i add two params, F.E: /giveweapon playerid weaponid, i get the message "USAGE: /giveplayerid [playerid] [weaponid] [ammo]"
Reply
#5

sorry i forgot that sscanf must return true/-1 if it is false

Код:
if(sscanf(params,"ii",giveplayer,weapon))return SendClientMessage(...);
Reply


Forum Jump:


Users browsing this thread: