SA-MP Forums Archive
[help] plz fix my errors! /arrest - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [help] plz fix my errors! /arrest (/showthread.php?tid=66865)



[help] plz fix my errors! /arrest - StrickenKid - 25.02.2009

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.



Re: [help] plz fix my errors! /arrest - Mikep - 25.02.2009

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


Re: [help] plz fix my errors! /arrest - StrickenKid - 25.02.2009

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?


Re: [help] plz fix my errors! /arrest - Norn - 25.02.2009

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?



Re: [help] plz fix my errors! /arrest - StrickenKid - 25.02.2009

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


Re: [help] plz fix my errors! /arrest - JaYmE - 25.02.2009

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


Re: [help] plz fix my errors! /arrest - StrickenKid - 25.02.2009

cool thx