User Tools

Site Tools


crpl:crpltutorial:code_examples

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
Last revisionBoth sides next revision
crpl:crpltutorial:code_examples [2015/04/13 09:56] Karsten75crpl:crpltutorial:code_examples [2022/01/09 00:42] – added Make a non-moving unit only buildable in void Grabz
Line 1: Line 1:
  
-<html><!--Comments visible to editors only can be placed in HTML comments --></html> 
 <-[[cw3:creeper_world_3|CW3 Home]]<- [[crpl:start|CRPL Home]] <-[[cw3:creeper_world_3|CW3 Home]]<- [[crpl:start|CRPL Home]]
  
Line 965: Line 964:
 </code> </code>
 <sub>Contributed by Telanir</sub> <sub>Contributed by Telanir</sub>
 +
 +
 +===CRPL generating CRPL===
 +This CRPL will generate CRPL with custom program (if it is in the map scripts)
 +<code>
 +CreateUnit("CRPLCORE" CurrentX CurrentY) ->unit
 +AddScriptToUnit(<-unit "[Programname].crpl")
 +</code>
 +<sub> Stolen from Teknotiss(who took it from virgil), where pyramids make golems. I simply changed golem to unit. Added by cpaca, known as Karma's coming on map search </sub>
 +
 +===== Make a non-moving unit only buildable in void =====
 +This code will make it so a unit can be only built in void and not on terrain. It only works properly for stationary units.
 +
 +  * This is a global script, so you have to add it in Package Manager -> Global Control -> Pre Update.
 +  * **Tick the Run when paused box**, then in one of the UNITGUID fields paste the GUID of one or more void only units.
 +  * The script does not work in editor, you can finalize the map, back out then open the finalized map and test there if it works.
 +  * The unit must have the "Can build/land anywhere" toggle enabled. 
 +
 +<code>
 +$UnitGUID0:""
 +$UnitGUID1:""
 +$UnitGUID2:""
 +$UnitGUID3:""
 +$UnitGUID4:""
 +
 +GetBuildUnit ->curBuildUnit
 +
 +#Only do something if state has changed
 +<-curBuildUnit <-lastBuildUnit neq if
 + FALSE ->buildUnitSelected
 + FALSE ->buildUnitDeselected
 +
 + 5 0 do
 + "UnitGUID" I concat <-! ->val
 + <-val StringLength gt0 <-val <-curBuildUnit eq and if
 + TRUE ->buildUnitSelected
 + endif
 + <-val StringLength gt0 <-val <-lastBuildUnit eq and if
 + TRUE ->buildUnitDeselected
 + endif
 + loop
 +
 + #If a void only unit was selected, and the last selection was not a void only unit
 + <-buildUnitSelected <-buildUnitDeselected not and if
 + FALSE SetAllLegalUnitCells
 + <-LEGAL_CELLS TRUE SetLegalUnitCells
 + TRUE UseLegalUnitCells
 + #If a non void only unit was selected, and the last selection was a void only unit
 + else <-buildUnitSelected not <-buildUnitDeselected and if
 + FALSE SetAllLegalUnitCells
 + FALSE UseLegalUnitCells
 + endif endif
 +endif
 +
 +#Save current state
 +<-curBuildUnit ->lastBuildUnit
 +
 +#Initialize
 +:once
 + GetBuildUnit ->lastBuildUnit
 + @RebuildVoidCellsList
 +
 +:RebuildVoidCellsList
 + #Build list of void cells
 + CreateList ->LEGAL_CELLS
 + GetMapSize ->sizeZ ->sizeX
 + <-sizeZ 0 do
 + <-sizeX 0 do
 + #If terrain is void, add coordinates to list
 + I J GetTerrain eq0 if
 + <-LEGAL_CELLS I J V2 AppendToList
 + endif
 + loop
 + loop
 +</code>
crpl/crpltutorial/code_examples.txt · Last modified: 2022/01/11 03:00 by Karsten75