Please help, will be explained in the text.
#1

Hello reader,

I am trying to add an Admin, Moderator and Helper system for my server. The problem I have is the next:
When I set one player as Admin ( As that is the only thing I've scripted commands for yet so I can test if it works. ) everyone is Admin. How to fix this? The code:
pawn Код:
*under includes*
new isadmin[MAX_PLAYERS];
new targetplayerid;


// /setadmin command.
CMD:setadmin(playerid, params[])
{
        if (IsPlayerAdmin(playerid) == 1)
        {
        if (isnull(params)) return SendClientMessage(playerid, KLEUR_VOORB, "USAGE: /setadmin [ID] [level]");
            {
            if(!sscanf(params, "dd", targetplayerid, isadmin[targetplayerid]))
            if(isadmin[targetplayerid] > 6 || isadmin[targetplayerid] < 0) return SendClientMessage(playerid, KLEUR_VOORB, "Level: 0-6");
            if(isadmin[targetplayerid] == 0)
            {
            isadmin[targetplayerid] = 0;
            new maker[110];
            format(maker, sizeof(maker), "You have just removed %s from the Administration team.", pNaam(targetplayerid));
            SendClientMessage(playerid, KLEUR_BLAUW, maker);
            new krijger[110];
            format(krijger, sizeof(krijger), "Administrator %s has just removed you from the Administration team.", pNaam(playerid));
            SendClientMessage(targetplayerid, KLEUR_BLAUW, krijger);
            }
            if(isadmin[targetplayerid] == 1)
            {
            isadmin[targetplayerid] = 1;
            new maker[110];
            format(maker, sizeof(maker), "You have just added %s to the Administration team.", pNaam(targetplayerid));
            SendClientMessage(playerid, KLEUR_BLAUW, maker);
            new krijger[110];
            format(krijger, sizeof(krijger), "Administrator %s has just added you to the Administration team.", pNaam(playerid));
            SendClientMessage(targetplayerid, KLEUR_BLAUW, krijger);
            }
            }
        return 1;
        }
return 1;
}
I don't need a fixed up code as I do not really learn a lot from it, I'd like an explanation of how to fix it.

Thank you in advance,
Jesse
Reply
#2

pawn Код:
cmd(setadmin, playerid, params[])
{
    new level;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not an admin"); // If the player isn't an admin it will send him the message.
    if(!sscanf(params, "ui", targetplayerid, level)) return SendClientMessage(playerid, -1, "/setadmin [playerid] [level]);
    if(Level > 6 || 0 > Level) return SendClientMessage(playerid, -1, "
Level 0-6");
    isadmin[targetplayerid] = level; //isadmin will be the level you wrote in.
    switch (isadmin[targetplayerid]
    {
        case 0: SendClientMessage(playerid, -1, "
You have been removed from the admin team."); //If isadmin == 0 it will send him this message
        case 1: SendClientMessage(playerid, -1, "
You've been added to the admin team."); // If level 1 and so on this message will be set.
        case 2: SendClientMessage(playerid, -1, "You'
ve been added to the admin team.");
        case 3: SendClientMessage(playerid, -1, "
You've been added to the admin team.");
        case 4: SendClientMessage(playerid, -1, "You'
ve been added to the admin team.");
        case 5: SendClientMessage(playerid, -1, "
You've been added to the admin team.");
        case 6: SendClientMessage(playerid, -1, "You'
ve been added to the admin team.");
    }
    return 1;
}
Not tested but should work , edit it and stuff.
Reply
#3

Thank you for your reply but I already managed to fix it :P.. I fixed it like this:
pawn Код:
*under includes*
new answer;

// /setadmin command.
CMD:setadmin(playerid, params[])
{
        if (IsPlayerAdmin(playerid) == 1)
        {
        if (isnull(params)) return SendClientMessage(playerid, KLEUR_VOORB, "USAGE: /setadmin [ID] [level]");
            {
            if(!sscanf(params, "dd", targetplayerid, isadmin[answer]))
            if(isadmin[answer] > 6 || isadmin[answer] < 0) return SendClientMessage(playerid, KLEUR_VOORB, "Level: 0-6");
            if(isadmin[answer] == 0)
            {
            isadmin[targetplayerid] = 0;
            new maker[110];
            format(maker, sizeof(maker), "You have just removed %s from the Administration team.", pNaam(targetplayerid));
            SendClientMessage(playerid, KLEUR_BLAUW, maker);
            new krijger[110];
            format(krijger, sizeof(krijger), "Administrator %s has just removed you from the Administration team.", pNaam(playerid));
            SendClientMessage(targetplayerid, KLEUR_BLAUW, krijger);
            }
            if(isadmin[answer] == 1)
            {
            isadmin[targetplayerid] = 1;
            new maker[110];
            format(maker, sizeof(maker), "You have just added %s to the Administration team.", pNaam(targetplayerid));
            SendClientMessage(playerid, KLEUR_BLAUW, maker);
            new krijger[110];
            format(krijger, sizeof(krijger), "Administrator %s has just added you to the Administration team.", pNaam(playerid));
            SendClientMessage(targetplayerid, KLEUR_BLAUW, krijger);
            }
            }
        return 1;
        }
return 1;
}
Best regards,
Jesse
Reply
#4

All right, by the way if (isnull(params)) return SendClientMessage(playerid, KLEUR_VOORB, "USAGE: /setadmin [ID] [level]"); is not needed because you have sscanf.
Reply
#5

Quote:
Originally Posted by JhnzRep
Посмотреть сообщение
All right, by the way if (isnull(params)) return SendClientMessage(playerid, KLEUR_VOORB, "USAGE: /setadmin [ID] [level]"); is not needed because you have sscanf.
I know, but if you don't have the if (isnull(params)) line it won't send the "USAGE: /setadmin [ID] [level]" text right? People have told me before I don't need it but I don't know/think you don't see the text if it isn't there.
Reply
#6

pawn Код:
if(sscanf(params, "ui", targetplayerid, level)) return SendClientMessage(playerid, ADD_COLOR_HERE, "/setadmin [playerid] [level]);
by this
Reply
#7

pawn Код:
if(!sscanf(params, "dd", targetplayerid, isadmin[answer]))
You have this..

To that you add return SCM like this.

pawn Код:
if(!sscanf(params, "dd", targetplayerid, isadmin[answer])) return SCM(playerid, -1, "/setadmin [Playerid] [Level]");
This will send the message.

Offtopic
Oh and SCM stands for SendClientMessage. You can do this by:
pawn Код:
#define SCM SendClientMessage
Little tricks like this make scripting faster.
Reply
#8

Quote:
Originally Posted by emokidx111
Посмотреть сообщение
pawn Код:
if(sscanf(params, "ui", targetplayerid, level)) return SendClientMessage(playerid, ADD_COLOR_HERE, "/setadmin [playerid] [level]);
by this
That won't work...Because it has to be either

pawn Код:
if(sscanf(params, "u", targetplayerid, level)) return SendClientMessage(playerid, ADD_COLOR_HERE, "/setadmin [playerid] [level]);
Or

pawn Код:
if(!sscanf(params, "ui", targetplayerid, level)) return SendClientMessage(playerid, ADD_COLOR_HERE, "/setadmin [playerid] [level]);
EDIT: Sorry for double post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)