Code: Select all
local koenigsberg = game:GetHex(112, 17)
if koenigsberg.unit ~= nil
and unit.hex ~= nil
and unit.hex.x == 112
and unit.hex.y == 17
and unit.prototype.name == "garrison" then
unit.mp = 0
end
Moderators: Slitherine Core, The Lordz
Code: Select all
local koenigsberg = game:GetHex(112, 17)
if koenigsberg.unit ~= nil
and unit.hex ~= nil
and unit.hex.x == 112
and unit.hex.y == 17
and unit.prototype.name == "garrison" then
unit.mp = 0
end
Code: Select all
local paris = game:GetHex(82, 30)
Code: Select all
local hexes = game.map:GetHexesInRange(paris, 3)
Code: Select all
for _, hex in pairs(hexes) do
end
Code: Select all
if hex.unit ~= nil
Code: Select all
and hex.unit.faction.id == 2
Code: Select all
SetEvent("Taxis", game.turn)
break
Code: Select all
function Taxis()
local paris = game:GetHex(82, 30)
if GetEvent("Taxis") == 0 then
local hexes = game.map:GetHexesInRange(paris, 3)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.faction.id == 2 then
SetEvent("Taxis", game.turn)
break
end
end
end
end
Code: Select all
local koenigsberg= game:GetHex(112, 17)
local hexes = game.map:GetHexesInRange(koenigsberg, 4)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.faction.id == 4 then
if koenigsberg.unit ~= nil
and koenigsberg.unit.alliance.id == 2 then
koenigsberg.unit.mp = 0
break
end
end
end
Code: Select all
if koenigsberg.unit ~= nil
and koenigsberg.unit.alliance.id == 2 then
koenigsberg.unit.mp = 0
break
end
Code: Select all
local birmingham= game:GetHex(76, 22)
local hexes = game.map:GetHexesInRange(birmingham, 4)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.alliance.id == 2
and hex.unit.type == Unit.LAND then
if birmingham.unit ~= nil
and unit.prototype.name == "garrison"
and birmingham.unit.alliance.id == 1 then
birmingham.unit.mp = 0
break
end
end
end
Code: Select all
local birmingham = game:GetHex(76, 22)
local hexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(hexes) do
if hex.unit == nil
or (hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 1) then
if birmingham.unit ~= nil
and unit.prototype.name == "garrison"
and birmingham.unit.alliance.id == 1 then
birmingham.unit.mp = 0
break
end
end
end
Code: Select all
local birmingham = game:GetHex(76, 22)
local hexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(hexes) do
if hex.unit == nil
or (hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 1) then ---- change the 1 to 2 or else the unit will freeze when Entente units are in range
if birmingham.unit ~= nil
and unit.prototype.name == "garrison"
and birmingham.unit.alliance.id == 1 then
birmingham.unit.mp = 0
break
end
end
end
andwhen an enemy unit in range, freeze the garrison unit
because I can't see any.mantain freeze the garrison unit until an enemy unit is in range
Code: Select all
local birmingham = game:GetHex(76, 22)
local hexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(hexes) do
if hex.unit == nil ----<<<<<<----- why is this included? this would mean that even if no enemy is in range the garrison would freeze in place
or (hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 1) then ----<<<<<< change the 1 to 2 or else the unit will freeze when Entente units are in range
if birmingham.unit ~= nil
and unit.prototype.name == "garrison"
and birmingham.unit.alliance.id == 1 then
birmingham.unit.mp = 0
break
end
end
end
Code: Select all
local britain = game:GetFactionById(1)
for unit in britain.units do
if unit.hex ~= nil then
local center = unit.hex
local hexes = game.map:GetHexesInRange(center, 5)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 2 then
if center.unit ~= nil
and center.unit.prototype.name == "garrison"
and center.unit.alliance.id == 1
and center.construction ~= nil
and center.originalFaction.id == britain.id then
center.unit.mp = 0
break
end
end
end
end
end
With the first one I mean an unit is free to move until enemy units are in range, when is freezed (useless). With the second one the unit is freeze from the first turn until enemy units are in range from the hex it occupies (what I want).
It was a wrong try, it's difficult for me to explain the reason in englishRobotron wrote: ↑Thu Aug 20, 2020 4:20 pm I just noticed another problem with your script:
Code: Select all
local birmingham = game:GetHex(76, 22) local hexes = game.map:GetHexesInRange(birmingham, 5) for _, hex in pairs(hexes) do if hex.unit == nil ----<<<<<<----- why is this included? this would mean that even if no enemy is in range the garrison would freeze in place or (hex.unit ~= nil and hex.unit.type == Unit.LAND and hex.unit.alliance.id == 1) then ----<<<<<< change the 1 to 2 or else the unit will freeze when Entente units are in range if birmingham.unit ~= nil and unit.prototype.name == "garrison" and birmingham.unit.alliance.id == 1 then birmingham.unit.mp = 0 break end end end
It's an interesting script I'll use for other purposes, but not for "freezed garrisons" subject. I only want to freeze a few garrisons, not all of them in british cities.Robotron wrote: ↑Thu Aug 20, 2020 4:20 pm Also you don't have to write a script for each city. You can just check every British unit on hex with a construction originally belonging to Britain by doing:
Code: Select all
local britain = game:GetFactionById(1) for unit in britain.units do if unit.hex ~= nil then local center = unit.hex local hexes = game.map:GetHexesInRange(center, 5) for _, hex in pairs(hexes) do if hex.unit ~= nil and hex.unit.type == Unit.LAND and hex.unit.alliance.id == 2 then if center.unit ~= nil and center.unit.prototype.name == "garrison" and center.unit.alliance.id == 1 and center.construction ~= nil and center.originalFaction.id == britain.id then center.unit.mp = 0 break end end end end end
Code: Select all
local birmingham = game:GetHex(76, 22)
local check = 0
local hexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 2 then
if birmingham.unit ~= nil
and birmingham.unit.prototype.name == "garrison"
and birmingham.unit.faction.id == 1 then
check = 1
break
end
end
end
if check == 0 then
unit.mp = 0
end
Code: Select all
local birmingham = game:GetHex(76, 22)
local check = 0
local hexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(hexes) do
if hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 2 then
check = 1
break
end
end
if birmingham.unit ~= nil
and birmingham.unit.prototype.name == "garrison"
and birmingham.unit.faction.id == 1
and check == 0 then
birmingham.unit.mp = 0
end
Code: Select all
[00:05:02][4208]game/game_events.lua:14(global SetEvent) game/game_events.lua:14: attempt to compare number with nil
Code: Select all
function RussiaStorm()
local belgium = game:GetFactionById(6)
local russia = game:GetFactionById(4)
if GetEvent("RussiaStorm") == 0
and player.alliance.id == 2
and game.type == Game.TYPE_SINGLE
and GetEvent("Rupprecht") <= 0
and GetEvent("AllEast") <= 0
and GetEvent("Redeploy") <= 0
and GetEvent("BelgiumAttacked2") == 0
and GetEvent("DOWgermany") >0
and GetEvent("RussiaMob") <= 0
and GetEvent("RussiaSurprise") == 0
and GetEvent("DOWrussia") == 0 then
SetFactionAlignment(4, 100)
SetEvent("RussiaSurprise", game.turn)
SetEvent("RussiaStorm", -1)
end
end
Code: Select all
local birmingham = game:GetHex(76, 22)
local check = 0
if unit.hex ~= nil
and unit.faction.id == 1
and unit.hex == birmingham then
local ahexes = game.map:GetHexesInRange(birmingham, 5)
for _, hex in pairs(ahexes) do
if hex.unit ~= nil
and hex.unit.type == Unit.LAND
and hex.unit.alliance.id == 2 then
check = 1
break
end
end
if unit.prototype.name == "garrison"
and check == 0 then
unit.mp = 0
end
end