Raised This Month: $32 Target: $400
 8% 

Get distance between player & entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2011 , 16:10   Get distance between player & entity
Reply With Quote #1

Ok , i have this

Code:
public plugin_init() {     register_think("NiceArbol","Think_NiceArbol" );     maxplayers = get_maxplayers() } public Think_NiceArbol(Ent) {     new Float:PlayerOrigin[3]     for(new i = 1 ; i <= maxplayers; i++)     {         pev(i, pev_origin, PlayerOrigin)                     if( get_distance_f( g_Origin, PlayerOrigin ) <= 30.0)         {             client_print(i , print_chat, "[AMXX] Negro alejate del arbol")         }     } }

And this not working, dont print the message

What is the exactly problem with that ? , g_Origin is good , because , if that failed, the entity doesnt appear in the map
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-15-2011 , 16:15   Re: Get distance between player & entity
Reply With Quote #2

Are you sure your entity is thinking ?
__________________
Arkshine is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2011 , 16:23   Re: Get distance between player & entity
Reply With Quote #3

entity_set_string( Entity , EV_SZ_classname, "NiceArbol");
entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);
entity_set_model( Entity , "models/bigtree.mdl" );

I think , yes arkshine.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 02-15-2011 , 16:29   Re: Get distance between player & entity
Reply With Quote #4

Code:
public plugin_init()     register_think( "entity_classname", "EntityThink" ) Foo() // function where you make the ent     entity_set_float( Entity, EV_FL_nextthink, halflife_time() + 0.01 ) public EntityThink( ent )     entity_set_float( ent, EV_FL_nextthink, halflife_time() + 0.01 )
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-15-2011 , 16:35   Re: Get distance between player & entity
Reply With Quote #5

You need to tell the entity to start to think. It won't think until you say it.
__________________
Arkshine is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2011 , 16:36   Re: Get distance between player & entity
Reply With Quote #6

Code:
register_think("NiceArbol","Think_NiceArbol" ); public Think_NiceArbol(Ent) {     entity_set_float( Ent, EV_FL_nextthink, halflife_time() + 0.01 )     new Float:PlayerOrigin[3]         for(new i = 1 ; i <= maxplayers; i++)     {         pev(i, pev_origin, PlayerOrigin)                     if( get_distance_f( g_Origin, PlayerOrigin ) <= 30.0)         {             client_print(i , print_chat, "[AMXX] Negro alejate del arbol")         }     }         } public something() {         Entity = create_entity( "info_target" );     if( is_valid_ent(Entity) )     {         entity_set_string( Entity , EV_SZ_classname, "NiceArbol");         entity_set_float( Entity, EV_FL_nextthink, halflife_time() + 0.01 )         entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);         entity_set_model( Entity , "models/bigtree.mdl"  );         entity_set_size( Entity , Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 30.0 } );                        server_print("* Entidad creada en las coordenadas %0.2f %0.2f %0.2f", g_Origin[0], g_Origin[1], g_Origin[2] );         entity_set_origin( Entity, Origin );     } }

doen't work.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 02-15-2011 at 17:01.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 02-15-2011 , 17:17   Re: Get distance between player & entity
Reply With Quote #7

Quote:
Originally Posted by lucas_7_94 View Post
Code:
if( get_distance_f( g_Origin, PlayerOrigin ) <= 30.0)
Quote:
Originally Posted by lucas_7_94 View Post
Code:
entity_set_origin( Entity, Origin );
Perhaps you're checking the wrong variable for the origin of the entity. You use Origin to set the entity's original origin but you use g_Origin to check the distance.

