Simple command issue.
#1

I'm having an issue with my command:

pawn Код:
if (strcmp("/hold", cmdtext, true, 10) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_LIGHTYELLOW,"[USAGE:] /hold [itemname]");
            return 1;
        }
        if (strcmp("burger", cmdtext, true, 10) == 0)
        {
            SetPlayerHoldingObject(playerid, 2880, 5);
        }
    }
    if (strcmp("/holdhelp", cmdtext, true, 10) == 0)
    {
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "_______________________________________");
        SendClientMessage(playerid, GREEN, "[FOOD:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " burger - pizza - burrito - pizzabox - sprunkcup - takeout");
        SendClientMessage(playerid, GREEN, "[ALCOHOL:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " beer - beer2 - whiskey - wineglass");
        SendClientMessage(playerid, GREEN, "[MISC:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " briefcase - hairdryer - scythe - record - backpack - boombox - moneybag");
        return 1;
    }
    return 0;
The compile is telling me:
error 017: undefined symbol "tmp"
error 017: undefined symbol "idx"
error 017: undefined symbol "tmp"


What I want is if the player doesn't type /hold and the item id.. it tells them the proper define. Also if the player types /hold burger, it'll actually put it in their hand.
Reply
#2

pawn Код:
if (strcmp("/hold", cmdtext, true, 10) == 0)
    {
        new tmp[64];
        new idx;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_LIGHTYELLOW,"[USAGE:] /hold [itemname]");
            return 1;
        }
        if (strcmp("burger", cmdtext, true, 10) == 0)
        {
            SetPlayerHoldingObject(playerid, 2880, 5);
        }
    }
    if (strcmp("/holdhelp", cmdtext, true, 10) == 0)
    {
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "_______________________________________");
        SendClientMessage(playerid, GREEN, "[FOOD:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " burger - pizza - burrito - pizzabox - sprunkcup - takeout");
        SendClientMessage(playerid, GREEN, "[ALCOHOL:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " beer - beer2 - whiskey - wineglass");
        SendClientMessage(playerid, GREEN, "[MISC:]");
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, " briefcase - hairdryer - scythe - record - backpack - boombox - moneybag");
        return 1;
    }
    return 0;
Fixed. If it doesn't work, please specify a problem.

Also, try using x_nr. I can give you a tutorial if you'd like.
Reply
#3

All help is appreciated. I'd love to learn as much as I can. So yes.. please pass up the tutorial.
Reply
#4

It doesn't seem to be working. When I type /hold it give me an unknown command error.
Reply
#5

firstly, if you are writing a gamemode yourself, you should consider using a fast command processor like zcmd
https://sampforum.blast.hk/showthread.php?tid=91354
if you decide to use zcmd, I suggest you also use sscanf(2)
https://sampforum.blast.hk/showthread.php?tid=120356
It will be harder at first, but a lot easier as you learn more.

If you are editing a gamemode, I suggest you consider converting it to zcmd and sscanf. If you don't want to convert it, then look closely at the OnPlayerCommandText() callback.

In your post above you are not using strcmp correctly, specifically the length parameter. Read this.
https://sampwiki.blast.hk/wiki/Strcmp

The first thing you do is define the variables you will be using in your commands.
Then you use strtok to separate the command from the rest of the parameters.
Then you use strcmp to process the command.
inside the command script, you keep using strtok to remove parameters from cmdtext one word at a time, using idx as a reference.

pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
     new cmd[32],idx,tmp[32],string[164];
     cmd = strtok(cmdtext, idx);
     if(!strcmp(cmd,"/hold",true))
     {
         tmp = strtok(cmdtext, idx);
         if(!strlen(tmp))
         {
              SendClientMessage(playerid,0xAFAFAFAA,"/hold [hold name] ( available names: briefcase, bottle, cigar, surfboard...)");
         }
         //rest of command here
once you have mastered this you can move on to the SetPlayerHoldingObject command, read this.
https://sampwiki.blast.hk/wiki/SetPlayerHoldingObject


good luck!
Reply
#6

Thanks. This helped tons .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)