WB Coding Can't tune a ti_on_weapon_attack trigger for weapon reloading

正在查看此主题的用户

Allas

Recruit
So I've set up a magic system that, if you become a mage in camp menu, allows you to open a spell book in battle that gives you spells - itcf_throw_stone throwing weapons (with 2 ammo, because the character unwields the weapon as soon as there is no ammo). And it works fine except for the reloading of the item: from my understanding when the character attacks with the spell, the ti_on_weapon_attack trigger fires before the ammo is used which leads to the attack not occurring at all if I don't have enough mana for yet another attack.

["lightning_bolt", "Lightning Bolt", [("empty",0),("light_beam",ixmesh_flying_ammo),("icon_lightning",ixmesh_inventory)], itp_type_thrown|itp_primary|itp_can_penetrate_shield|itp_crush_through|itp_extra_penetration, itcf_throw_stone, 23, weight(0.23)|difficulty(0)|spd_rtng(60)|shoot_speed(60)|thrust_damage(70,pierce)|max_ammo(100)|weapon_length(7, imodbits_thrown, [(ti_on_weapon_attack,[(play_sound,"snd_lightning"),(val_sub,"$mana","$curcost"),(try_begin),(get_player_agent_no,":agent"),(gt,"$mana","$curcost"),(agent_set_ammo,":agent","$curspell",2),(else_try),(agent_unequip_item,":agent","$curspell"),(try_end)])] ],

Is there a way to circumvent this issue while using a throwing weapon? I tried firearms but unless you reload them manually with a separate item (bullets) you can't use custom projectiles from what I've gathered. How else can I implement this?
 
解决方案
If you read through it, the first thing you do is subtract the cost, then check to see if you can use it. This will make you unable to use it since it will fail the check when it should have passed it.

You really should do the opposite. Subtract the cost last, after actually using it, and if you cannot, dequip the item.

Also, by using gt instead of ge you will make your player dequip the item when the values are equal and they should have been able to use it.

插入代码块:
["lightning_bolt", "Lightning Bolt", [("empty", 0), ("light_beam", ixmesh_flying_ammo), ("icon_lightning", ixmesh_inventory)], itp_type_thrown|itp_primary|itp_can_penetrate_shield|itp_crush_through|itp_extra_penetration, itcf_throw_stone, 23...
If you read through it, the first thing you do is subtract the cost, then check to see if you can use it. This will make you unable to use it since it will fail the check when it should have passed it.

You really should do the opposite. Subtract the cost last, after actually using it, and if you cannot, dequip the item.

Also, by using gt instead of ge you will make your player dequip the item when the values are equal and they should have been able to use it.

插入代码块:
["lightning_bolt", "Lightning Bolt", [("empty", 0), ("light_beam", ixmesh_flying_ammo), ("icon_lightning", ixmesh_inventory)], itp_type_thrown|itp_primary|itp_can_penetrate_shield|itp_crush_through|itp_extra_penetration, itcf_throw_stone, 23, weight(0.23)|difficulty(0)|spd_rtng(60)|shoot_speed(60)|thrust_damage(70, pierce)|max_ammo(100)|weapon_length(7, imodbits_thrown,
[(ti_on_weapon_attack, [
        (play_sound,"snd_lightning"),
        (get_player_agent_no,":agent"),
       
        (try_begin),
                (ge, "$mana", "$curcost"),
                (agent_set_ammo, ":agent", "$curspell", 2),
                (val_sub, "$mana", "$curcost"),
            (else_try),
                (agent_unequip_item,":agent","$curspell"),
        (try_end),
           
        ])]],

disclaimer: I have not checked to see the viability of this and haven't done a script in WB for a few months so I may be wrong.
 
点赞 0
解决方案
If you read through it, the first thing you do is subtract the cost, then check to see if you can use it. This will make you unable to use it since it will fail the check when it should have passed it.

You really should do the opposite. Subtract the cost last, after actually using it, and if you cannot, dequip the item.

Also, by using gt instead of ge you will make your player dequip the item when the values are equal and they should have been able to use it.

插入代码块:
["lightning_bolt", "Lightning Bolt", [("empty", 0), ("light_beam", ixmesh_flying_ammo), ("icon_lightning", ixmesh_inventory)], itp_type_thrown|itp_primary|itp_can_penetrate_shield|itp_crush_through|itp_extra_penetration, itcf_throw_stone, 23, weight(0.23)|difficulty(0)|spd_rtng(60)|shoot_speed(60)|thrust_damage(70, pierce)|max_ammo(100)|weapon_length(7, imodbits_thrown,
[(ti_on_weapon_attack, [
        (play_sound,"snd_lightning"),
        (get_player_agent_no,":agent"),
      
        (try_begin),
                (ge, "$mana", "$curcost"),
                (agent_set_ammo, ":agent", "$curspell", 2),
                (val_sub, "$mana", "$curcost"),
            (else_try),
                (agent_unequip_item,":agent","$curspell"),
        (try_end),
          
        ])]],

disclaimer: I have not checked to see the viability of this and haven't done a script in WB for a few months so I may be wrong.
Jesus Christ, turns out it's like the easiest, most obvious fix ever. Thanks:smile:
 
点赞 0
后退
顶部 底部