Hi!
I'm currently developing an inventory sytem to a sourcesdk 2013 mod. Without going in to more about that, I have a more specific problem that is related to one specific item: A key.
Note: I'm very familiat with the source-engine, but not so much the code base (learning about its syntax/"rules" as I go).
It is a generic item that is to be configured to work properly in Hammer, by the level designer. The key (for now) takes two keyfields:
- Target to unlock : FIELD_STRING
- Discard on use : FIELD_BOOLEAN
The first one is the issue at hand (more or less).
In my "OnUse" handler, I need to be able to check if the key is being used on an entity with that name, as well as checking that the player is facing in the right direction and is pressing use in a given radius of that door/entity.
So, I have two psuedo-solutions I'd prefer:
- Handle all the unlocking and tracing logic in "OnUse"
- Use a custom trigger entity (brush entity) that the level designer creates paralell to the door entity that takes an input and searches the players' inventory for the matching entity.
If that is the case, the trigger will have to know about the door entity, the name of the key and then it will have to match it all up and work out the logic.
For any experienced SourceSDK programmer: Which is the best (or are there better solutions)?
EDIT: I encountered another issue that needs solving
So, obvious as it was, I loose properties that has been set, in Hammer editor, to an entity when I remove the entity from the world on-pickup.
I.e: I create an "item_key" in hammer. I set its "unlock target" to "door_03". It's all well and good when it spawns. When I pick it up in-game, my code calls on "UTIL_Remove" to remove the entity from the world. However; if I discard it from the inventory to spawn it back to the world, these properties are lost (my code simply creates the same type of entity and spawns it). This was quite obvious when I first encountered such an instance.
So my question is: Are there any standard functions/ways-of-doing-things when an entity and the properties set in hammer, needs to be saved?
Best regards,
Oyvind