[SUPPORT]: /warn - HELP!
#1

Hey guys,

I'm currently working on a new warning system which uses MySQL to store the reason for the warning. Anhow, here's the scenario... When I go ingame and type /warn [playerid] [reason] it gives them a warning but the reason doesn't save into the database.

Here's the command:

pawn Код:
if(strcmp(cmd, "/warn", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(pLogged[playerid] == 0)
            {
                SendSplitClientMessage(playerid, COLOR_LIGHTRED, "[ERROR]: 0003 - You've not logged in.",80,90);
                return 1;
            }
            if(PlayerInfo[playerid][pAdmin] == 0)
            {
                SendSplitClientMessage(playerid, COLOR_LIGHTRED, "[ERROR]: 0004 - You're not a member of staff.",80,90);
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendSplitClientMessage(playerid, COLOR_SYSTEM, "[SYNTAX]: /warn [playerid/PartOfName] [reason]",80,90);
                return 1;
            }
            new giveplayerid;
            giveplayerid = ReturnUser(tmp);
            if (IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    new length = strlen(cmdtext);
                    while ((idx < length) && (cmdtext[idx] <= ' '))
                    {
                        idx++;
                    }
                    new offset = idx;
                    new result[64];
                    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                    {
                        result[idx - offset] = cmdtext[idx];
                        idx++;
                    }
                    result[idx - offset] = EOS;
                    if(!strlen(result))
                    {
                        SendSplitClientMessage(playerid, COLOR_SYSTEM, "[SYNTAX]: /warn [playerid/PartOfName] [reason]",80,90);
                        return 1;
                    }
                    format(string, sizeof(string), "[ADMIN]: %s %s has just given %s a warning. (Reason: %s)",AdminRank(playerid),GPN(playerid),GPN(giveplayerid),result);
                    SendAdminMessage(COLOR_LIGHTRED,string);
                    if(giveplayerid == playerid)
                    {
                        return 1;
                    }
                    else
                    {
                        if(PlayerInfo[giveplayerid][pWarn1] == 0)
                        {
                            SetAccount(PlayerInfo[giveplayerid][pID],"warn1","1");
                            format(string,sizeof(string),"%s",result);
                            SetAccount(PlayerInfo[giveplayerid][pID],"warnreason1",string);
                        }
                        else if(PlayerInfo[giveplayerid][pWarn2] == 0)
                        {
                            SetAccount(PlayerInfo[giveplayerid][pID],"warn2","1");
                            format(string,sizeof(string),"%s",result);
                            SetAccount(PlayerInfo[giveplayerid][pID],"warnreason2",string);
                        }
                        else if(PlayerInfo[giveplayerid][pWarn3] == 0)
                        {
                            SetAccount(PlayerInfo[giveplayerid][pID],"warn3","1");
                            format(string,sizeof(string),"%s",result);
                            SetAccount(PlayerInfo[giveplayerid][pID],"warnreason3",string);
                            format(string,sizeof(string),"[ADMIN]: %s has been banned by server. (Reason: 3 Warnings Recieved)",GPN(giveplayerid));
                            SendSplitClientMessageToAll(COLOR_LIGHTRED,string,80,90);
                            Kick(giveplayerid);
                        }
                    }
                    return 1;
                }
            }
            else
            {
                format(string, sizeof(string), "   %d is not an active player.", giveplayerid);
                SendSplitClientMessage(playerid, COLOR_GRAD1, string,80,90);
            }
        }
        return 1;
    }
SetAccount function:

pawn Код:
stock SetAccount(dbid, set[], amount[])
{
    new Query[ 128 ];
    format( Query, sizeof( Query ), "UPDATE players SET %s=%s WHERE id = '%d'", set,amount,dbid);
    mysql_query( Query );
    mysql_store_result();
    mysql_free_result();
    return 1;
}
The MySQL column that holds the reason is a VARCHAR, 128 characters so I don't see what the problem is, help?

~ Mike.
Reply
#2

%s='%s' Maybe?
Reply
#3

I think you need to revise your second piece of code. You need to add `'s where you have "players" and "id".
Reply
#4

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I think you need to revise your second piece of code. You need to add `'s where you have "players" and "id".
How do you mean?
Reply
#5

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
How do you mean?
I'm still learning MySQL code, but look...

pawn Код:
format( Query, sizeof( Query ), "UPDATE `players` SET '%s' = '%s' WHERE `id` = '%d'", set,amount,dbid);
That's the revised code, with my suggestion.
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I'm still learning MySQL code, but look...

pawn Код:
format( Query, sizeof( Query ), "UPDATE `players` SET '%s' = '%s' WHERE `id` = '%d'", set,amount,dbid);
That's the revised code, with my suggestion.
Nah, you dont need it on the "players" and "id" ..

im pretty sure that the only places you need it is on the second %s and %d...
Reply
#7

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
Nah, you dont need it on the "players" and "id" ..

im pretty sure that the only places you need it is on the second %s and %d...
Eh... I don't know, in my code I have to have the use of `'s, otherwise it won't work correctly.
Reply
#8

Yeah, that's what I don't get.

As soon as I use the function with another player variable such as pSkin it works perfectly, so I haven't got any idea.

~ Mike.
Reply
#9

Quote:
Originally Posted by Shadow™
Посмотреть сообщение
Yeah, that's what I don't get.

As soon as I use the function with another player variable such as pSkin it works perfectly, so I haven't got any idea.

~ Mike.
I'll tell you what; I will work on a MySQL enhanced warning system and if I can get one working, I will let you in on the code.
Reply
#10

Alright Sounds fair, hehe.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)