AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] NPC's distance (https://forums.alliedmods.net/showthread.php?t=255118)

yan1255 01-10-2015 20:56

[HELP] NPC's distance
 
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.

RateX 01-11-2015 02:52

Re: [HELP] NPC's distance
 
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?

yan1255 01-11-2015 13:16

Re: [HELP] NPC's distance
 
Quote:

Originally Posted by RateX (Post 2247664)
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

RateX 01-11-2015 14:14

Re: [HELP] NPC's distance
 
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?

yan1255 01-11-2015 20:50

Re: [HELP] NPC's distance
 
Quote:

Originally Posted by RateX (Post 2247905)
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

RateX 01-11-2015 22:23

Re: [HELP] NPC's distance
 
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?

yan1255 01-11-2015 22:43

Re: [HELP] NPC's distance
 
Quote:

Originally Posted by RateX (Post 2248043)
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 :cry: 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...

RateX 01-11-2015 23:08

Re: [HELP] NPC's distance
 
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

yan1255 01-12-2015 00:42

Re: [HELP] NPC's distance
 
Quote:

Originally Posted by RateX (Post 2248049)
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 :D

I'll redo it and send it back :)


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

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