Command Help
#1

I think these will be my last questions of the day. (I apologize...)

EDIT: Alright, the below /kickall command is working now. (credits to PotH3Ad)

pawn Код:
command(kickall, playerid, params[]) // Credits to "PotH3Ad" //
{
    new reason[100], string[128];
    if(sscanf(params, "s", reason)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /kickall [reason]");
    else if(PlayerStatistics[playerid][pAdminLevel] >= 4) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /kickall [reason]");

    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        format(string, sizeof(string), "Administrator %s has kicked all players. Reason: %s", GetName(playerid), reason);
        SendClientMessageToAll(COLOR_RED, string);
        SavePlayerAccount(i);
        Kick(i);
    }
    return 1;
}
EDIT: The command below is also fixed. (credits to mick88)

pawn Код:
command(freeze, playerid, params[]) // Credits to mick88 //
{
    if(PlayerStatistics[playerid][pAdminLevel] >= 2) return false;
    new pid, string[128];
    if(sscanf(params, "u", pid)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /freeze [player]");
    if(pid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "That player is not connected!");
    PlayerFrozen[pid] = !PlayerFrozen[pid];
    TogglePlayerControllable(pid, !PlayerFrozen[pid]);
    format(string, sizeof(string), "Administrator %s has frozen you!", GetName(playerid));
    SendClientMessage(pid, COLOR_LIGHTBLUE, string);
    format(string, sizeof(string), "You have frozen player %s", GetName(pid));
    SendClientMessage(pid, COLOR_WHITE, string);
    return 1;
}
EDIT: Okay, I fixed the command below. If you want it, take it. (it repairs the specified players vehicle) [TESTED]

pawn Код:
command(pvrepair, playerid, params[])
{
    new id, string[128];
    if(sscanf(params, "u", id))
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 4)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /pvrepair [playerid]");
        }
    }
    else
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 4)
        {
            if(IsPlayerConnectedEx(id))
            {
                if(IsPlayerInAnyVehicle(id))
                {
                    RepairVehicle(GetPlayerVehicleID(id));
                    format(string, sizeof(string), "Administrator %s has fixed your vehicle!", GetName(playerid));
                    SendClientMessage(id, COLOR_LIGHTBLUE, string);
                    format(string, sizeof(string), "You have fixed %s's vehicle!", GetName(id));
                    SendClientMessage(playerid, COLOR_WHITE, string);
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: That player is not in a vehicle!");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "ERROR: That player is either not connected, or not logged in!");
            }
        }
    }
    return 1;
}
Reply
#2

This should work:

pawn Код:
command(kickall, playerid, params[])
{
    new reason[100], string[128];
    if(sscanf(params, "s", reason)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /kickall [reason]");
    else if(PlayerStatistics[playerid][pAdminLevel] < 4) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /kickall [reason]");

    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        format(string, sizeof(string), "Administrator %s has kicked all players. Reason: %s", GetName(playerid), reason);
        SendClientMessageToAll(COLOR_RED, string);
        SavePlayerAccount(i);
        Kick(i);
    }
    return 1;
}
Reply
#3

You don't assign any value to player_frozen before you check it, you should make a public array where you store informations which players are frozen and then check it when you execute command. The variable you used is local...
Reply
#4

Quote:
Originally Posted by mick88
Посмотреть сообщение
You don't assign any value to player_frozen, you should make a public array where you store informations which players are frozen and then check it when you execute command. The variable you used is local...
Or better yet, just use PVars...
Reply
#5

Quote:
Originally Posted by mick88
Посмотреть сообщение
You don't assign any value to player_frozen before you check it, you should make a public array where you store informations which players are frozen and then check it when you execute command. The variable you used is local...
Okay, you've confused me. If it isn't too much trouble, could you please show me an example?

Quote:
Originally Posted by PotH3Ad
Посмотреть сообщение
Or better yet, just use PVars...
I don't quite know how to use PVars yet, got an example?
Reply
#6

Код:
new PlayerFrozen[MAX_PLAYERS];
CMD:freeze()
{
//check if playerid is admin here
new pid;
//sscanf here
PlayerFrozen[pid] = !PlayerFrozen[pid];
return TogglePlayerControllable(pid, !PlayerFrozen[pid]);
}
Dont forget to clear the PlayerFrozen[] array in OnPlayerConnect()

This is the way i'd do it. I dont use PVars myself, i use arrays/enums for efficiency, but if you use PVars you can share player variables across filterscripts and you can print them out to console easily.
Reply
#7

Quote:
Originally Posted by mick88
Посмотреть сообщение
Код:
new PlayerFrozen[MAX_PLAYERS];
CMD:freeze()
{
//check if playerid is admin here
new pid;
//sscanf here
PlayerFrozen[pid] = !PlayerFrozen[pid];
return TogglePlayerControllable(pid, !PlayerFrozen[pid]);
}
Dont forget to clear the PlayerFrozen[] array in OnPlayerConnect()

This is the way i'd do it. I dont use PVars myself, i use arrays/enums for efficiency, but if you use PVars you can share player variables across filterscripts and you can print them out to console easily.
Okay, so I transformed the example you game me, to this.

pawn Код:
new PlayerFrozen[MAX_PLAYERS];
CMD:freeze()
{
    if(PlayerStatistics[playerid][pAdminLevel])
    {
        new pid;
        if(sscanf(params, "u", id))
        {
            if(PlayerStatistics[playerid][pAdminLevel] >= 1)
            {
                SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /freeze [playerid]");
            }
        }
        PlayerFrozen[pid] = !PlayerFrozen[pid];
        return TogglePlayerControllable(pid, !PlayerFrozen[pid]);
    }
    return 1;
}
You said to clear the array under "public OnPlayerConnect", how do I do that?
Reply
#8

Quote:
Originally Posted by PotH3Ad
Посмотреть сообщение
Or better yet, just use PVars...
I don't see why everyone is referring to Pvar's? It's slower, and Vars is easier to remember.
Reply
#9

Код:
        new pid;
        if(sscanf(params, "u", id))
Bug here. Also, why do you check if player is admin twice?
And check if player id is correct, otherwise command will crash because INVALID_PLAYER_NAME is larger than array size MAX_PLAYERS.

Reset by setting player as un-frozen when he connects:
Код:
PlayerFrozen[playerid] = false;
EDIT: sorry, just corrected last piece of code.
Reply
#10

Quote:
Originally Posted by mick88
Посмотреть сообщение
Код:
        new pid;
        if(sscanf(params, "u", id))
Bug here. Also, why do you check if player is admin twice?
And check if player id is correct, otherwise command will crash because INVALID_PLAYER_NAME is larger than array size MAX_PLAYERS.

Reset by setting player as un-frozen when he connects:
Код:
PlayerFrozen[playeris]
The way you do that command is confusing me. I'll be changing how I check if a player is an admin twice, but the main reason is so I can tell the admin how to do the command correctly. If you have a better way, care to share? I'm still modifying the command, but its truly confusing me and I don't know why. Could you explain it a little to me?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)