/setskin help!! Errors [rep+]
#1

pawn Код:
if(strcmp(cmd, "/setskin", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [Playerid/PartOfName] [skin id]");
                return 1;
            }
            new para1;
            new level;
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            level = strval(tmp);
            if(level > 299 || level < 1) { SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); return 1; }
            if (PlayerInfo[playerid][pAdmin] >= 2)
            {
                if(IsPlayerConnected(para1))
                {
                    if(para1 != INVALID_PLAYER_ID)
                    {
                        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                        format(string, sizeof(string), "You have set %s's skin to %d.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_GRAD2, string);
                        SetPlayerSkin(para1, level);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorised to use that command.");
            }
        }
        return 1;
    }

Ive have this command in a script of mine, Was a ripoff. It works fine over there according to my needs but when i put it my new GM. I dont know what is the problem of ReturnUser, I dont how it is used exactly? Please help!

On Compilation , It gives me the following errors :

Код:
C:\Documents and Settings\Luthra\Desktop\Country Wars\CW V2.5\gamemodes\CW.pwn(1321) : error 017: undefined symbol "ReturnUser"
C:\Documents and Settings\Luthra\Desktop\Country Wars\CW V2.5\gamemodes\CW.pwn(1331) : error 017: undefined symbol "giveplayer"
C:\Documents and Settings\Luthra\Desktop\Country Wars\CW V2.5\gamemodes\CW.pwn(1331) : error 017: undefined symbol "giveplayer"
C:\Documents and Settings\Luthra\Desktop\Country Wars\CW V2.5\gamemodes\CW.pwn(1331) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Luthra\Desktop\Country Wars\CW V2.5\gamemodes\CW.pwn(1331) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#2

ReturnUser is a function from utils isnt it? Or is it dutils? Try getting those 2 includes
Reply
#3

ReturnUser is a function from utils isnt it? Or is it dutils? Try getting those 2 includes
Reply
#4

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256],
        tmp[128],
        idx;
    if(strcmp(cmd, "/setskin", true) == 0) {
        if(IsPlayerConnected(playerid)) {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [Playerid/PartOfName] [skin id]");
                return 1;
            }
            new para1,
                level,
                string[128],
                giveplayer[MAX_PLAYER_NAME];
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            level = strval(tmp);
            if(level > 299 || level < 1) { SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); return 1; }
            if (PlayerInfo[playerid][pAdmin] >= 2) {
                if(IsPlayerConnected(para1)) {
                    if(para1 != INVALID_PLAYER_ID) {

                        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                        format(string, sizeof(string), "You have set %s's skin to %d.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_GRAD2, string);
                        SetPlayerSkin(para1, level);
                    }
                }
            }
            else {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorised to use that command.");
            }
        }
        return 1;
    }
    return 0;
}

stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) {
        if (text[pos] == 0) return INVALID_PLAYER_ID;
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS) {
            if(!IsPlayerConnected(userid)) {
                userid = INVALID_PLAYER_ID;
            }
            else {
                return userid;
            }
        }
    }
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++) {
        if (IsPlayerConnected(i)) {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) {
                if (len == strlen(name)) {
                    return i;
                }
                else {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1) {
        if (playerid != INVALID_PLAYER_ID) {
            if (count) {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
            }
            else {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid;
}
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++) {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Reply
#5

I urgently suggest you are going to use either zcmd or y_cmd, and use sscanf for the parameters. This is much much faster, and you will get better support from everyone. You can do a simple search query to find many tutorials about these systems.
Reply
#6

Quote:
Originally Posted by Neozftw
Посмотреть сообщение
I urgently suggest you are going to use either zcmd or y_cmd, and use sscanf for the parameters. This is much much faster, and you will get better support from everyone. You can do a simple search query to find many tutorials about these systems.
If i want to change to zcmd or y_cmd?Do i need to change all my cmds?? And Which is and better, zcmd or y_cmd??

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
I usually work with sscanf so I'm not that familiar with this kind of way to do commands but I think that you actually forgot to define giveplayer.
So this is the new code.

Try now

pawn Код:
if(strcmp(cmd, "/setskin", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [Playerid/PartOfName] [skin id]");
            return 1;
        }
        new para1;
        new level;
        new giveplayer[MAX_PLAYER_NAME];                       
        tmp = strtok(cmdtext, idx);
        para1 = ReturnUser(tmp);
        level = strval(tmp);
        if(level > 299 || level < 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!");
            return 1;
        }
        if (PlayerInfo[playerid][pAdmin] >= 2)
        {
            if(IsPlayerConnected(para1))
            {
                if(para1 != INVALID_PLAYER_ID)
                {
                    GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                    format(string, sizeof(string), "You have set %s's skin to %d.", giveplayer,level);
                    SendClientMessage(playerid, COLOR_GRAD2, string);
                    SetPlayerSkin(para1, level);
                }
            }
        }
        else
        {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorised to use that command.");
        }
    }
    return 1;
}
Given an error "ReturnUser undefined symbol" Thanks for the help though bro! Sscanf easy to use??

Quote:
Originally Posted by Kostas'
Посмотреть сообщение
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256],
        tmp[128],
        idx;
    if(strcmp(cmd, "/setskin", true) == 0) {
        if(IsPlayerConnected(playerid)) {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [Playerid/PartOfName] [skin id]");
                return 1;
            }
            new para1,
                level,
                string[128],
                giveplayer[MAX_PLAYER_NAME];
            para1 = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            level = strval(tmp);
            if(level > 299 || level < 1) { SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); return 1; }
            if (PlayerInfo[playerid][pAdmin] >= 2) {
                if(IsPlayerConnected(para1)) {
                    if(para1 != INVALID_PLAYER_ID) {

                        GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                        format(string, sizeof(string), "You have set %s's skin to %d.", giveplayer,level);
                        SendClientMessage(playerid, COLOR_GRAD2, string);
                        SetPlayerSkin(para1, level);
                    }
                }
            }
            else {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorised to use that command.");
            }
        }
        return 1;
    }
    return 0;
}

