User Tools

Site Tools


cw4:4rpl_tools

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
cw4:4rpl_tools [2024/03/16 19:53] – [Automated Tower Grid Building] Added a statement for clarity of how to use it. LiteralNoobcw4:4rpl_tools [2024/09/10 17:41] (current) – Updated manipulateUnitPosition and added SetTerrainHigherThan20 Vertu
Line 2212: Line 2212:
 #By Vertu #By Vertu
  
-$HEIGHT:100.0 #Float or Integer +$HEIGHT:3000.0 #Float or Integer 
-$RAND_MAX:8   #Integer +$RAND_MAX:15 #Integer 
-$RAND_MIN:-8  #Integer+$RAND_MIN:25 #Integer 
 +$STEP:1.0 #--How far something moves per incrament when using the script. 
 +$$BUFFER:2
  
-if(GetKey("RightArrow" false))+if(<-inputDelay gt0) <-inputDelay 1 - ->inputDelay endif 
 + 
 +if(GetKey("RightArrow" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x + <-unitPosPre.y <-unitPosPre.z))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-STEP + <-unitPosPre.y <-unitPosPre.z))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2226: Line 2231:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
-if(GetKey("LeftArrow" false))+if(GetKey("LeftArrow" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x - <-unitPosPre.y <-unitPosPre.z))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-STEP - <-unitPosPre.y <-unitPosPre.z))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2240: Line 2246:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
-if(GetKey("UpArrow" false))+if(GetKey("UpArrow" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-unitPosPre.z +))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-unitPosPre.z <-STEP +))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2254: Line 2261:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
-if(GetKey("DownArrow" false))+if(GetKey("DownArrow" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-unitPosPre.z -))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-unitPosPre.z <-STEP -))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2268: Line 2276:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
-if(GetKey("PageUp" false))+if(GetKey("PageUp" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y + <-unitPosPre.z))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-STEP + <-unitPosPre.z))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2282: Line 2291:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
-if(GetKey("PageDown" false))+if(GetKey("PageDown" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
  GetUnitPosition(<-units[I]) ->unitPosPre  GetUnitPosition(<-units[I]) ->unitPosPre
- SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y - <-unitPosPre.z))+ SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-unitPosPre.y <-STEP - <-unitPosPre.z))
  GetTerrain(GetUnitCell(<-units[I])) ->terrainH  GetTerrain(GetUnitCell(<-units[I])) ->terrainH
  GetUnitPosition(<-units[I]) ->unitPos  GetUnitPosition(<-units[I]) ->unitPos
Line 2296: Line 2306:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
 if(GetKey("Backspace" false)) if(GetKey("Backspace" false))
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
Line 2310: Line 2321:
  SetUnitOccupiesLand(<-units[I] true)  SetUnitOccupiesLand(<-units[I] true)
  else  else
- if(<-unitPos.y lt(<-terrainH)) SetUnitOccupiesLand(<-units[I] false) endif+ if(<-unitPos.y lt(<-terrainH)) endif #SetUnitOccupiesLand(<-units[I] false) endif
  endif  endif
  loop  loop
 endif endif
  
-if(GetKey("Slash" false))+if(GetKey("Slash" false) <-inputDelay eq0 &&) 
 + true ->doesBuffer
  GetSelectedUnits ->units  GetSelectedUnits ->units
  do(GetListCount(<-units) 0)  do(GetListCount(<-units) 0)
Line 2322: Line 2334:
  SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-randHeight <-unitPosPre.z))  SetUnitPosition(<-units[I] V3(<-unitPosPre.x <-randHeight <-unitPosPre.z))
  loop  loop
 +endif
 +
 +if(<-doesBuffer)
 + false ->doesBuffer
 + <-BUFFER ->inputDelay
 endif endif
  
