SA-MP Forums Archive
GivePlayerWeapon with dcmd - 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)
+--- Thread: GivePlayerWeapon with dcmd (/showthread.php?tid=603862)



GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

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!


Re: GivePlayerWeapon with dcmd - Luis- - 28.03.2016

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


Re: GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

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


Re: GivePlayerWeapon with dcmd - introzen - 28.03.2016

Go with Zcmd and Sscanf instead.


Re: GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

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


Re: GivePlayerWeapon with dcmd - introzen - 28.03.2016

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


Re: GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

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

Awesome Introzen!


Re: GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

Код:
	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 ..


Re: GivePlayerWeapon with dcmd - introzen - 28.03.2016

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!


Re: GivePlayerWeapon with dcmd - luckie12 - 28.03.2016

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