OnPlayerKeyStateChange (problem 2)
#1

Somebody tell me why this not working, it sends a message to the cop that there is no player in range of point even there is a player in range of point.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new targetid, string[128];
    new Random = random(sizeof(RandomJail));
    new Float:x,Float:y,Float:z;

    if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
    {
        if(LawEnforcementMode[playerid] == 1)
        {
            GetPlayerPos(targetid,x,y,z);
            if(!IsPlayerInRangeOfPoint(playerid, 4.5, x,y,z)) return SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point.");
            if(IsPlayerInRangeOfPoint(playerid, 4.5, x,y,z))
            {
                if(1<=GetPlayerWantedLevel(targetid)<=3)
                {
                    if(PlayerInfo[targetid][pTicket] == 0)
                    {
                        PlayerInfo[targetid][pTicket] = 1;
                        PlayerInfo[targetid][pTReceived] ++;
                        PlayerInfo[playerid][pTIssued] ++;
                        SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
                        format(string, sizeof(string), "%s(%d) has issued you a ticket for $4000, you have 20 seconds to /pay the ticket.", GetName(playerid), playerid);
                        SendClientMessage(targetid, COLOR_WHITE,string);
                        GameTextForPlayer(targetid,"~w~Ticket is Issued~n~Type /pay to pay it",5000,4);
                        WantedInc[targetid] = SetTimerEx("WantedIncreaser", 20000, false, "i", targetid);
                        format(string, sizeof(string), "You have issued a Ticket to %s(%d) for $4000", GetName(targetid),targetid);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                    }
                }
                if(GetPlayerWantedLevel(targetid)>=4)
                {
                    GameTextForPlayer(targetid,"~r~Busted!",7000,4);
                    SetPlayerWantedLevel(targetid,0);
                    ResetPlayerWeapons(targetid);
                    PlayerInfo[targetid][pJailed] = 1;
                    SetPlayerInterior(targetid,3);
                    SetPlayerPos(targetid, RandomJail[Random][0], RandomJail[Random][1], RandomJail[Random][2]);
                    SetPlayerFacingAngle(targetid, RandomJail[Random][3]);
                    SetCameraBehindPlayer(targetid);
                    SetPlayerVirtualWorld(targetid,1);
                    SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
                    SetPlayerScore(targetid,GetPlayerScore(targetid)-1);
                    format(string, sizeof(string), "%s(%d) has been Arrested by Law Enforcement %s(%d)", GetName(targetid), targetid, GetName(playerid), playerid);
                    SendClientMessageToAll(COLOR_WHITE,string);
                    Releaser[targetid] = SetTimerEx("JailTime",60000, false, "i", targetid);
                }
                if(GetPlayerWantedLevel(targetid) == 0)
                {
                    SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point");
                }
            }
        }
    }
    return 1;
}
Reply
#2

You declared targetid and never assigned any value on it. So it's 0; therebefore you check if the player is not in range of the player with ID 0 position to return the error message.

And except that, you send the same message if the wanted level of the player with ID 0 is 0:
pawn Код:
if(GetPlayerWantedLevel(targetid) == 0)
{
    SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point");
}
Assuming you wanted to write another message.
Reply
#3

so what to do now ? delete this:
pawn Код:
if(GetPlayerWantedLevel(targetid) == 0)
{
    SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point");
}
Reply
#4

I cannot help on that, you use that script so you are the one you should know. Maybe it should return an error message that you cannot arrest a player with wanted level 0?

Anyways, the main problem is the targetid like I said on the first post because it's always 0.
Reply
#5

FIXED
Reply
#6

And change this

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 4.5, x,y,z)) return SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point.");
if(IsPlayerInRangeOfPoint(playerid, 4.5, x,y,z))
to this

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 4.5, x,y,z)) SendClientMessage(playerid, COLOR_WHITE, "Error: There is no player in range of point.");
else
There is no need to check again nor return.
Reply
#7

yes thanks i got this, and i fixed it :)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)