Once you have made your map select the terrain type tab and use Sand01 and paint the areas you want the effect to happen on, you can change the terrain type to another one if you don't like the dust effect sand01 uses just make sure you change the references in the script to match.
With this script you need to make your map unranked because it affects the units in a way that is not always obvious, and might affect the balance.
You should put an explanation in the description on what terrain and where is effected by this script to avoid player confusion.
Standard map (not Adaptive)
open your script.lua and replace everything with this
- Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local ScenarioFramework = import('/lua/ScenarioFramework.lua')
local simUnit = import('/lua/sim/Unit.lua')
local oldUnit = simUnit.Unit
local TERRAIN_SAND_NAME = 'Sand01'
------ GENERAL
function OnPopulate ()
ScenarioUtils.InitializeArmies()
ScenarioFramework.SetPlayableArea('AREA_1' , false)
end
function OnStart (scenario)
ForkThread(showmessage)
ForkThread(gatherFeedback)
end
------ Startmessage
function gatherFeedback()
WaitSeconds(10)
BroadcastMSG('The -- INSERT TERRAIN OR AREA HERE -- will slow your GROUND units down -- HOVER units are affected less', -- message
40, -- fontsize
'd0d0d0', -- color
10, -- duration
'center') -- position
end
-- Change message colour to stand out against terrain colour codes are; Yellow - ffff00, Orange - ffa500, Red - ff0000, Purple - 9370db Blue - 0000ff,
-- Light Blue - 00bfff, Green - 7cfc00, Black - 000000, White - d0d0d0
function showmessage()
local message = ''
local sendmessage = false
end
function BroadcastMSG(message, fontsize, RGBColor, duration, location)
-- broadcast a text message to players
-- possible locations = lefttop, leftcenter, leftbottom, righttop, rightcenter, rightbottom, rightbottom, centertop, center, centerbottom
PrintText(message, fontsize, 'ff' .. RGBColor, duration , location) ;
end
----- SLOW ON SAND
simUnit.Unit = Class(oldUnit) {
OnTerrainTypeChange = function(self, new, old)
oldUnit.OnTerrainTypeChange(self, new, old)
if (new and new.Name == TERRAIN_SAND_NAME) then
if (isLandUnit(self)) then
if (isCommanderUnit(self)) then
self:SetSpeedMult(0.9)
elseif (isHoveringUnit(self)) then
self:SetSpeedMult(0.8)
else
self:SetSpeedMult(0.6)
end
end
elseif (old and old.Name == TERRAIN_SAND_NAME) then
if (isLandUnit(self)) then
self:SetSpeedMult(1)
end
end
end,
}
function isLandUnit (unit)
if (EntityCategoryContains(categories.MOBILE * categories.LAND, unit)) then
return true
else
return false
end
end
function isHoveringUnit (unit)
if (EntityCategoryContains(categories.HOVER, unit)) then
return true
else
return false
end
end
function isCommanderUnit (unit)
if (EntityCategoryContains(categories.COMMAND + categories.SUBCOMMANDER, unit)) then
return true
else
return false
end
end
Adaptive Maps
With adaptive maps it's a bit more involved but not to hard, first you need to add this, where the script is calling for all the other local references
- Code: Select all
local simUnit = import('/lua/sim/Unit.lua')
local oldUnit = simUnit.Unit
local TERRAIN_SAND_NAME = 'Sand01'
- Code: Select all
----- SLOW ON SAND
simUnit.Unit = Class(oldUnit) {
OnTerrainTypeChange = function(self, new, old)
oldUnit.OnTerrainTypeChange(self, new, old)
if (new and new.Name == TERRAIN_SAND_NAME) then
if (isLandUnit(self)) then
if (isCommanderUnit(self)) then
self:SetSpeedMult(0.9)
elseif (isHoveringUnit(self)) then
self:SetSpeedMult(0.8)
else
self:SetSpeedMult(0.6)
end
end
elseif (old and old.Name == TERRAIN_SAND_NAME) then
if (isLandUnit(self)) then
self:SetSpeedMult(1)
end
end
end,
}
function isLandUnit (unit)
if (EntityCategoryContains(categories.MOBILE * categories.LAND, unit)) then
return true
else
return false
end
end
function isHoveringUnit (unit)
if (EntityCategoryContains(categories.HOVER, unit)) then
return true
else
return false
end
end
function isCommanderUnit (unit)
if (EntityCategoryContains(categories.COMMAND + categories.SUBCOMMANDER, unit)) then
return true
else
return false
end
end
--Startmessageslow
function gatherFeedback()
WaitSeconds(0)
BroadcastMSG('The -- INSERT TERRAIN OR AREA HERE -- will slow your GROUND units down -- HOVER units are affected less', -- message
40, -- fontsize
'ff0000', -- color
10, -- duration
'center') -- position
end
-- Change message colour to stand out against terrain colour codes are; Yellow - ffff00, Orange - ffa500, Red - ff0000, Purple - 9370db Blue - 0000ff,
-- Light Blue - 00bfff, Green - 7cfc00, Black - 000000, White - d0d0d0
Changing the speed
To change how much units are effected you need to change unit:SetSpeedMult(0.9)
with 1 being default speed 0.5 being half speed and anything over 1 will speed units up
there are 3 categories;
- Code: Select all
if (new and new.Name == TERRAIN_SAND_NAME) then
if (isLandUnit(self)) then
if (isCommanderUnit(unit)) then
unit:SetSpeedMult(0.9)
elseif (isHoveringUnit(unit)) then
unit:SetSpeedMult(0.8)
else
unit:SetSpeedMult(0.6)
end
- Code: Select all
if (isCommanderUnit(unit)) then
unit:SetSpeedMult(0.9)
- Code: Select all
elseif (isHoveringUnit(unit)) then
unit:SetSpeedMult(0.8)
- Code: Select all
else
unit:SetSpeedMult(0.6)
And credit the author in description