B Tutorial Module System Make weapon use the suitable ammo

Users who are viewing this thread

Use slot system + mission template triggers to check the ammo

firstly, define a slot for item called "slot_item_ammo"

secondly, you can check the players weapon in mission_templates
You can use agent_get_wield_item to get the player current using weapon, and then get the ammo item by using item_get_slot from this weapon, then check the player's inventory, if there is ammo but not suitable for this weapon, record them firstly and remove them, so that the player's ammo is 0 when player don't have the suitable ammo.
When player switch to another weapon, check the player inventory and check the items you removed, if there is ammo in player inventory, the ammo is right, if there is suitable ammo but removed in last checked, restore them.

player only have 4 weapon slots, so you will only record three unsuitable ammo item in one check (1 weapon + 3 ammos, there is no necessary to check the backpack, we can't use them directly in the game, we only check the weapon slots) under the worst situation which means player don't have suitable ammo for current wield weapon.

You can use a trooper to store these things, you can this like "trp_ammo_removed_array", once you remove unsuitable item, you need to add the ammo item id to this trooper like this:
Code:
troop_set_slot, trp_ammo_removed_array, :check_index, :ammo_item_id

You can use this to check the whole array:

Code:
try_for_range, ":check_index", 0, 4
troop_get_slot, ":removed_ammo_item_id", trp_ammo_removed_array, ":check_index"
... check the item whether suitable for current weapon ...
... if so, re-add this item to player weapon slot and set this slot to 0 which means clear this slot ...
try_end
 
Last edited:
Back
Top Bottom