Need help with dcmd and sscanf
#1

So guys, I realized I had to learn dcmd and sscanf to script this shit properly.

Anyway, I followed the instructions on the wiki about dcmd the best I could, here's what I got:

Under my includes(tried under my color defines too):
Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Under OnPlayerCommandText:
Код:
	dcmd(kill, 4, cmdtext);
	dmcd(slap, 4, cmdtext);
Bottom of script(outside any other function):
Код:
dcmd_kill(playerid, params[])
{
	DidKill[playerid] = 1;
	SetPlayerHealth(playerid, 0);
	SendClientMessage(playerid, COLOR_ORANGE, "You committed suicide.");
	return 1;
}

dcmd_slap(playerid, params[])
{
	new id;
	if(strlen(params))
	{
	    id = strval(params);
	    if(IsPlayerConnected(id))
	    {
	        if(PlayerInfo[playerid][AdminLevel] > 1)
	        {
				new Float:px, Float:py, Float:pz;
				GetPlayerPosition(playerid, px, py, pz);
				SetPlayerPosition(playerid, px, py, pz+15);
				SendClientMessage(playerid,
			}
			else
			{
			    SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
			}
		}
		else
		{
		    SendClientMessage(playerid, COLOR_GREY, "Invalid Player ID.");
		}
	}
	else
	{
	    SendClientMessage(playerid, COLOR_GREY, "Usage: /slap (playerid)"
	}
	return 1;
}
Here's the errors I get:

Quote:

C:\Program Files (x86)\Rockstar Games\GTA San Andreas\ServerScript\pawno\edited.pwn(1421) : error 017: undefined symbol "dmcd"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\ServerScript\pawno\edited.pwn(2081) : warning 203: symbol is never used: "params"
C:\Program Files (x86)\Rockstar Games\GTA San Andreas\ServerScript\pawno\edited.pwn(2120) : warning 203: symbol is never used: "dcmd_slap"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

Could someone explain what I did wrong?


Also, I read about sscanf on the wiki as well. But I'm still not sure how to use it. If there is a tutorial somewhere, or someone would like to give me a brief and basic one, I'd be really happy.

Final question: Even with dcmd, the best I can do with commands is 1 parameter. Like /slap (ID). With trouble, I could do something like /spray (color 1) (color2). But how do I make a command with, say, 4 parameters? Like /ajail (ID/name) (time) (cell) (reason)?

Thanks for any help.
Reply
#2

pawn Код:
dcmd_slap(playerid, params[])
{
    new id;
                    if(sscanf(params,"u",id)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /Slap <ID>");
                    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY, "Player is not connected");

            if(PlayerInfo[playerid][AdminLevel] > 1)
            {
                new Float:px, Float:py, Float:pz;
                GetPlayerPosition(id, px, py, pz);
                SetPlayerPosition(id, px, py, pz+15);
                SendClientMessage(id,COLOR_GREY,"You just been slapped, bitch!");
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
            }
   

    return 1;
}
under onplayercommandtext
change dmcd to dcmd, and on the kill command you dont need that variable in there btw this code is untested
Reply
#3

OH FUCKING FAIL.

I didn't spot that typo

And in the kill command, I need the DidKill to check if the player committed suicide by the command or not.

Thanks bro.

And anyone who can help me on the last two questions?
Reply
#4

Sorry for double posting, but I must've been tired. I posted an incomplete code for the slap-command. Fixed it now.

Sscanf and 4-parameter commands, anyone?
Reply
#5

it is very very simple to make a 4 parameter command i will show you, its pretty much this one piece of code that does it:
pawn Код:
new id,id2,id3,id4;
if(sscanf(params,"uuuu",id,id2,id3,id4)) return SendClientMessage(playerid,COLOR_GREY,"USAGE: /bring p1 p2 p3 p4");
SetPlayerPos(id,2384.60, -1674.36, 14.75);
SetPlayerPos(id2,2384.60, -1674.36, 14.75);
SetPlayerPos(id3,2384.60, -1674.36, 14.75);
SetPlayerPos(id4,2384.60, -1674.36, 14.75);
This will set 4 people of your choice to those co-ordinates

It really is that simple, the "u" means a username or an id, so you can type in part of a players name or an id.

If you wanted a /givecash command for example, you would use:
"ui"
for the username and the i for the interval (ammount),

if you wanted a string, you would use s, thats for like a /kick reason command
Reply
#6

Wow, that's really nice. Thanks a lot.

I owe you a cookie, bro.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)