Skip to content

Reusable Projectiles

szapp edited this page Oct 12, 2019 · 10 revisions

The feature Re-usable Projectiles (GFA_REUSE_PROJECTILES) will make shot projectiles (arrows and bolts) collectable and re-usable. Projectiles will remain in the world and may be picked up. Projectiles may also be collected from shot NPCs' inventories. For this feature, the number of projectiles available in the world need to be reduced, otherwise this will result in a balancing issue. You can find details and a solution to this issue here.

Once a projectile stops moving in the world or an NPC is positively hit, a "config function" is called (GFA_GetUsedProjectileInstance). In this function, based on the projectile, the shooter and the NPC that was hit (if any), you can define whether the projectile is removed, exchanged for another or kept as is. This is useful to control the amount of special ammunition (e.g. magical arrows should vanish on impact and should not be re-usable) or to implement a feature about used/broken projectiles that first need to be repaired.

The configuration of this feature is found in the file config/collectable.d.


GFA_GetUsedProjectileInstance

This function is called whenever a projectile (arrows and bolts) hits an NPC or stops in the world. There it can be decided whether to keep the projectile (in the world or in the inventory of the NPC), replace the it with a different instance (e.g. broken projectile that needs to be repaired) or to remove it.

The global variable GFA_ProjectilePtr will contain the pointer to the projectile (oCItem) in question for the duration of the function. Outside of the function this variable will always be reset to zero.

Ideas: exchange projectile for a 'used' or 'broken' one, require the possession of retrieval talent or tool, ...
There are a lot of examples given inside the function, they are all commented out and serve as inspiration of what is possible.

func int GFA_GetUsedProjectileInstance(int projectileInst, C_Npc shooter, C_Npc inventoryNpc)
projectileInst The instance of the projectile in question. Typically ItRw_Arrow or ItRw_Bolt (or ItAmArrow or ItAmBolt in Gothic 1).
shooter The NPC that shot the projectile.
inventoryNpc The NPC that was hit by the projectile (in whose inventory it will be put), or empty if it landed in the world.
returns New item instance. Return projectileInst to keep the projectile unchanged. When returning zero, the projectile is removed.