- Joined
- Nov 26, 2021
- Messages
- 25
Anyone know possible causes of of editor crashing when trying to save map with this code
In log file says invalid jass script in lua, but it is not jass it’s lua
In log file says invalid jass script in lua, but it is not jass it’s lua
Code:
-- Global table to store original movement speeds of units
local originalMoveSpeeds = {}
-- Helper function to store the original movement speed of a unit
function StoreOriginalMoveSpeed(unit)
originalMoveSpeeds[unit] = GetUnitMoveSpeed(unit)
end
-- Helper function to restore the original movement speed of a unit
function RestoreOriginalMoveSpeed(unit)
if originalMoveSpeeds[unit] then
SetUnitMoveSpeed(unit, originalMoveSpeeds[unit])
end
end
-- Helper function to create a meteor at a random position
function CreateMeteorAtPosition(x, y)
local meteor = AddSpecialEffect("Abilities\\Spells\\Other\\Inferno\\Inferno.mdl", x, y)
local moveDuration = 2.0 -- Duration in seconds for meteor to fall
local meteorSpeed = 10.0 -- Speed of falling meteor
local targetHeight = 0 -- Target height for impact (ground level)
-- Start a timer to animate the falling effect
local timer = CreateTimer()
TimerStart(timer, 0.03, true, function()
local x, y = GetUnitX(meteor), GetUnitY(meteor)
local z = GetUnitZ(meteor) - meteorSpeed
-- Update meteor's position (fall downward)
if z <= targetHeight then
-- Deal damage to nearby units when meteor hits the ground
local unitsInRange = GetUnitsInRangeOfLocAll(200, Location(x, y))
for _, unit in ipairs(unitsInRange) do
UnitDamageTarget(unit, 100, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_FIRE, nil) -- 100 damage
end
DestroyEffect(meteor)
DestroyTimer(timer)
else
SetUnitPosition(meteor, x, y, z)
end
end)
end
-- Helper function to create a lightning strike at a random position
function CreateLightningAtPosition(x, y)
AddSpecialEffect("Abilities\\Spells\\Human\\StormBolt\\StormBoltTarget.mdl", x, y)
PlaySoundAtPoint("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", x, y)
-- Deal lightning damage to nearby units
local unitsInRange = GetUnitsInRangeOfLocAll(250, Location(x, y)) -- Lightning radius of 250
for _, unit in ipairs(unitsInRange) do
UnitDamageTarget(unit, 50, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_LIGHTNING, nil) -- 50 damage
end
end
-- Function to set the weather (Rain, Snow, Fog, Clear, etc.)
function SetWeather(weatherType)
-- First, restore the movement speed of all units
local units = GetUnitsInRangeOfLocAll(10000, Location(0, 0)) -- Check all units on the map
for _, unit in ipairs(units) do
RestoreOriginalMoveSpeed(unit)
end
-- Clear all weather effects
BlzSetWeatherEffect(WEATHER_EFFECT_RAIN, false)
BlzSetWeatherEffect(WEATHER_EFFECT_SNOW, false)
SetFogState(0, false) -- Clear fog
PlaySoundAtPoint("", 0, 0) -- Stop any active sound
-- Now apply the new weather
if weatherType == "Rain" then
BlzSetWeatherEffect(WEATHER_EFFECT_RAIN, true)
PlaySoundAtPoint("Environment\\Rain\\RainLoop1.mdl", 0, 0) -- Rain sound
-- Impact on gameplay: Slows down units
for _, unit in ipairs(units) do
SetUnitMoveSpeed(unit, GetUnitMoveSpeed(unit) * 0.7) -- 30% slower movement
end
elseif weatherType == "Snow" then
BlzSetWeatherEffect(WEATHER_EFFECT_SNOW, true)
PlaySoundAtPoint("Environment\\Snow\\SnowstormLoop.mdl", 0, 0) -- Snow sound
-- Impact on gameplay: Slows down units and reduces visibility
for _, unit in ipairs(units) do
SetUnitMoveSpeed(unit, GetUnitMoveSpeed(unit) * 0.6) -- 40% slower movement
end
-- Reduce vision range (simulating the blizzard effect)
SetUnitFogState(0, true) -- Use fog for reduced visibility
elseif weatherType == "Fog" then
SetFogState(1, true) -- Apply heavy fog
PlaySoundAtPoint("Environment\\Fog\\FogLoop1.mdl", 0, 0) -- Fog sound
for _, unit in ipairs(units) do
SetUnitFogState(unit, true) -- Apply reduced visibility
end
elseif weatherType == "Wind" then
PlaySoundAtPoint("Environment\\Wind\\WindLoop1.mdl", 0, 0) -- Wind sound
-- Impact on gameplay: Affect movement speed and projectiles
for _, unit in ipairs(units) do
SetUnitMoveSpeed(unit, GetUnitMoveSpeed(unit) * 1.2) -- 20% faster movement
end
elseif weatherType == "Meteor" then
local x = GetRandomReal(-500, 500)
local y = GetRandomReal(-500, 500)
CreateMeteorAtPosition(x, y)
PlaySoundAtPoint("Environment\\Meteors\\MeteorImpact.mdl", 0, 0) -- Meteor impact sound
elseif weatherType == "Lightning" then
local x = GetRandomReal(-500, 500)
local y = GetRandomReal(-500, 500)
CreateLightningAtPosition(x, y)
PlaySoundAtPoint("Environment\\Lightning\\LightningStrike.mdl", 0, 0) -- Lightning sound
elseif weatherType == "Clear" then
-- Clear weather: Stop all weather effects, restore normal conditions
SetFogState(0, false) -- Clear fog
PlaySoundAtPoint("Environment\\Clear\\ClearWeatherLoop.mdl", 0, 0) -- Calm ambient sound
-- Impact on gameplay: Restore normal movement speeds
for _, unit in ipairs(units) do
RestoreOriginalMoveSpeed(unit)
end
elseif weatherType == "AcidRain" then
-- Acid Rain Effect: Visual or sound effect for acid rain
PlaySoundAtPoint("Environment\\AcidRain\\AcidRainLoop.mdl", 0, 0) -- Acid rain sound
local acidRainEffect = AddSpecialEffect("Abilities\\Spells\\Other\\AcidCloud\\AcidCloud.mdl", 0, 0)
-- Deal 1 damage per second to all units for 1 minute
local acidRainTimer = CreateTimer()
TimerStart(acidRainTimer, 1.0, true, function()
-- Deal 1 damage to all units on the map every second
local unitsInRange = GetUnitsInRangeOfLocAll(10000, Location(0, 0))
for _, unit in ipairs(unitsInRange) do
UnitDamageTarget(unit, 1, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_ACID, nil) -- 1 damage per second
end
end)
-- Stop the acid rain after 1 minute
TimerStart(CreateTimer(), 60.0, false, function()
DestroyEffect(acidRainEffect)
DestroyTimer(acidRainTimer)
end)
end
-- Set a timer to end the current weather effect after 5 minutes (except for AcidRain)
local weatherDuration = (weatherType == "AcidRain") and 60.0 or 300.0 -- 1 minute for AcidRain, 5 minutes for others
local weatherTimer = CreateTimer()
TimerStart(weatherTimer, weatherDuration, false, function()
-- Reset to clear weather after the weather duration
SetWeather("Clear")
DestroyTimer(weatherTimer)
end)
end
-- Function to randomly create a weather event (rain, snow, fog, wind, meteor, lightning, clear, acid rain)
function RandomWeatherEvent()
local eventType = GetRandomInt(0, 7) -- 0: Rain, 1: Snow, 2: Fog, 3: Wind, 4: Meteor, 5: Lightning, 6: Clear, 7: Acid Rain
-- Rare chance for Acid Rain (1 in 20 chance)
if GetRandomInt(1, 20) == 1 then
SetWeather("AcidRain")
else
if eventType == 0 then
SetWeather("Rain")
elseif eventType == 1 then
SetWeather("Snow")
elseif eventType == 2 then
SetWeather("Fog")
elseif eventType == 3 then
SetWeather("Wind")
elseif eventType == 4 then
SetWeather("Meteor")
elseif eventType == 5 then
SetWeather("Lightning")
elseif eventType == 6 then
SetWeather("Clear")
end
end
end
-- Function to start the dynamic weather system
function StartDynamicWeatherSystem()
local interval = 5.0 * 60.0 -- 5 minutes interval (in seconds)
local timer = CreateTimer()
-- Start the periodic weather system every 5 minutes
TimerStart(timer, interval, true, function()
-- Trigger a random weather event (rain, snow, fog, wind, meteor, lightning, clear, acid rain)
RandomWeatherEvent()
end)
end
-- Start the dynamic weather system when the game begins
StartDynamicWeatherSystem()