Editing Quick Stat Tweaks

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 22: Line 22:
  
 
== Simple Example ==
 
== Simple Example ==
In this example we make Glaive faster and cheaper.
+
In this example we make Glaive faster and healthier.
  
 
Start with an empty Lua table.
 
Start with an empty Lua table.
Line 31: Line 31:
 
     cloakraid = {},
 
     cloakraid = {},
 
}</syntaxhighlight>
 
}</syntaxhighlight>
The [https://springrts.com/wiki/Gamedev:UnitDefs SpringRTS wiki page on unitdefs] says that a unit's cost is 'metalCost' and its speed is just 'speed'. [https://github.com/ZeroK-RTS/Zero-K/blob/master/units/cloakraid.lua The Glaive file] shows us the current value of these parameters, as well as their position in the structure of a unitdef. We can change these values like so:
+
The [https://springrts.com/wiki/Gamedev:UnitDefs SpringRTS wiki page on unitdefs] says that a unit's health is 'maxDamage' and its speed is 'maxVelocity'. [https://github.com/ZeroK-RTS/Zero-K/blob/master/units/cloakraid.lua The Glaive file] shows us the current value of these parameters, as well as their position in the structure of a unitdef. We can change these values like so:
 
<syntaxhighlight lang="lua">{
 
<syntaxhighlight lang="lua">{
 
     cloakraid = {
 
     cloakraid = {
         metalCost = 50,
+
         maxDamage = 500,
         speed = 240,
+
         maxVelocity = 8,
 
     },
 
     },
 
}</syntaxhighlight>
 
}</syntaxhighlight>
 
Copy this text into a [https://www.base64encode.org/ base64 encoder] and click encode. Here is the resulting encoding.
 
Copy this text into a [https://www.base64encode.org/ base64 encoder] and click encode. Here is the resulting encoding.
<code style="display:block;overflow:auto">ewogICAgY2xvYWtyYWlkID0gewogICAgICAgIG1ldGFsQ29zdCA9IDUwLAogICAgICAgIHNwZWVkID0gMjQwLAogICAgfSwKfQ==</code>
+
<code style="display:block;overflow:auto">ewogICAgY2xvYWtyYWlkID0gewogICAgICAgIG1heERhbWFnZSA9IDUwMCwKICAgICAgICBtYXhWZWxvY2l0eSA9IDgsCiAgICB9LAp9</code>
 
Set the Tweak Units modoption to your encoding and start the game. Your infolog should indicate that the modoption loaded successfully.
 
Set the Tweak Units modoption to your encoding and start the game. Your infolog should indicate that the modoption loaded successfully.
 
<samp><pre>[f=-000001] Loading UnitDefs_posts
 
<samp><pre>[f=-000001] Loading UnitDefs_posts
[f=-000001] Loading tweakunits modoption       <------
+
[f=-000001] Loading tweakunits modoption
[f=-000001] Loading tweakunits for cloakraid   <------
+
[f=-000001] Loading tweakunits for cloakraid
 
[f=-000001] Loading FeatureDefs_posts
 
[f=-000001] Loading FeatureDefs_posts
 
[f=-000001] Loading WeaponDefs_posts
 
[f=-000001] Loading WeaponDefs_posts
Line 54: Line 54:
 
<syntaxhighlight lang="lua">{
 
<syntaxhighlight lang="lua">{
 
     cloakraid = {
 
     cloakraid = {
         metalCost = 50,
+
         maxDamage = 500,
         speed = 240,
+
         maxVelocity = 8,
 
     },
 
     },
 
     shieldraid = {},
 
     shieldraid = {},
Line 62: Line 62:
 
<syntaxhighlight lang="lua">{
 
<syntaxhighlight lang="lua">{
 
     cloakraid = {
 
     cloakraid = {
         metalCost = 50,
+
         maxDamage = 500,
         speed = 240,
+
         maxVelocity = 8,
 
     },
 
     },
 
     shieldraid = {
 
     shieldraid = {
Line 77: Line 77:
 
}</syntaxhighlight>
 
}</syntaxhighlight>
 
As before, we now take this text, [https://www.base64encode.org/ base64 encode] it, and copy it into Tweak Units. Encodings can be shortened by removing whitespace prior to encoding.
 
As before, we now take this text, [https://www.base64encode.org/ base64 encode] it, and copy it into Tweak Units. Encodings can be shortened by removing whitespace prior to encoding.
<code style="display:block;overflow:auto">e2Nsb2FrcmFpZD17bWV0YWxDb3N0PTUwLHNwZWVkPTI0MCx9LHNoaWVsZHJhaWQ9e3dlYXBvbkRlZnM9e0xBU0VSPXtyYW5nZT02MDAsZGFtYWdlPXtkZWZhdWx0PTUwLH0sfSx9LH0sfQ==</code>
+
<code style="display:block;overflow:auto">e2Nsb2FrcmFpZCA9IHttYXhEYW1hZ2UgPSA1MDAsbWF4VmVsb2NpdHkgPSA4LH0sc2hpZWxkcmFpZCA9IHt3ZWFwb25EZWZzID0ge0xBU0VSID0ge3JhbmdlID0gNjAwLGRhbWFnZSA9IHtkZWZhdWx0ID0gNTAsfSx9LH0sfSx9</code>
  
 
== Mass post-processing ==
 
== Mass post-processing ==
  
The above examples deal with specific values for a single unit (e.g. "make Glaive have 240 speed").
+
The above examples deal with specific values for a single unit (e.g. "make Glaive have 500 health").
 
It is also possible to write Lua code that works on units, including changing values for all units or doing some sort of logic. This time, the option is not "Tweak Units" but "Tweak Defs". Again, it should be encoded to base64.
 
It is also possible to write Lua code that works on units, including changing values for all units or doing some sort of logic. This time, the option is not "Tweak Units" but "Tweak Defs". Again, it should be encoded to base64.
  
 
Here's an example:
 
Here's an example:
 
<syntaxhighlight lang="lua">for name, ud in pairs(UnitDefs) do
 
<syntaxhighlight lang="lua">for name, ud in pairs(UnitDefs) do
if ud.speed then
+
if ud.maxvelocity then
ud.speed = ud.speed*10
+
ud.maxvelocity = ud.maxvelocity*10
 
else
 
else
ud.health = ud.health*5
+
ud.maxdamage = ud.maxdamage*5
end
 
 
 
if ud.metalcost then
 
ud.metalcost = ud.metalcost*2
 
 
end
 
end
 
end</syntaxhighlight>
 
end</syntaxhighlight>
  
<var>UnitDefs</var> is a Lua table indexed with unit names as above (for example "cloakraid" for Glaive) whose values are the unit def tables in a similar format as for tweakunits, BUT WITH ALL KEYS LOWERCASE (notice how it's <var>metalcost</var> and not <var>metalCost</var>!). This snippet increases unit speeds 10 times for all mobiles and health 5 times for all statics, and makes all units twice as expensive. Some fields may be <code>nil</code> (for another example, death explosions are weapons but don't have a reload time). Specific Tweak Units values override the values that result from Tweak Defs.  
+
UnitDefs is a Lua table indexed with unit names as above (for example "cloakraid" for Glaive) whose values are the unit def tables in a similar format as for tweakunits, BUT WITH ALL KEYS LOWERCASE. This snippet increases unit speeds 10 times for all mobiles and health 5 times for all statics. Some fields may be <code>nil</code> (for another example, death explosions are weapons but don't have a reload time). Specific Tweak Units values override the values that result from Tweak Defs.  
  
 
Happy hacking!
 
Happy hacking!

Please note that all contributions to Zero-K are considered to be released under the Creative Commons Attribution-ShareAlike (see Zero-K:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)