User Tools

Site Tools


4rpl:commands:setunitammoware

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:setunitammoware [2021/09/28 00:27] – [Description] Added a note about Porters. Sweepingdread604rpl:commands:setunitammoware [2023/12/07 19:08] (current) Grabz
Line 17: Line 17:
 <code 4rpl> <code 4rpl>
 SetUnitAmmoWare(self 1) SetUnitAmmoWare(self 1)
 +</code>
 +
 +===== Programming Notes =====
 +
 +Do not use SetUnitAmmoWare in the ''[[func_Awake|:Awake]]'' function. This causes all further units in the map to fail to load.
 +
 +When using SetUnitAmmoWare on a unit, it is advised to make sure that in the unit's blueprint (CMOD Settings), the initial Ammo Ware is set to Energy. Should it be set to one of the special wares (Liftic / Arg / Anticreeper), if the unit is later changed to use Energy, a reload of the game from a save file will cause the unit to request both Energy and the ware set in the unit's initial blueprint at the same time.
 +
 +Minimum reproducible example of the issue. Create a unit whose initial Ammo Ware is Liftic, and have the unit request ammo. Then give it this code.
 +<code 4rpl>
 +GetTimer0 1 eq if
 +   SetUnitAmmo(Self 0)
 +   SetUnitAmmoWare(Self 0)
 +endif
 +
 +:once
 +  300 SetTimer0
 +</code>
 +In the finalized map, wait out a little over 10 seconds until the unit swaps to Energy, then save and load. The unit now requests both Energy and Liftic.
 +
 +To avoid this issue, ensure the unit's initial Ammo Ware in CMOD Settings is Energy, then if the desired initial Ware is e.g. Liftic, that is later to be swapped to Energy, use ''[[func_GameLoaded|:GameLoaded]]'' as follows to set the unit to use Liftic from the start, while leaving it as Energy in the unit's CMOD Settings.
 +<code 4rpl>
 +:GameLoaded
 +   @init
 +:Once
 +   @init
 +:init
 +   once
 +      SetUnitAmmoWare(Self 3)
 +   endonce
 </code> </code>
  
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
4rpl/commands/setunitammoware.1632803225.txt.gz · Last modified: 2021/09/28 00:27 by Sweepingdread60