[help] plz fix my errors! /arrest
#1

i made this , arrest cmd but i got errors :S
heres the code:
pawn Код:
if(strcmp("/arrest", cmdtext, true, 7) == 0)
    {
        if(gTeam[playerid] != TEAM_COP) return SendClientMessage(playerid, COLOR_RED, "You Are Not A Cop. Only Cops Can Use This Command.");
        if(strlen(cmdtext[8]) == playerid) return SendClientMessage(playerid,COLOR_RED,"You Cannot Arrest Yourself, Idoit.");

        if(strlen(cmdtext[8]) == 0){

        new closest[MAX_PLAYERS];
        new closestlvl;
        closest = GetClosestPlayer(0);
        closestlvl = GetPlayerWantedLevel(closest);
        if(closestlvl < 4)
        {


        new copname[MAX_PLAYER_NAME];
        new cmdname[MAX_PLAYER_NAME], string[128];

        GetPlayerName(playerid, copname, sizeof(cmdname));
        GetPlayerName(strval(cmdtext[8]), cmdname, sizeof(cmdname));

        format(string, sizeof(string), "%s (%d) Has Been Arested By Officer %s (%d)", cmdname,strval(cmdtext[8]),copname,playerid);
        SendClientMessageToAll(COLOR_PURPLE, string);

        new rand;
        rand = random(sizeof(AJail));
        SetPlayerInterior(strval(cmdtext[8]), 3);
        SetPlayerPos(strval(cmdtext[8]), AJail[rand][0], AJail[rand][1], AJail[rand][2]);
        gPlayerJailed[playerid] = 1;
        SetPlayerWantedLevel(strval(cmdtext[8]),0);

        return 1;
        } else return SendClientMessage(playerid,COLOR_RED,"No Wanted Players Close Enough TO Arrest.");


        return 1;
        }


        return 1;
    }
and heres the errors

Код:
C:\Users\Ethan\Desktop\SAMPSERVER\gamemodes\Untitled.pwn(1518) : error 033: array must be indexed (variable "closest")
C:\Users\Ethan\Desktop\SAMPSERVER\gamemodes\Untitled.pwn(1519) : error 035: argument type mismatch (argument 1)
C:\Users\Ethan\Desktop\SAMPSERVER\gamemodes\Untitled.pwn(1544) : warning 225: unreachable code
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Reply
#2

Removed [MAX_PLAYERS] or add [playerid] when you set it.
Reply
#3

thx lol, just a silly mistake :S

i also took one of the "return 1;" out and it took out the unreachable code warning, heres the working code:
pawn Код:
if(strcmp("/arrest", cmdtext, true, 7) == 0)
    {
        if(gTeam[playerid] != TEAM_COP) return SendClientMessage(playerid, COLOR_RED, "You Are Not A Cop. Only Cops Can Use This Command.");
        if(strlen(cmdtext[8]) == playerid) return SendClientMessage(playerid,COLOR_RED,"You Cannot Arrest Yourself, Idoit.");

        if(strlen(cmdtext[8]) == 0){

        new closest[MAX_PLAYERS];
        new closestlvl;
        closest[playerid] = GetClosestPlayer(0);
        closestlvl = GetPlayerWantedLevel(closest[playerid]);
        if(closestlvl < 4)
        {


        new copname[MAX_PLAYER_NAME];
        new cmdname[MAX_PLAYER_NAME], string[128];

        GetPlayerName(playerid, copname, sizeof(cmdname));
        GetPlayerName(strval(cmdtext[8]), cmdname, sizeof(cmdname));

        format(string, sizeof(string), "%s (%d) Has Been Arested By Officer %s (%d)", cmdname,strval(cmdtext[8]),copname,playerid);
        SendClientMessageToAll(COLOR_PURPLE, string);

        new rand;
        rand = random(sizeof(AJail));
        SetPlayerInterior(strval(cmdtext[8]), 3);
        SetPlayerPos(strval(cmdtext[8]), AJail[rand][0], AJail[rand][1], AJail[rand][2]);
        gPlayerJailed[playerid] = 1;
        SetPlayerWantedLevel(strval(cmdtext[8]),0);

        return 1;
        } else return SendClientMessage(playerid,COLOR_RED,"No Wanted Players Close Enough TO Arrest.");

        }
       
        return 1;
    }
note: not tested in game yet!

also i got a question:
pawn Код:
if(closestlvl < 4)
thats it the wanted level is OVER 4, would
pawn Код:
if(closestlvl <= 4)
make it so if its 4 OR ABOVE?
Reply
#4

Quote:
Originally Posted by Ethan1233
thx lol, just a silly mistake :S

i also took one of the "return 1;" out and it took out the unreachable code warning, heres the working code:
pawn Код:
if(strcmp("/arrest", cmdtext, true, 7) == 0)
    {
        if(gTeam[playerid] != TEAM_COP) return SendClientMessage(playerid, COLOR_RED, "You Are Not A Cop. Only Cops Can Use This Command.");
        if(strlen(cmdtext[8]) == playerid) return SendClientMessage(playerid,COLOR_RED,"You Cannot Arrest Yourself, Idoit.");

        if(strlen(cmdtext[8]) == 0){

        new closest[MAX_PLAYERS];
        new closestlvl;
        closest[playerid] = GetClosestPlayer(0);
        closestlvl = GetPlayerWantedLevel(closest[playerid]);
        if(closestlvl < 4)
        {


        new copname[MAX_PLAYER_NAME];
        new cmdname[MAX_PLAYER_NAME], string[128];

        GetPlayerName(playerid, copname, sizeof(cmdname));
        GetPlayerName(strval(cmdtext[8]), cmdname, sizeof(cmdname));

        format(string, sizeof(string), "%s (%d) Has Been Arested By Officer %s (%d)", cmdname,strval(cmdtext[8]),copname,playerid);
        SendClientMessageToAll(COLOR_PURPLE, string);

        new rand;
        rand = random(sizeof(AJail));
        SetPlayerInterior(strval(cmdtext[8]), 3);
        SetPlayerPos(strval(cmdtext[8]), AJail[rand][0], AJail[rand][1], AJail[rand][2]);
        gPlayerJailed[playerid] = 1;
        SetPlayerWantedLevel(strval(cmdtext[8]),0);

        return 1;
        } else return SendClientMessage(playerid,COLOR_RED,"No Wanted Players Close Enough TO Arrest.");

        }
       
        return 1;
    }
note: not tested in game yet!

also i got a question:
pawn Код:
if(closestlvl < 4)
thats it the wanted level is OVER 4, would Below 4
pawn Код:
if(closestlvl <= 4)
Below 4 or equal to 4
make it so if its 4 OR ABOVE?
Reply
#5

ok so
pawn Код:
if(closestlvl >= 4)
is 4 or above right?
Reply
#6

Quote:
Originally Posted by Ethan1233
ok so
pawn Код:
if(closestlvl >= 4)
is 4 or above right?
Right
Reply
#7

cool thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)