Raised This Month: $51 Target: $400
 12% 

[Help] Distance between player and object


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kiryxa
Junior Member
Join Date: Jan 2014
Old 02-03-2014 , 11:31   [Help] Distance between player and object
Reply With Quote #1

[en]
Hi!. I want to exist between player and object "Sandbags"(max radius, when the player puts sundbags).
PHP Code:
get_entity_distance(id,ent
not suitable, because the object did not exist yet.
How can this be done?

[ru]
Привет,я хочу,чтобы был максимальный радиус,куда можно поставить мешки с песком,
PHP Code:
get_entity_distance(id,ent
не подходит,так как обьект еще не существует-он работает-только тогда,когда он создался(то есть как я уже поставил сам мешок).Как можно реализовать проверку на этот радиус?

Code/Код:
PHP Code:
public Place_sandbags(id)
{
    if(
palletscout == get_pcvar_num(Max_Num_Pallets))
        return 
PLUGIN_HANDLED;
        
    
        
/* Не подходит
        new units = get_entity_distance(id,ent)
    
    if(units >= 100.0)
    {
        client_print(id,print_chat,"Нельзя больше")
        return PLUGIN_HANDLED;
    }
        */
    
    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"func_wall"));
    
    
set_pev(ent,pev_classname,"amxx_pallets");
            
    
engfunc(EngFunc_SetModel,entPALLET_MODEL);
    
    static 
Float:xorigin[3];
    
get_user_hitpoint(id,xorigin);
    
    if(
engfunc(EngFunc_PointContents,xorigin) == CONTENTS_SKY)
        return 
PLUGIN_HANDLED
    
    
static Float:p_mins[3], Float:p_maxs[3];
    
p_mins PALLET_MINS;
    
p_maxs PALLET_MAXS;
    
engfunc(EngFunc_SetSizeentp_minsp_maxs);
    
set_pev(entpev_minsp_mins);
    
set_pev(entpev_maxsp_maxs );
    
set_pev(entpev_absminp_mins);
    
set_pev(entpev_absmaxp_maxs );

    
engfunc(EngFunc_SetOriginentxorigin);

    
set_pev(ent,pev_solid,SOLID_BBOX)
    
set_pev(ent,pev_movetype,MOVETYPE_FLY)
    
    new 
Float:p_cvar_health get_pcvar_float(Health_Pallets);
    
    switch(
p_cvar_health)
    {
        case 
0.0 :
        {
            
set_pev(ent,pev_takedamage,DAMAGE_NO);
        }
        
        default :
        {
            
set_pev(ent,pev_health,p_cvar_health);
            
set_pev(ent,pev_takedamage,DAMAGE_YES);
        }
    }
    
    static 
Float:rvec[3];
    
pev(id,pev_v_angle,rvec);
    
    
rvec[0] = 0.0;
    
    
set_pev(ent,pev_angles,rvec);
    
    
fm_drop_to_floor(ent);
    
    
palletscout++;
    
    return 
PLUGIN_HANDLED;

Thanks!

Last edited by kiryxa; 02-03-2014 at 11:32.
kiryxa is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-03-2014 , 13:17   Re: [Help] Distance between player and object
Reply With Quote #2

Show get_user_hitpoints function or make it return the distance, and call it before create_entity, so you can, if distance is too short, abort the creation.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
kiryxa
Junior Member
Join Date: Jan 2014
Old 02-03-2014 , 13:25   Re: [Help] Distance between player and object
Reply With Quote #3

The stock "get_user_hitpoint":
PHP Code:
stock get_user_hitpoint(idFloat:hOrigin[3]) 
{
    if ( ! 
is_user_aliveid ))
        return 
0;
    
    new 
Float:fOrigin[3], Float:fvAngle[3], Float:fvOffset[3], Float:fvOrigin[3], Float:feOrigin[3];
    new 
Float:fTemp[3];
    
    
pev(idpev_originfOrigin);
    
pev(idpev_v_anglefvAngle);
    
pev(idpev_view_ofsfvOffset);
    
    
xs_vec_add(fOriginfvOffsetfvOrigin);
    
    
engfunc(EngFunc_AngleVectorsfvAnglefeOriginfTempfTemp);
    
    
xs_vec_mul_scalar(feOrigin9999.9feOrigin);
    
xs_vec_add(fvOriginfeOriginfeOrigin);
    
    
engfunc(EngFunc_TraceLinefvOriginfeOrigin0id);
    
global_get(glb_trace_endposhOrigin);
    
    return 
1;

kiryxa is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-03-2014 , 16:42   Re: [Help] Distance between player and object
Reply With Quote #4

Try :

PHP Code:
get_user_hitpoint(idFloat:hOrigin[3], Float:fDistance)  

    if ( ! 
is_user_aliveid )) 
        return 
0
     
    new 
Float:fOrigin[3], Float:feOrigin[3]; 

    
pev(idpev_originfOrigin);
    
velocity_by_aim(id9999feOrigin);

    
xs_vec_add(fOriginfeOriginfeOrigin); 

    
trace_line(idfOriginfeOriginhOrigin);

    
fDistance get_distance_f(fOriginhOrigin);

    return 
1

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
kiryxa
Junior Member
Join Date: Jan 2014
Old 02-04-2014 , 01:29   Re: [Help] Distance between player and object
Reply With Quote #5

