User Tools

Site Tools


4rpl:commands:setunitwantsern

Differences

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

Link to this comparison view

Next revision
Previous revision
4rpl:commands:setunitwantsern [2024/05/23 07:59] – created Karsten754rpl:commands:setunitwantsern [2024/06/13 18:32] (current) – [Workaround for SetUnitWantsErn(<-uid 0)] Kalli
Line 6: Line 6:
 </WRAP> </WRAP>
 :!: Available in version 2.5 and later. :!: Available in version 2.5 and later.
-====== CommandName ======+====== SetUnitWantsERN ======
 SetUnitWantsERN(<-UID, <-wantsERN)   SetUnitWantsERN(<-UID, <-wantsERN)  
  
Line 17: Line 17:
 <code 4rpl> <code 4rpl>
 # need worked example # need worked example
 +</code>
 +
 +===== Workaround for SetUnitWantsErn(<-uid 0) =====
 +
 +<code 4rpl>
 +# A unit that has an ERN slotted and receives the 4rpl command to "not want an ERN", 
 +# will not actually unequip the ERN. As a workaround, it is possible to destroy the unit 
 +# and recreate it without the ERN. That's what this function is for.
 +
 +<-uid GetUnitWantsErn not <-uid GetUnitErnState AND if
 +  <-uid @freeErnFromUnit
 + endif
 +
 +:freeErnFromUnit
 +->UID
 +  <-UID getunitconstructingdata ev2 pop dup -1 eq if pop 999 endif ->buildResources
 +  <-UID getunittype <-UID getunitposition <-UID getunitsettings createunit dup ->newUID <-buildResources constructunit
 +  # Resources that are on the way to the old unit will be lost.
 +  
 +# Enable/disable the settings that you don't need by commenting them out.
 +  <-newUID <-UID
 +    # dup2 getunitmaxammo setunitmaxammo
 +    dup2 getunitammo setunitammo
 +    dup2 getunitcandestroy setunitcandestroy
 +    dup2 getunitselectable setunitselectable
 +    dup2 getunitenabled setunitenabled
 +    dup2 getunitarmed setunitarmed
 +    dup2 getunitsupplied setunitsupplied
 +    # dup2 getunithealrate setunithealrate
 +    # dup2 getunitmaxhealth setunitmaxhealth
 +    dup2 getunithealth setunithealth
 +    # dup2 getunitrange setunitrange
 +    dup2 getunitstuncount setunitstuncount
 +    dup2 getunitmovecell dup -1 neq if setunitmovecell else pop pop pop pop endif 
 +    pop pop
 +    
 +<-UID 1 1 1 destroyunit
 +
 </code> </code>
  
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
4rpl/commands/setunitwantsern.1716465594.txt.gz · Last modified: 2024/05/23 07:59 by Karsten75