GetPlayerPos on NPC returns 0.0, 0.0, 0.0
#1

Hi guys,

I have a really big headache with this shit, please, help someone. Why does GetPlayerPos returns 0.0, 0.0, 0.0? What the hell?
pawn Код:
new
    Float:zPos[ 3 ]
;
for( new i; i < MAX_PLAYERS; i++ )
{
    if( !IsPlayerConnected( i ) || !IsPlayerNPC( i ) || !IsPlayerInAnyVehicle( i ) ) continue;
    print( "5" );
    GetPlayerPos( i, zPos[ 0 ], zPos[ 1 ], zPos[ 2 ] );
    printf( "6: %f, %f, %f", zPos[ 0 ], zPos[ 1 ], zPos[ 2 ] );
}
Thanks.
Reply
#2

pawn Код:
!IsPlayerNPC( i )
must be

pawn Код:
IsPlayerNPC( i )
Reply
#3

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
!IsPlayerNPC( i )
must be

pawn Код:
IsPlayerNPC( i )
Yoy don't understand me, I want to get NPC(not player) position. With your fix, the loop just ignores NPC.
Reply
#4

Dude " if(!IsPlayerNPC(i)) " that condition means if that player is NOT NPC, of course it doesn't work. you should do if(IsPlayerNPC(i)) as Lorenc_ said.
Reply
#5

If you're trying to get the position of an NPC that is in a vehicle, use GetVehiclePos instead.
Reply
#6

Damn, do you even know what "continue" do? Go read wiki...
pawn Код:
for( new i; i < 5; i++ )
{
    if( i == 3 ) continue;
    printf( "%d", i );
}
/*
result:
[14:38:50] 0
[14:38:50] 1
[14:38:50] 2
[14:38:50] 4
*/

Quote:
Originally Posted by YJIET
Посмотреть сообщение
If you're trying to get the position of an NPC that is in a vehicle, use GetVehiclePos instead.
Yes, it's in vehicle, but I tried!! It returns also 0.0, 0.0, 0.0
Reply
#7

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Damn, do you even know what "continue" do? Go read wiki...
pawn Код:
for( new i; i < 5; i++ )
{
    if( i == 3 ) continue;
    printf( "%d", i );
}
/*
result:
[14:38:50] 0
[14:38:50] 1
[14:38:50] 2
[14:38:50] 4
*/



Yes, it's in vehicle, but I tried!! It returns also 0.0, 0.0, 0.0
I will not go read wiki cause i know what continue do. It just skips a loop iteration.

So IsPlayerConnected checks if the player is connected, IsPlayerNPC checks if the player is a NPC, so !IsPlayerNPC checks if the player is NOT a NPC in your case you need to check if the player IS A NPC to get its position.

Edit:


Quote:
Originally Posted by YJIET
Посмотреть сообщение
If you're trying to get the position of an NPC that is in a vehicle, use GetVehiclePos instead.
GetVehiclePos gets the vehicle position not NPC position. Even the NPC is in the car GetPlayerPos should work.
Reply
#8

I changed it to
pawn Код:
if( IsPlayerConnected( i ) && IsPlayerNPC( i ) && IsPlayerInAnyVehicle( i ) )
{
    // ...
}
and it works perfectly, but I don't understand why. Continue skips the loop, so: if player is not connected - skip, if player is not NPC - skip, if player is not in any vehicle - skip. There shouldn't be any difference.
Reply
#9

because && means and, || means or. Try on this way.

pawn Код:
if( IsPlayerConnected( i ) && IsPlayerInAnyVehicle( i ) && !IsPlayerNPC( i ) ) continue;
Reply
#10

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
GetVehiclePos gets the vehicle position not NPC position.
No shit, Sherlock.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)