AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to set enitity's body (https://forums.alliedmods.net/showthread.php?t=133689)

Gadzislaw007 07-27-2010 20:52

How to set enitity's body
 
Code:

public set_mine(id) {
  new Float:StartOrigin[3]

 
  new PlayerOrigin[3]
  get_user_origin(id, PlayerOrigin, 1)

  StartOrigin[0] = float(PlayerOrigin[0])
  StartOrigin[1] = float(PlayerOrigin[1])
  StartOrigin[2] = float(PlayerOrigin[2]-60)

  new MineEnt = create_entity("info_target")
 
  entity_set_string(MineEnt, EV_SZ_classname, "landmine")
  entity_set_model(MineEnt, "models/w_landmine_zlw.mdl")
  entity_set_origin(MineEnt, StartOrigin)

  entity_set_int(MineEnt, EV_INT_solid, 2)
  entity_set_edict(MineEnt, EV_ENT_owner, id)


}

For some reasons it doesn't react for:

Code:

public pfn_touch(ptr, ptd) {
new ClassName[32]



if(!pev_valid(ptr))
        return FMRES_IGNORED;

if ((ptr > 0) && is_valid_ent(ptr))
    entity_get_string(ptr, EV_SZ_classname, ClassName, 31)
 

static toucherClass[32];
pev(ptd, pev_classname, toucherClass, 31);
if(equal(ClassName, "landmine") && equal(toucherClass, "player"))
{

client_print(0,print_chat,"Umba umba!")
remove_entity(ptr)

}

It seems like the mine has no body, I wonder how could I fix it? How can i make the mine "touchable"?

Emp` 07-28-2010 01:53

Re: How to set enitity's body
 
You need to set the size after setting the solid type.

Code:

/* Set entity bounds. */
native entity_set_size(index, const Float:mins[3], const Float:maxs[3]);


Gadzislaw007 07-28-2010 06:16

Re: How to set enitity's body
 
Code:

public set_mine(id) {
  new Float:StartOrigin[3]

 
  new PlayerOrigin[3]
  get_user_origin(id, PlayerOrigin, 1)

  StartOrigin[0] = float(PlayerOrigin[0])
  StartOrigin[1] = float(PlayerOrigin[1])
  StartOrigin[2] = float(PlayerOrigin[2]-53)

  new MineEnt = create_entity("info_target")
 
  entity_set_string(MineEnt, EV_SZ_classname, "landmine")
  entity_set_model(MineEnt, "models/w_landmine_zlw.mdl")
  entity_set_origin(MineEnt, StartOrigin)

  new Float:MinBox[3] = {-3.0, -3.0, -1.0}
  new Float:MaxBox[3] = {3.0, 3.0, 1.0}
  entity_set_size(MineEnt, MinBox, MaxBox);
  entity_set_vector(MineEnt, EV_VEC_mins, MinBox)
  entity_set_vector(MineEnt, EV_VEC_maxs, MaxBox)

  entity_set_int(MineEnt, EV_INT_solid, 2)
  entity_set_int(MineEnt, EV_INT_movetype, 5)
  entity_set_edict(MineEnt, EV_ENT_owner, id)

  new Float:Velocity[3]
  VelocityByAim(id, 0, Velocity)
  entity_set_vector(MineEnt, EV_VEC_velocity, Velocity)
 
 

 

}

Still doesn't working. :/

Hunter-Digital 07-28-2010 08:25

Re: How to set enitity's body
 
And you must spawn it.

Made a few adjustments:
Code:

public set_mine(id) {
  new Float:StartOrigin[3]
 
  new PlayerOrigin[3]
  get_user_origin(id, PlayerOrigin, 1)

  StartOrigin[0] = PlayerOrigin[0] + 0.0
  StartOrigin[1] = PlayerOrigin[1] + 0.0
  StartOrigin[2] = PlayerOrigin[2] - 53.0

  new MineEnt = create_entity("info_target")

  entity_set_string(MineEnt, EV_SZ_classname, "landmine")
  entity_set_model(MineEnt, "models/w_landmine_zlw.mdl")
  entity_set_edict(MineEnt, EV_ENT_owner, id)

  DispatchSpawn(MineEnt)

  entity_set_origin(MineEnt, StartOrigin)
  entity_set_size(MineEnt, Float:{-3.0, -3.0, -1.0}, Float:{3.0, 3.0, 1.0})
  entity_set_int(MineEnt, EV_INT_solid, 2) /* for readability, use the HLSDK defines... SOLID_* and MOVETYPE_*. */
  entity_set_int(MineEnt, EV_INT_movetype, 5)

  new Float:Velocity[3]
  VelocityByAim(id, 0, Velocity) /* what's the point of setting velocity 0 towards nothing ? */
  entity_set_vector(MineEnt, EV_VEC_velocity, Velocity)
}

Btw, be careful when spawning the mine while player is ducking.

You could easily make one variable, use entity_get_vector(id, EV_VEC_origin, fOrigin) and use -32 or -16 if player is ducking.

Gadzislaw007 07-28-2010 08:46

Re: How to set enitity's body
 
Thanks' for the 'ducking' tip.

Quote:

* what's the point of setting velocity 0 towards nothing ? */
Just forgot to erease that :D. So movetype is needen no more too?

Even so, code still isn't working properly. Nothing's happening when mine is touched by a player.

Hunter-Digital 07-28-2010 09:25

Re: How to set enitity's body
 
I see you use MOVETYPE_FLY... I recommend using MOVETYPE_TOSS or something, so that the mine falls on it's own.

How do you hook the touch, register_touch() ?
See that you don't mix up variables in the function, first it's the ent then the ent touching it and also, see that the classname in the register_touch() is "landmine".

Gadzislaw007 07-28-2010 09:28

Re: How to set enitity's body
 
Well, touch is working for other entities, like rpgrocket, or something (cause I have mixed rpg in it). Only landmine isn't working.

I realized that the condition of my pfn_touch is bad.
Code:

if(equal(ClassName, "landmine") && equal(toucherClass, "player"))
It just doesn't work.

If i set just:

Code:

if(equal(ClassName, "landmine"))
Mine explodes after it touches the ground. I want to make it explode after touching player, what's wrong in my method (first post)?

NiHiLaNTh 07-28-2010 11:22

Re: How to set enitity's body
 
Maybe try to use register_touch from engine
Code:

register_touch( your_mine_classname, "player", "fn_MineTouch" )

...

public fn_MineTouch( iMine, iOther )
{
    if( !pev_valid( iMine ) )
        return

    Explosion etc...
}


Gadzislaw007 07-28-2010 11:38

Re: How to set enitity's body
 
Still nothing :/.
I run and jump over the mine, but it's not going to explode anyway.

Gadzislaw007 07-28-2010 11:39

Re: How to set enitity's body
 
Still nothing :/.
I run and jump over the mine, but it's not going to explode anyway.


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

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