Just a guess, it'd be nice to see the full code.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2011 , 17:21   Re: Get distance between player & entity
Reply With Quote #8

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <engine> #include <fakemeta> #define PLUGIN "Crear Entity" #define VERSION "1.0" #define AUTHOR "xPaw & Luqqas'" enum _:INFO {     MAP[20],     Float:X,     Float:Y,     Float:Z } new Entity new Float:g_Origin[3] new const DATE[] = { "models/bigtree.mdl" , "NiceArbol" } new const szInfo[2][INFO] = {     { "de_dust2", 1386.71, 2142.82 , 36.0 },     { "de_inferno", 0.20, 0.18, 0.24 } } new maxplayers public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_think( DATA[1],"Think_NiceArbol" );     register_clcmd("say /origins", "origins")     maxplayers = get_maxplayers() } public Think_NiceArbol(Ent) {     entity_set_float( Ent, EV_FL_nextthink, halflife_time() + 0.01 )     new Float:PlayerOrigin[3]         for(new i = 1 ; i <= maxplayers; i++)     {         pev(i, pev_origin, PlayerOrigin)                     if( get_distance_f( g_Origin, PlayerOrigin ) <= 30.0)         {             client_print(i , print_chat, "[AMXX] Negro alejate del arbol")         }     }         } public origins(id) {     new Get_Origins[3]     pev(id , pev_origin, Get_Origins)         client_print(id, print_chat, "%0.2f - %0.2f - %0.2f", Get_Origins[0], Get_Origins[1], Get_Origins[2])         return PLUGIN_HANDLED } public plugin_precache() {     precache_model(DATE[0])         static map[20]     get_mapname(map, charsmax(map))         for( new i = 0 ; i < 2 ; i++)     {         if( equal( map, szInfo[i][MAP] ))         {                         g_Origin[0] = szInfo[i][X]             g_Origin[1] = szInfo[i][Y]             g_Origin[2] = szInfo[i][Z]             CreateEntity( 0 , g_Origin)         }     } } CreateEntity( id,  Float:Origin[3] = { 0.00, 0.00 , 0.00 }) {     if( !id && Origin[0] == 0.00 && Origin[1] == 0.00 && Origin[2] == 0.00 )         return;             Entity = create_entity( "info_target" );      //assert is_valid_ent(Entity)     if( is_valid_ent(Entity) )     {         entity_set_string( Entity , EV_SZ_classname, DATE[1]);         entity_set_float( Entity, EV_FL_nextthink, halflife_time() + 0.01 )         entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);         entity_set_model( Entity , DATE[0] );         entity_set_size( Entity , Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 30.0 } );                        server_print("* Entidad creada en las coordenadas %0.2f %0.2f %0.2f", Origin[0], Origin[1], Origin[2] );         entity_set_origin( Entity, Origin );     }             return; }
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 02-15-2011 , 17:25   Re: Get distance between player & entity
Reply With Quote #9

You declared the constant as DATE[] when you should have declared it as DATA[][]. When changing this you must also change the variable name used at the bottom when setting the classname.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2011 , 17:37   Re: Get distance between player & entity
Reply With Quote #10

sorry , mistake when i change the post.

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <engine> #include <fakemeta> #define PLUGIN "Crear Entity" #define VERSION "1.0" #define AUTHOR "xPaw & Luqqas'" enum _:INFO {     MAP[20],     Float:X,     Float:Y,     Float:Z } new Entity new Float:g_Origin[3] new const DATE[] = "models/bigtree.mdl" new const szInfo[2][INFO] = {     { "de_dust2", 1386.71, 2142.82 , 36.0 },     { "de_inferno", 0.20, 0.18, 0.24 } } new maxplayers public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_think("NiceArbol","Think_NiceArbol" );     register_clcmd("say /origins", "origins")     maxplayers = get_maxplayers() } public Think_NiceArbol(Ent) {     entity_set_float( Ent, EV_FL_nextthink, halflife_time() + 0.01 )     new Float:PlayerOrigin[3]         for(new i = 1 ; i <= maxplayers; i++)     {         pev(i, pev_origin, PlayerOrigin)                     if( get_distance_f( g_Origin, PlayerOrigin ) <= 30.0)         {             client_print(i , print_chat, "[AMXX] Negro alejate del arbol")         }     }         } public origins(id) {     new Get_Origins[3]     pev(id , pev_origin, Get_Origins)         client_print(id, print_chat, "%0.2f - %0.2f - %0.2f", Get_Origins[0], Get_Origins[1], Get_Origins[2])         return PLUGIN_HANDLED } public plugin_precache() {     precache_model(DATE)         static map[20]     get_mapname(map, charsmax(map))         for( new i = 0 ; i < 2 ; i++)     {         if( equal( map, szInfo[i][MAP] ))         {                         g_Origin[0] = szInfo[i][X]             g_Origin[1] = szInfo[i][Y]             g_Origin[2] = szInfo[i][Z]             CreateEntity( 0 , g_Origin)         }     } } CreateEntity( id,  Float:Origin[3] = { 0.00, 0.00 , 0.00 }) {     if( !id && Origin[0] == 0.00 && Origin[1] == 0.00 && Origin[2] == 0.00 )         return;             Entity = create_entity( "info_target" );      //assert is_valid_ent(Entity)     if( is_valid_ent(Entity) )     {         entity_set_string( Entity , EV_SZ_classname, "NiceArbol");         entity_set_float( Entity, EV_FL_nextthink, halflife_time() + 0.01 )         entity_set_int( Entity , EV_INT_solid, SOLID_BBOX);         entity_set_model( Entity , DATE );         entity_set_size( Entity , Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 30.0 } );                                server_print("* Entidad creada en las coordenadas %0.2f %0.2f %0.2f", Origin[0], Origin[1], Origin[2] );         entity_set_origin( Entity, Origin );     }             return; }

Not working...
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
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 05:44.


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