SA-MP Forums Archive
GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - 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)
+--- Thread: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 (/showthread.php?tid=354290)



GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - zgintasz - 26.06.2012

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.


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - Lorenc_ - 26.06.2012

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

pawn Код:
IsPlayerNPC( i )



Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - zgintasz - 26.06.2012

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.


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - TheArcher - 26.06.2012

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.


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - Stylock - 26.06.2012

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


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - zgintasz - 26.06.2012

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


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - TheArcher - 26.06.2012

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.


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - zgintasz - 26.06.2012

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.


Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - TheArcher - 26.06.2012

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

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



Re: GetPlayerPos on NPC returns 0.0, 0.0, 0.0 - Stylock - 26.06.2012

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