#1

I have made 2 jail commands witch seams not want work

First one, this do nothing but crash the server
pawn Код:
*COMMAND:jail(playerid, params[])
{
    new id;
    if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /jail [id] Reason.");
    GetPlayerName(playerid, Name, sizeof(Name));
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        format(String, sizeof(String), "%s jailed you, Reason %s .",Name);
        SendClientMessage(id,0xFF0000FF, String);
        SetPlayerColor(id,COLOR_RED);
        SetPlayerPos(id, 412.99816894531,2543.0656738281,26.244613647461);
        SetPlayerHealth(id, 99999999999999999999999);
        SetPlayerSkin(id, 62);
        format(String, sizeof(String), "You have jailed %s, Reason %s",Name);
        SendClientMessage(playerid,0xFF0000FF, String);
        TogglePlayerControllable(id,true);
    }
    return 1;
}
This one does not crash the server, but do nothing
pawn Код:
COMMAND:jail(playerid, params[])
{
    new id;
    if(IsPlayerConnected(id))
    if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /jail [id]");
    //if(Jail[id] == 1) return SendClientMessage(playerid,red,"This user is already in jail!");
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        GetPlayerName(playerid, Name, sizeof(Name));
        format(String, sizeof(String), "%s has jailed you",Name);
        SendClientMessage(id,green, String);
        //Jail[id] = 1;
        SetPlayerSkin(id, 62);
        SetPlayerPos(id, 412.99816894531,2543.0656738281,26.244613647461);
        SetPlayerColor(id,COLOR_GREEN);
        format(String, sizeof(String), "You have jailed %s",Name);
        SendClientMessage(playerid,green, String);
    }
    return 1;
}
Cant understand why they don't work.
Reply
#2

Your code hardly makes any sense. I'll point out the critical flaws for you to understand:

pawn Код:
COMMAND:jail(playerid, params[])
{
    new id; // <-- You're declaring the variable, which by default is 0
    if(IsPlayerConnected(id)) // <-- You're checking if ID 0 is connected, no matter what!
    if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /jail [id]"); // <-- Now you're getting the ID after it's too late...
    //if(Jail[id] == 1) return SendClientMessage(playerid,red,"This user is already in jail!");
    if(PlayerInfo[playerid][Admin] >= 1) // <-- This part is fine
    {
        GetPlayerName(playerid, Name, sizeof(Name)); // <-- Where did you declare 'Name'?
        format(String, sizeof(String), "%s has jailed you",Name); // <-- Where did you declare 'String'?
        SendClientMessage(id,green, String);
        //Jail[id] = 1;
        SetPlayerSkin(id, 62);
        SetPlayerPos(id, 412.99816894531,2543.0656738281,26.244613647461);
        SetPlayerColor(id,COLOR_GREEN);
        format(String, sizeof(String), "You have jailed %s",Name);
        SendClientMessage(playerid,green, String);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
Your code hardly makes any sense. I'll point out the critical flaws for you to understand:

pawn Код:
COMMAND:jail(playerid, params[])
{
    new id; // <-- You're declaring the variable, which by default is 0
    if(IsPlayerConnected(id)) // <-- You're checking if ID 0 is connected, no matter what!
    if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /jail [id]"); // <-- Now you're getting the ID after it's too late...
    //if(Jail[id] == 1) return SendClientMessage(playerid,red,"This user is already in jail!");
    if(PlayerInfo[playerid][Admin] >= 1) // <-- This part is fine
    {
        GetPlayerName(playerid, Name, sizeof(Name)); // <-- Where did you declare 'Name'?
        format(String, sizeof(String), "%s has jailed you",Name); // <-- Where did you declare 'String'?
        SendClientMessage(id,green, String);
        //Jail[id] = 1;
        SetPlayerSkin(id, 62);
        SetPlayerPos(id, 412.99816894531,2543.0656738281,26.244613647461);
        SetPlayerColor(id,COLOR_GREEN);
        format(String, sizeof(String), "You have jailed %s",Name);
        SendClientMessage(playerid,green, String);
    }
    return 1;
}
Thank you!
Now it works, but what do you mean with "Where did you declare 'Name'?" "Where did you declare 'String'?"
Reply
#4

@Calg00ne
I my scripts almost all variables are global ;x
So maybe he did it here too ;p
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)