If is player near coords..
#1

Hey I'm trying to detect if player is near those coords:
pawn Код:
new GasStations[8][]=
{
    {1942.0497,-1769.2963,13.6406}, // IW 1
    {1941.6536,-1776.3457,13.6406}, // IW 2
    {-1601.3220,-2708.2751,48.5391}, // highway towards Prickle Pine
    {1604.5129,-2712.7729,48.5335}, // highway towards Prickle Pine
    {-1607.7809,-2717.2312,48.5391}, // highway towards Prickle Pine
    {-1610.9799,-2722.2913,48.5391}, // highway towards Prickle Pine
    {-2247.2778,-2559.1624,31.9219}, // Diliamore
    {-2240.6899,-2562.2366,31.9219} // Dilliamore
};
I want to detect them in this function:
pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 7.0, 2695.6880, -1704.6300, 11.8438))
what to write in parameters to detect if player is near those coords?
And, is code correct? I'm not getting any errors for now..
Thanks for help in advance
Reply
#2

if u use '!' , it means that if he ISN'T in that place.
Reply
#3

pawn Код:
forward bool: IsPlayerInRangeOfGasStations( playerid );

new GasStations[8][3]=
{
    {1942.0497,-1769.2963,13.6406}, // IW 1
    {1941.6536,-1776.3457,13.6406}, // IW 2
    {-1601.3220,-2708.2751,48.5391}, // highway towards Prickle Pine
    {1604.5129,-2712.7729,48.5335}, // highway towards Prickle Pine
    {-1607.7809,-2717.2312,48.5391}, // highway towards Prickle Pine
    {-1610.9799,-2722.2913,48.5391}, // highway towards Prickle Pine
    {-2247.2778,-2559.1624,31.9219}, // Diliamore
    {-2240.6899,-2562.2366,31.9219} // Dilliamore
};

stock bool: IsPlayerInRangeOfGasStations( playerid )
{
    new
        bool: in_range
    ;
    for( new i; i != sizeof( GasStations ); i++ )
    {
        if( IsPlayerInRangeOfPoint( playerid, 7.0, GasStations[ i ][ 0 ], GasStations[ i ][ 1 ], GasStations[ i ][ 2 ] ) )
        {
            in_range = true;
            break;
        }
    }
    return in_range;
}
Where you want to check:
pawn Код:
if( IsPlayerInRangeOfGasStations( playerid ) )
{
    // player is in range:
}
Reply
#4

@Newbie scripter: I know that ^^

@Konstantinos:
Well I added your code for start it was great but after I added in my command:
pawn Код:
if( IsPlayerInRangeOfGasStations( playerid ) )
I received a lot of those warnings
pawn Код:
warning 213: tag mismatch
On those lines:
pawn Код:
{1942.0497,-1769.2963,13.6406}, // IW 1
    {1941.6536,-1776.3457,13.6406}, // IW 2
    {-1601.3220,-2708.2751,48.5391}, // highway towards Prickle Pine
    {1604.5129,-2712.7729,48.5335}, // highway towards Prickle Pine
    {-1607.7809,-2717.2312,48.5391}, // highway towards Prickle Pine
    {-1610.9799,-2722.2913,48.5391}, // highway towards Prickle Pine
    {-2247.2778,-2559.1624,31.9219}, // Diliamore
    {-2240.6899,-2562.2366,31.9219} // Dilliamore
EDIT: Command I want to use:
pawn Код:
if(strcmp(cmdtext, "/refuel", true) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to use this command.");
        if(IsPlayerInRangeOfGasStations(playerid))
        {
            // I will put code here
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You are not near any gas pump.");
            return 1;
        }
        return 1;
    }
    return 0;
}
Thanks for help in advance
Reply
#5

pawn Код:
GasStations[ i ][ 0 ]
what does 'i' mean?
Reply
#6

Sorry about that, I pasted your GasStations array without changing the tag.

Anyways, change to:
pawn Код:
new Float: GasStations[8][3]=
{
    {1942.0497,-1769.2963,13.6406}, // IW 1
    {1941.6536,-1776.3457,13.6406}, // IW 2
    {-1601.3220,-2708.2751,48.5391}, // highway towards Prickle Pine
    {1604.5129,-2712.7729,48.5335}, // highway towards Prickle Pine
    {-1607.7809,-2717.2312,48.5391}, // highway towards Prickle Pine
    {-1610.9799,-2722.2913,48.5391}, // highway towards Prickle Pine
    {-2247.2778,-2559.1624,31.9219}, // Diliamore
    {-2240.6899,-2562.2366,31.9219} // Dilliamore
};
since they're floats.

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
pawn Код:
GasStations[ i ][ 0 ]
what does 'i' mean?
It's from the for loop. We use it to loop through each row of GasStations.
Reply
#7

.
removed my post
Reply
#8

newbie scripter, "i" is from here
pawn Код:
for( new i; i != sizeof( GasStations ); i++ )
as kons. said it's loop, I still don't know exactly what is this but I'm learning, thanks for help you will get rep+ it's working.

EDIT: I gave to much rep last 24 hours, don't worry you 2 will get it as soon as I will be able to give it
Reply
#9

i know about loop,i just didn't see that piece of code. Thanks for rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)