Why it won't detect when I'm near a vehicle?
#1

So, I'm working on a spray thingy and I'm checking if a player is near a vehicle, though it doesn't work.

Like, this detects when I'm near a vehicle but spams the chat with with client message and dialogs.


pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE && GetPlayerWeapon(playerid) == 41)
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            new Float:x, Float:y, Float:z;
            GetVehiclePos(i, x, y, z);
            if(IsPlayerConnected(playerid) && IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
            {
                ShowPlayerDialog(playerid, DIALOG_CAR_SPRAY, DIALOG_STYLE_LIST, "Spray Colour", "Color White\nColor Black\nColor Red\nColor Green\nColor Blue\nColor Yellow\nColor Orange\n", "Spray", "Exit");
            }
            else if(!IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
            {
                SendClientMessage(playerid, 0xFF0000FF, "You are not near any vehicle.");
            }
        }
    }
    return 1;
}

And this one doesn't spam the chat and doesn't detect when I'm near vehicle:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE && GetPlayerWeapon(playerid) == 41)
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            new Float:x, Float:y, Float:z;
            GetVehiclePos(i, x, y, z);
            if(IsPlayerConnected(playerid))
            {
                if(IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
                {
                    ShowPlayerDialog(playerid, DIALOG_CAR_SPRAY, DIALOG_STYLE_LIST, "Spray Colour", "Color White\nColor Black\nColor Red\nColor Green\nColor Blue\nColor Yellow\nColor Orange\n", "Spray", "Exit");
                }
                else
                {
                    SendClientMessage(playerid, 0xFF0000FF, "You are not near any vehicle.");
                }
            }
        }
    }
    return 1;
}

So, I wonder, how am I supposed to fix it and make it work properly.
Reply
#2

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE && GetPlayerWeapon(playerid) == 41)
    {
        new Float:x, Float:y, Float:z;
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            if(!GetVehiclePos(i, x, y, z)) continue;
            if(IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
            {
                ShowPlayerDialog(playerid, DIALOG_CAR_SPRAY, DIALOG_STYLE_LIST, "Spray Colour", "Color White\nColor Black\nColor Red\nColor Green\nColor Blue\nColor Yellow\nColor Orange\n", "Spray", "Exit");
                return 1;
            }
        }
        SendClientMessage(playerid, 0xFF0000FF, "You are not near any vehicle.");
    }
    return 1;
}
Reply
#3

EDIT: Forgive it, you just need a GetClosestVehicleToPlayer, search, you'll find.
Reply
#4

Quote:
Originally Posted by Pottus
Посмотреть сообщение
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE && GetPlayerWeapon(playerid) == 41)
    {
        new Float:x, Float:y, Float:z;
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            if(!GetVehiclePos(i, x, y, z)) continue;
            if(IsPlayerInRangeOfPoint(playerid, 10, x, y, z))
            {
                ShowPlayerDialog(playerid, DIALOG_CAR_SPRAY, DIALOG_STYLE_LIST, "Spray Colour", "Color White\nColor Black\nColor Red\nColor Green\nColor Blue\nColor Yellow\nColor Orange\n", "Spray", "Exit");
                return 1;
            }
        }
        SendClientMessage(playerid, 0xFF0000FF, "You are not near any vehicle.");
    }
    return 1;
}
Thanks it works, but I don't understand how? Like you are saying if it doesn't get the vehicle pos then continue? O.O and then I udnerstand, I didn't really get how you check if the player's near a vehicle inside the loop but outside the loop it also detects if you're not near any vehicle.

Could you explain it?


EDIT:


Quote:
Originally Posted by iFarbod
Посмотреть сообщение
EDIT: Forgive it, you just need a GetClosestVehicleToPlayer, search, you'll find.
I found that but I don't want to use a stock or anything like that, I want to use it in the code itself.


EDIT 2:

Oooop, I found some information about the continue thing, now I know why it works, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)