Line 2923: Line 2940:
  
 The snapping tool makes use of a unit for highlighting the nearest buildable cell, so it's a cpack instead of a script : [[https://knucklecracker.com/wiki/doku.php?id=cw4:cpack:docs:e58ef3f2-1468-42fa-ac84-c3561ddd9452|Kalli - SnappingTool]] The snapping tool makes use of a unit for highlighting the nearest buildable cell, so it's a cpack instead of a script : [[https://knucklecracker.com/wiki/doku.php?id=cw4:cpack:docs:e58ef3f2-1468-42fa-ac84-c3561ddd9452|Kalli - SnappingTool]]
 +
 +----
 +
 +===== Make Units Unselectable =====
 +
 +You can make friendly/enemy/all units (un)selectable and/or (un)destroyable with this script.
 +
 +The $ variables are now set so that friendly (=human) units are set unselectable and undestroyable, so that it's ready to use in a pac map. The variables are either 0 or 1.
 +
 +Enemy (=creeper) units are always undestroyable. Changing this setting with 4rpl does nothing, but also doesn't break anything.
 +
 +The script can be used from the console, or be added as a global script to a cpack. If used as a global script, then the script must run while paused. It will only apply to units that exist at map start.
 +
 +<hidden click here for source code>
 +
 +<code 4rpl MakeUnitsUnselectable.4rpl>
 +
 +# MakeUnitsUnselectable
 +
 +# The script can be used from the console, or be added as a global script to a cpack.
 +# If used as a global script, then the script must run while paused. It will only apply to units that exist at map start.
 +
 +$applyToFriendlyUnits:1
 +
 +$applyToEnemyUnits:0
 +
 +$applyToAllUnits:0
 +
 +$makeUnitsSelectable:0
 +$makeUnitsDestroyable:0
 +
 +:once
 + GetMapSize 2 div ->midPointZ 2 div ->midPointX 
 +
 + <-midPointX 0 <-midpointZ v3 ->pos
 +
 + <-applyToAllUnits <-applyToFriendlyUnits <-applyToEnemyUnits and or if
 + 0 ->enemyState
 + else
 + <-applyToFriendlyUnits if 2 else <-applyToEnemyUnits endif ->enemyState
 + endif
 +
 + # The position is the center of the map. The max possible range for units within the map boundaries is (512/2^2 + 128/2^2)^0.5 +1 = 265. To also catch units that have wandered just outside the map boundaries, I chose range 300.
 + "" <-pos 300 0 0 0 <-enemyState 0 0 getunits ->unitList
 +
 + <-unitList 0 do 
 + <-unitList[i] <-makeUnitsSelectable SetUnitSelectable
 + <-unitList[i] <-makeUnitsDestroyable SetUnitCanDestroy
 + loop
 +
 +</code>
 +
 +</hidden>
 +
 +----
 +
 +===== Set terrain higher than 20 =====
 +A console script that lets you place terrain higher than 20. Details below.
 +<hidden click here for source code>
 +Notes about terrain higher than 20:\\
 +  * There is a limit to how high terrain can be before it causes an overflow and crashes your game should the script try to make that terrain height. I have limited the script to a height of 100 to be safe, I have not tested when this crash occurs but I do know it does. Terrain higher than 100 gets excessive anyways.
 +  * The game was not built to account for terrain higher than 20, this means Creeper will not render at the top of the terrain but at a height of 20 (the maximum terrain height) should Creeper be on terrain higher than 20.
 +  * The build system does not detect terrain higher than 20, you have to point your mouse down as if it was a height of 20 in order to place units on that terrain. Obviously the best workaround to this is using top-down view.
 +  * The game doesn't fully render terrain higher than 20 graphically. The cliffs of terrain higher than 20 will have stripes of black and after a height of 50, the final black stripe will continue to "infinity" height.
 +  * The surfaces of various terrain higher than 20 will have **<fc #ff0000>BLINDING</fc>** bloom effects. If the surface isn't void-black, it is best you do not use that height as with bloom enabled, it **is** blinding. The effect is typically encountered when the terrain is at a height within a black stripe with the exception of height higher than 50.
 +  * I recommend only using terrain higher than 20 for visual effect rather than gameplay due to Creeper not rendering at the surface of the terrain. Best to make it impossible for Creeper to reach such areas.
 +<code 4rpl SetTerrainAbove20.4rpl>
 +# SetTerrainAbove20
 +#By Vertu.
 +
 +$HEIGHT:42 #--Integer, incramented by +-1 via hotkeys.
 +
 +$$BUFFER:2
 +
 +if(<-inputDelay gt0) <-inputDelay 1 - ->inputDelay endif
 +
 +if(<-phase2 ! GetKeyDown("Space" true) &&)
 + GetPointerTerrainCoords ->y1 ->x1
 + if(IsV2InMap(V2(<-x1 <-y1)))
 + true ->phase2
 + Trace4("Lower Coord: " <-x1 " " <-y1)
 + else
 + Trace("That wasn't in the map. Try again.")
 + endif
 +else
 +if(<-phase2 GetKeyDown("Space" true) &&)
 + GetPointerTerrainCoords ->y2 ->x2
 + if(IsV2InMap(V2(<-x2 <-y2)))
 + false ->phase2
 + Trace4("Upper Coord: " <-x2 " " <-y2)
 + else
 + Trace("That wasn't in the map. Try again.")
 + endif
 +endif
 +endif
 +if(GetKeyDown("Backspace" true) <-x1 neq(-1) && <-x2 neq(-1) &&)
 + <-y2 1 add <-y1 do
 +    <-x2 1 add <-x1 do
 + while I J GetTerrain <-setHeight neq repeat
 + SetTerrainInRange(I J <-setHeight dup 0 false 1)
 + endwhile
 +    loop
 + loop
 + ClearTraceLog
 + Trace4(<-keyBindText "
 +Height set to " <-setHeight ".")
 + EditAddUndo(0)
 +endif
 +
 +if(GetKeyDown("Keypad0" true))
 + ClearTraceLog
 + Trace4(<-keyBindText "
 +Height set to " <-setHeight ".")
 + GetPointerTerrainCoords ->posZ ->posX
 + FloodFillTerrain(<-posX <-posZ GetTerrain(<-posX <-posZ) GetTerrain(<-posX <-posZ) 1 + 10,000,000) ->cells
 + do(GetListCount(<-cells) 0)
 + EV2(<-cells[I]) ->cellyZ ->cellyX
 + while <-cellyX <-cellyZ GetTerrain <-setHeight neq repeat
 + SetTerrainInRange(<-cellyX <-cellyZ <-setHeight dup 0 false 1)
 + endwhile
 + loop
 + Trace3("Completed flood fill to height" <-setHeight ".")
 + EditAddUndo(0)
 +endif
 +
 +if(GetKey("PageUp" false) <-setHeight lt(100) && <-inputDelay eq0 &&)
 + <-setHeight 1 + ->setHeight
 + ClearTraceLog
 + Trace4(<-keyBindText "
 +Height set to " <-setHeight ".")
 + <-BUFFER ->inputDelay
 +endif
 +if(GetKey("PageDown" false) <-setHeight gt0 && <-inputDelay eq0 &&)
 + <-setHeight 1 - ->setHeight
 + ClearTraceLog
 + Trace4(<-keyBindText "
 +Height set to " <-setHeight ".")
 + <-BUFFER ->inputDelay
 +endif
 +
 +:Once
 + <-HEIGHT ->setHeight
 + "Key binds:
 +SpaceBar to specify coordinates, then backspace to set terrain as a rectangle.
 +
 +PageUp and PageDown to increase and decrease set terrain height.
 +
 +Pressing Keypad0 will conduct a flood-fill to set terrain to specified height." ->keyBindText
 + Trace(<-keyBindText)
 + Trace3("Height set to " <-HEIGHT ".")
 + -1 ->x1
 + -1 ->x2
 + -1 ->y1
 + -1 ->y2
 +</code>
 +
 +</hidden>
  
 ---- ----
Line 3289: Line 3463:
 <fs large>**Applying to a V3:**</fs> <fs large>**Applying to a V3:**</fs>
 <code> <code>
-V3(cos(RandFloat 2.0 / RandInt(0 7) +) <-RADIUS * <-cellX + <-Y_COORDINANT RandInt(-15 16) + sin(RandFloat 2.0 / RandInt(0 7) +) <-RADIUS * <-cellZ +) ->position+V3(cos(RandFloat RandInt(0 7) +) <-RADIUS * <-cellX + <-Y_COORDINANT RandInt(-15 16) + sin(RandFloat RandInt(0 7) +) <-RADIUS * <-cellZ +) ->position
 </code> </code>
 <fs large>**Applying to a V2:**</fs> <fs large>**Applying to a V2:**</fs>
 <code> <code>
-V2(cos(RandFloat 2.0 / RandInt(0 7) +) <-RADIUS * <-cellX + sin(RandFloat 2.0 / RandInt(0 7) +) <-RADIUS * <-cellZ +) ->cellLocation+V2(cos(RandFloat RandInt(0 7) +) <-RADIUS * <-cellX + sin(RandFloat RandInt(0 7) +) <-RADIUS * <-cellZ +) ->cellLocation
 </code> </code>
  
Line 3313: Line 3487:
  if(GetEditMode !)  if(GetEditMode !)
  GetUnitPosition(self) ->placementPos  GetUnitPosition(self) ->placementPos
- SetUnitPosition(self V3(cos(RandFloat 2.0 / RandInt(0 7) +) 45 * <-placementPos.x + <-FALL_HEIGHT RandInt(-15 16) + sin(RandFloat 2.0 / RandInt(0 7) +) 45 * <-placementPos.z +))+ SetUnitPosition(self V3(cos(RandFloat RandInt(0 7) +) 45 * <-placementPos.x + <-FALL_HEIGHT RandInt(-15 16) + sin(RandFloat RandInt(0 7) +) 45 * <-placementPos.z +))
  endif  endif
 </code> </code>
  
 +</hidden>
 +
 +
 +----
 +===== Random X-Z position along the circumference of a circle =====
 +
 +<hidden click here for source code>
 +This is a simple piece of trigonometry that is able to pick a random position along the circumference of a circle on the X-Z plain with a definable radius. This is useful in the event you wish to introduce circles into your 4RPL code's behavior.\\
 +Uses [[4rpl:commands:randint|RandInt]] and [[4rpl:commands:randfloat|RandFloat]] to determine the angle on the unit circle where the position along the circumference is.\\
 +Note: Floats will work for the radius.\\
 +\\
 +<code>
 +RandFloat RandInt(0 7) + ->angle
 +V3(cos(<-angle) <-RADIUS * <-cellX + <-Y_COORDINANT RandInt(-15 16) + sin(<-angle) <-RADIUS * <-cellZ +) ->position
 +</code>
 </hidden> </hidden>
  
cw4/4rpl_tools.1710633227.txt.gz · Last modified: 2024/03/16 19:53 by LiteralNoob