[CSS] Creating a usable, destroyable prop.

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

[CSS] Creating a usable, destroyable prop.

Postby Doldol » Wed Jun 10, 2015 5:40 am

I'm trying to create a usable and destroyable prop, I'm however seemingly unable to set the prop's health, and I cannot detect +use on the prop.

Syntax: Select all

MEDKIT_MODEL = Model("models/items/healthkit.mdl")

def spawn_medkit(origin):
medkit = Entity(create_entity("prop_physics_override"))
medkit.set_property_uchar("m_takedamage", 2)
medkit.set_key_value_string("model", MEDKIT_MODEL.path)
medkit.set_key_value_int("explodedamage", 7)
medkit.set_key_value_int("exploderadius", 250)
medkit.set_key_value_int("physdamagescale", 999)
medkit.set_property_int("m_iHealth", 25)
medkit.health = MEDKIT_HEALTH
medkit.max_health = MEDKIT_HEALTH
medkit.spawn_flags = 32+256
medkit.ltime = MEDKIT_LIFETIME
medkit.solid = 6
origin.z += 10
medkit.origin = origin
medkit.spawn()
medkit.set_property_int("m_iHealth", 25)
medkit.health = MEDKIT_HEALTH
medkit.max_health = MEDKIT_HEALTH



class CBaseEntity(CustomType, metaclass=manager):
#CBaseEntity::StartTouch(CBaseEntity*)
StartTouch = manager.virtual_function(
98 if PLATFORM == 'windows' else 99,
(DataType.POINTER,),
DataType.VOID
)


#CBaseEntity::Use(CBaseEntity*, CBaseEntity*, USE_TYPE, float)
Use = manager.virtual_function(
97 if PLATFORM == 'windows' else 98,
(DataType.POINTER, DataType.POINTER, DataType.POINTER, DataType.FLOAT,),
DataType.VOID
)


@property
def entity(self):
return Entity(index_from_pointer(self))


CBEntity = make_object(CBaseEntity, pointer_from_index(create_entity('info_target')))
@PreHook(CBEntity.StartTouch)
def preStartTouch(args):
entity = make_object(CBaseEntity, args[0])
toucher = make_object(CBaseEntity, args[1])
SayText2(message="Entity: {} {}, Toucher: {}".format(entity.entity.classname, entity.entity.health, toucher.entity.classname)).send()
# Health always reports 0 for the prop_physics


@PreHook(CBEntity.Use) # This doesn't seem to fire
def preUse(args):
entity = make_object(CBaseEntity, args[0])
toucher = make_object(CBaseEntity, args[1])
toucher2 = make_object(CBaseEntity, args[2])
SayText2(message="Entity: {} Toucher: {} Toucher2: {}".format(entity.entity.classname, toucher.entity.classname, toucher2.entity.classname)).send()
CBEntity.entity.remove()
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Jun 10, 2015 7:04 am

I could imagine that the info_target entity implements its own Use() method. So, your hook only gets called when you press +USE on an info_target entity. Try hooking it on prop_physics_override.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Wed Jun 10, 2015 4:26 pm

Ayuto wrote:I could imagine that the info_target entity implements its own Use() method. So, your hook only gets called when you press +USE on an info_target entity. Try hooking it on prop_physics_override.


Yup, you are right, that works now! Thanks for that!

Any clue on how to set the props's health?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Jun 10, 2015 4:41 pm

Use medkit.set_key_value_int('health', 25), it is hardcoded in the game files.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Jun 10, 2015 4:45 pm

Also, no need to hardcode values when no needed.

Syntax: Select all

from entities.constants import TakeDamage

medkit.set_property_uchar("m_takedamage", TakeDamage.YES)
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Jun 10, 2015 6:22 pm

I had problems when setting the health keyvalue/property on prop_dynamic_override in csgo (it didn't do anything), entity.call_input('SetHealth', 200) worked fine for me. Just in case you run into the same problem with a physics prop.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Wed Jun 10, 2015 7:26 pm

stonedegg wrote:I had problems when setting the health keyvalue/property on prop_dynamic_override in csgo (it didn't do anything), entity.call_input('SetHealth', 200) worked fine for me. Just in case you run into the same problem with a physics prop.


Yes, thanks! Using this after spawning the entity seems to be the only way I can set the prop's health.

However the prop seems to not take damage when getting shot (health stays at the original value).

From what little I know about mapping I believe I'd need to mess around with a func_breakable?
Or I've been thinking about trying to hook CBaseEntity::TakeDamage on it and see if that works.

I'll test it out and post back if I find something.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Jun 10, 2015 7:56 pm

The m_takedamage property works fine for me on a dynamic prop in csgo. The only difference is that I set it after I spawn it. Did you try that?
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Wed Jun 10, 2015 8:23 pm

stonedegg wrote:The m_takedamage property works fine for me on a dynamic prop in csgo. The only difference is that I set it after I spawn it. Did you try that?


Urh, of course that's it :) . It works now, thanks!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 41 guests