Raised This Month: $ Target: $400
 0% 

[HELP] NPC's distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yan1255
Senior Member
Join Date: Jul 2011
Old 01-10-2015 , 20:56   [HELP] NPC's distance
Reply With Quote #1

So I succedded in createing a few NPCs and saving them all in one map together now my new problem is like this...
When a player touches an NPC, he then get an a menu, the menu has a few options that aren't really relative.
Now this is where it gets a little difficult. When a player is too far from the NPC he can't use the menu.
I tried creating Arrays but i'm not so good at it...
The NPCs is created in a stock that will contain the NPCs origin from a file now i want to add the NPCs origin to an array now if there are more than one it will of course push the array and then when i just need to get the array i'll check for its origin within the array...

If i'm missunderstood please tell me I'll try to be more specific and well written.
__________________
yan1255 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-11-2015 , 02:52   Re: [HELP] NPC's distance
Reply With Quote #2

Sorry, I don't understand your problems. Are you saying you don't want player to use menu if he too far from your npc?
RateX is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-11-2015 , 13:16   Re: [HELP] NPC's distance
Reply With Quote #3

Quote:
Originally Posted by RateX View Post
Sorry, I don't understand your problems. Are you saying you don't want player to use menu if he too far from your npc?
Yes, but there are a few NPCs so I need to get all of their Origins so I can check if the player is close enough to the NPC
__________________
yan1255 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-11-2015 , 14:14   Re: [HELP] NPC's distance
Reply With Quote #4

Well, you can use find_ent_by_class with a while loop to find them, then store their origins.
Btw, what's the method you use to check whether the player is close enough?
RateX is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-11-2015 , 20:50   Re: [HELP] NPC's distance
Reply With Quote #5

Quote:
Originally Posted by RateX View Post
Well, you can use find_ent_by_class with a while loop to find them, then store their origins.
Btw, what's the method you use to check whether the player is close enough?
I already recieved their origin now I just want to store it via Arrays (ArrayGetArray and such)
I succedded in creating 3 Arrays
Example:
PHP Code:
    ArrayPushArrayg_aOriginsXiOrigin] );
    
ArrayPushArrayg_aOriginsYiOrigin] );
    
ArrayPushArrayg_aOriginsZiOrigin] );
    
    
ArraySetArrayg_aOriginsXArraySizeg_aOriginsX ) - 1iOrigin] );
    
ArraySetArrayg_aOriginsYArraySizeg_aOriginsY ) - 1iOrigin] );
    
ArraySetArrayg_aOriginsZArraySizeg_aOriginsZ ) - 1iOrigin] ); 
but I want to save them all in one Array not three.

I am using get_distance_f
__________________
yan1255 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-11-2015 , 22:23   Re: [HELP] NPC's distance
Reply With Quote #6

Quote:
but I want to save them all in one Array not three.
Then just do it like this:
PHP Code:
ArrayPushArrayg_NPCOriginiOrigin 
The above example will store all 3 values of iOrigin into the array. The same goes with ArraySetArray and ArrayGetArray.
Quote:
I am using get_distance_f
Why don't you use find_ent_in_sphere?
RateX is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-11-2015 , 22:43   Re: [HELP] NPC's distance
Reply With Quote #7

Quote:
Originally Posted by RateX View Post
Then just do it like this:
PHP Code:
ArrayPushArrayg_NPCOriginiOrigin 
The above example will store all 3 values of iOrigin into the array. The same goes with ArraySetArray and ArrayGetArray.

Why don't you use find_ent_in_sphere?
Never heard of it plus I don't know how to use it...
This is my stock:
PHP Code:
stock boolis_distance( const index )
{
    static 
FloatiOrigin];
    
    
pevindexpev_originiOrigin );
    
    for ( new 
iArraySizeg_aOriginsX ); i++ )
    {
        if ( 
get_distance_fiOriginGetOrigin) ) <= DISTANCE )
            return 
true;
    }
    
    return 
false;

Oh and btw I already tried your method of the Arrays it didn't worked...
__________________

Last edited by yan1255; 01-11-2015 at 22:44.
yan1255 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-11-2015 , 23:08   Re: [HELP] NPC's distance
Reply With Quote #8

Quote:
Never heard of it plus I don't know how to use it...
http://amxmodx.org/doc/index.html?pa..._in_sphere.htm
Use this with a while loop when the npcs think so you don't have to store their origins. This will become more useful if you want to make moving npcs.
Quote:
Oh and btw I already tried your method of the Arrays it didn't worked...
Show me what you've done

Last edited by RateX; 01-11-2015 at 23:09.
RateX is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-12-2015 , 00:42   Re: [HELP] NPC's distance
Reply With Quote #9

Quote:
Originally Posted by RateX View Post
http://amxmodx.org/doc/index.html?pa..._in_sphere.htm
Use this with a while loop when the npcs think so you don't have to store their origins. This will become more useful if you want to make moving npcs.

Show me what you've done
Using moving NPCs isn't an issue because for now I don't need it but thank you I'll make sure to use it if I'll ever try to make moving NPCs

I'll redo it and send it back
__________________
yan1255 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode