GivePlayerWeapon with dcmd
#1

Hello, i am trying to make a /giveweapon command, but the problem is, i dont know how to catch the input from the admin after the id, i know how to catch /giveweapon <ID> but not the /giveweapon <id> <weaponid> <ammo>

this is my dcmd command:

Код:
	
 	dcmd_giveweapon(playerid, params[])
	{
	new id, n[MAX_PLAYER_NAME], on[MAX_PLAYER_NAME];
	new tmp[256],tmp2[256],tmp3[256], Index, str[49];
	tmp = strtok(params, Index), tmp2 = strtok(params,Index), tmp3 = strtok(params,Index), id = strval(tmp), weapon = strval(tmp2), ammo = strval(tmp3);
	GetPlayerName(id, on, sizeof(on));
	GetPlayerName(playerid,n,sizeof(n));
	if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid, ORANGE, "You need to be level 4 to use this command!");
	if(!strlen(params)) return SendClientMessage(playerid, GREY, "USAGE: /giveweapon <ID> <weaponid> <ammo>");
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, GREY, "Invalid ID");
	format(str, sizeof(str), "%s gave weapons to %s", n, on);
	SendClientMessageToAll(ORANGE, str);
	GivePlayerWeapon(id, weapon, ammo);
	return 1;
	}
The errors that i am getting:
Код:
 error 017: undefined symbol "weapon"
 error 017: undefined symbol "ammo"
 error 017: undefined symbol "weapon"
I know its something with the
''new'' lines,


If someone could help me, Thank you in advance!
Reply
#2

Guessing you've just copied and pasted that straight in to your gamemode. I'd suggest using zcmd it's much easier to use.
Reply
#3

I followed a tutorial, and from out to create a /heal command i tried to edit it to /giveweapon
Reply
#4

Go with Zcmd and Sscanf instead.
Reply
#5

I know what Zcmd is , but im wondering, where is Sscanf used for?
Does anyone have the download link for Sscanf? The one on the forum does not work
Reply
#6

Quote:
Originally Posted by luckie12
Посмотреть сообщение
I know what Zcmd is , but im wondering, where is Sscanf used for?
THe download link for Sscanf is not working at the thread ?
Sscanf is used for scanning and comparing strings aswell as defining paramterers and attaching each parameter to a variable. For example:

I have the command "/kick <playerid/partofname> <reason>"

pawn Код:
CMD:kick(playerid, params[]) {
     new id, reason;
     if(sscanf(params, "us[100]", id, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick <playerid/partofname> <reason>");
}
Where "us[100]" can be split up to "u" and "s[100]". The u defines a playerid or part of the players name. the s[100] tells you that we're looking for a string up to 100 characters in the parameters.

If the parameters in the command is not entered as shown above, we will then return the syntax-message.

You can with the rest of the command use the parameters we've entered.

pawn Код:
CMD:kick(playerid, params[]) {
    new id, reason, name[MAX_PLAYER_NAME];
    if(sscanf(params, "us[100]",id, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick <playerid/partofname> <reason>");
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You're not an admin.");
    Kick(id);
    GetPlayerName(id, name, sizeof(name));
    format(string, sizeof(string), "%s has been kicked of the server. Reason: %s", name, reason);
    SendClientMessageToAll(-1, string);
    return 1;
}
Github downloads are here: https://github.com/maddinat0r/sscanf/releases
Reply
#7

Ooh, wow, thanks for the link and the explanation of it!

Awesome Introzen!
Reply
#8

Код:
	format(string, sizeof(string), "%s has been kicked of the server. Reason: %s", name, reason);
gives me :

Код:
C:\Users\vm07\Desktop\SampServer\filterscripts\gAdmin.pwn(383) : error 017: undefined symbol "string"
C:\Users\vm07\Desktop\SampServer\filterscripts\gAdmin.pwn(383) : error 017: undefined symbol "string"
C:\Users\vm07\Desktop\SampServer\filterscripts\gAdmin.pwn(383) : error 029: invalid expression, assumed zero
I copied ur code to test it, but then i get that ..
Reply
#9

Quote:
Originally Posted by luckie12
Посмотреть сообщение
Ooh, wow, thanks for the link and the explanation of it!

Awesome Introzen!
No problem. Zcmd and sscanf is the reason I still got the energy to script. Once you learn them, you'll never go back. Good luck!
Reply
#10

The codes i use :

Код:
	CMD:me(playerid, params[])
	{
		new string[128],msg[128],pname[MAX_PLAYER_NAME];
		GetPlayerName(playerid,pname,sizeof(pname));
		if(sscanf(params,"sz",msg)) return SendClientMessage(playerid,ORANGE, "USAGE: /me <text>");
		format(string,sizeof(string),"*%s %s",pname,msg);
		SendClientMessageToAll(GREY,string);
		return 1;
	}
	
	CMD:kick(playerid, params[])
	{
	new string[128];
	new id, reason, name[MAX_PLAYER_NAME];
 	if(sscanf(params, "us[100]",id, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick <playerid/partofname> <reason>");
 	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You're not an admin.");
	Kick(id);
	GetPlayerName(id, name, sizeof(name));
	format(string, sizeof(string), "%s has been kicked of the server. Reason: %s", name, reason);
	SendClientMessageToAll(-1, string);
	return 1;
}
Both return

SERVER: Unknown command
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)