stock ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) {
        if (text[pos] == 0) return INVALID_PLAYER_ID;
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS) {
            if(!IsPlayerConnected(userid)) {
                userid = INVALID_PLAYER_ID;
            }
            else {
                return userid;
            }
        }
    }

    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++) {
        if (IsPlayerConnected(i)) {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) {
                if (len == strlen(name)) {
                    return i;
                }
                else {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1) {
        if (playerid != INVALID_PLAYER_ID) {
            if (count) {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
            }
            else {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid;
}
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++) {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Thanks alot brother. That worked! Can you explain me the usage of the functions you used? And return user?


EDIT: Which cmd system is better and easy for beginners?? zcmd/y_cmd/sscanf?


Thanks to everyone for the help! [repped+]
BMiaa
Reply
#7

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
I tested it like this and it compiled fine in my script
pawn Код:
if(strcmp(cmd, "/setskin", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [Playerid/PartOfName] [skin id]");
            return 1;
        }
        new string[128]; //remove this line if it gives errors about shadowed variables, etc
        new para1 = ReturnUser(tmp);
        new level = strval(tmp);
        new giveplayer[MAX_PLAYER_NAME];
        tmp = strtok(cmdtext, idx);
        if(level > 299 || level < 1)
        {
            SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!");
            return 1;
        }
        if (PlayerInfo[playerid][pAdmin] >= 2)
        {
            if(IsPlayerConnected(para1))
            {
                if(para1 != INVALID_PLAYER_ID)
                {
                    GetPlayerName(para1, giveplayer, sizeof(giveplayer));
                    format(string, sizeof(string), "You have set %s's skin to %d.", giveplayer,level);
                    SendClientMessage(playerid, COLOR_GRAD2, string);
                    SetPlayerSkin(para1, level);
                }
            }
        }
        else
        {
                SendClientMessage(playerid, COLOR_GRAD1, "You are not authorised to use that command.");
        }
    }
    return 1;
}
I already got the cmd done from Kostas!! Thanks alot for the help mate.

Which cmd system should i use? zcmd/y_cmd/sscanf? which is easy to use?
Reply
#8

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
I like sscanf myself because it's easy to understand and it's reliable.
But that depends on what you think is best, I'd suggest you to use the 3 of them, test them and evaluate which one is better for you.
Do i need to change all my CMD's if i want to change the cmd system
Reply
#9

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
yes..
That's why I suggested you to test the three in a little script before.
Will be a problem lol. I will try to learn the way we design CMD's with the help zcmd or anyone?

But can i use the CM's im using as well as the CMD's i will make from zcmd/sscanf at the same time in my GM?
Thanks for the reply brother
Reply
#10

Quote:
Originally Posted by belhot1992
Посмотреть сообщение
Yes, you can still use the OnPlayerCommandText commands while trying the other CM processors out.
I've compiled with code OnPlayerCommandText and it just works fine.
I will use the default way of designing code's even if they are tough lol.
But on the other side for all the NEW Cmds i will for my GM, I will use zcmd or sscanf for sure.
Anyhow u got a tutorial link for changing OnPlayerCommandText CMD's to zcmd/sscanf?

Ive seen dcmd to zcmd but not anyone else?
Thanks for your help mate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)