ConnorMcLeod
Ok, i try your code,but where i have to do the check of distance?
PHP Code:
    static Float:xorigin[3];
    new 
Float:fDistance;
    
get_user_hitpoint(id,xoriginfDistance);
    
    if(
engfunc(EngFunc_PointContents,xorigin) == CONTENTS_SKY)
        return 
PLUGIN_HANDLED
        
    
if (fDistance 50.0)
        return 
PLUGIN_HANDLED 
It does not work.How to do it correctly?
kiryxa is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-04-2014 , 01:58   Re: [Help] Distance between player and object
Reply With Quote #6

Try to print the distance in chat so you can figure out if result is relevant or not.
50 is really short, a player is 64.

May be you want :

PHP Code:
    get_user_hitpoint(id,xoriginfDistance); 
    
client_print(idprint_chat"Distance is %.1 units"fDistance);
    if (
fDistance 50.0// < (you did >)
        
return PLUGIN_HANDLED;

    if(
engfunc(EngFunc_PointContents,xorigin) == CONTENTS_SKY
        return 
PLUGIN_HANDLED
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
kiryxa
Junior Member
Join Date: Jan 2014
Old 02-04-2014 , 02:39   Re: [Help] Distance between player and object
Reply With Quote #7

Okey,So what I want on screen:



The check does not work,bags puts all the same where x-->bag:
PHP Code:
public Place_sandbags(id)
{
    if(
palletscout == get_pcvar_num(Max_Num_Pallets))
        return 
PLUGIN_HANDLED;
    
    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"func_wall"));
    
    
set_pev(ent,pev_classname,"amxx_pallets");
            
    
engfunc(EngFunc_SetModel,entPALLET_MODEL);
    
    static 
Float:xorigin[3];
    new 
Float:fDistance;
    
get_user_hitpoint(id,xoriginfDistance);
    
    if (
fDistance 300.0)
    {
        
client_print(idprint_chat"Distance is %.1f units"fDistance); 
        return 
PLUGIN_HANDLED;
    }
    
    if(
engfunc(EngFunc_PointContents,xorigin) == CONTENTS_SKY)
        return 
PLUGIN_HANDLED
    
        
// other code

Also, the compiler says:
D:\Server\ZP4.3\cstrike\addons\amxmodx\script ing\zp_test.sma(236) : warning 2 04: symbol is assigned a value that is never used: "fDistance"
in this code:
PHP Code:
get_user_hitpoint(idFloat:hOrigin[3], Float:fDistance)   
{  
    if ( ! 
is_user_aliveid ))  
        return 
0;  
      
    new 
Float:fOrigin[3], Float:feOrigin[3];  

    
pev(idpev_originfOrigin); 
    
velocity_by_aim(id9999feOrigin); 

    
xs_vec_add(fOriginfeOriginfeOrigin);  

    
trace_line(idfOriginfeOriginhOrigin); 

    
fDistance get_distance_f(fOriginhOrigin); 

    return 
1;  


Last edited by kiryxa; 02-04-2014 at 02:43.
kiryxa is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-04-2014 , 15:35   Re: [Help] Distance between player and object
Reply With Quote #8

Oh, add '&' in front of 'Float:fDistance'

-> get_user_hitpoint(id, Float:hOrigin[3], &Float:fDistance)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-04-2014 at 15:35.
ConnorMcLeod is offline
avril-lavigne
Banned
Join Date: Apr 2009
Old 02-04-2014 , 16:26   Re: [Help] Distance between player and object
Reply With Quote #9

distance between =

static iTarget, iBody
get_user_aiming(id, iTarget, iBody)

or


get_user_aiming(id, iTarget, iBody, 900) // 900 units of max distance

// 900 юнитов максимальное расстояние на котором будет действовать условие.

iTarget - enemy or something .
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc

Last edited by avril-lavigne; 02-04-2014 at 16:28.
avril-lavigne is offline
kiryxa
Junior Member
Join Date: Jan 2014
Old 02-05-2014 , 00:36   Re: [Help] Distance between player and object
Reply With Quote #10

Thanks a lot,but:
PHP Code:
stock get_user_hitpoint(idFloat:hOrigin[3]) 
{
    if ( ! 
is_user_aliveid ))
        return 
0;
    
    new 
Float:fOrigin[3], Float:fvAngle[3], Float:fvOffset[3], Float:fvOrigin[3], Float:feOrigin[3];
    new 
Float:fTemp[3];
    
    
pev(idpev_originfOrigin);
    
pev(idpev_v_anglefvAngle);
    
pev(idpev_view_ofsfvOffset);
    
    
xs_vec_add(fOriginfvOffsetfvOrigin);
    
    
engfunc(EngFunc_AngleVectorsfvAnglefeOriginfTempfTemp);
    
    
xs_vec_mul_scalar(feOrigin9999.9feOrigin);
    
xs_vec_add(fvOriginfeOriginfeOrigin);
    
    
engfunc(EngFunc_TraceLinefvOriginfeOrigin0id);
    
global_get(glb_trace_endposhOrigin);
    
    return 
1;

PHP Code:
xs_vec_mul_scalar(feOrigin9999.9feOrigin); 
where 9999.9-this is max radius,i did not know about this.

Last edited by kiryxa; 02-05-2014 at 00:38.
kiryxa 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 04:26.


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