Forged Alliance Forever Forums
Moderator: Morax
speed2 wrote:The only way to do this would be to set area triggers that will create visible areas (those are circles)
https://github.com/FAForever/fa/blob/develop/lua/ScenarioFramework.lua#L84-L91
https://github.com/FAForever/fa/blob/develop/lua/ScenarioFramework.lua#L1116-L1133
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local TriggerFile = import('scenariotriggers.lua')
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local UnitUpgradeTemplates = import('/lua/upgradeTemplates.lua').UnitUpgradeTemplates
local ScenarioPlatoonAI = import('/lua/ScenarioPlatoonAI.lua')
local VizMarker = import('/lua/sim/VizMarker.lua').VizMarker
local SimCamera = import('/lua/SimCamera.lua').SimCamera
local Cinematics = import('/lua/cinematics.lua')
local SimUIVars = import('/lua/sim/SimUIState.lua')
function OnPopulate()
ScenarioUtils.InitializeArmies()
ForkThread(CreateVisibleAreaLocation)
end
local vizLocation
local vizArmy
local vizRadius
local vizLifetime
local X
local Z
local Radius
local LifeTime
local Army
function CreateVisibleAreaLocation(vizRadius, vizLocation, vizLifetime, vizArmy)
if type(vizLocation) == 'string' then
vizLocation = ScenarioUtils.MarkerToPosition(vizLocation)
vizArmy = GetUnitsInRect( Rect(vizLocation[1]-5, vizLocation[3]-5, vizLocation[1]+5, vizLocation[3]+5) )
vizRadius = 20
vizLifetime = 0
end
local spec = {
X = vizLocation[1],
Z = vizLocation[3],
Radius = vizRadius,
LifeTime = vizLifetime,
Army = vizArmy:GetArmyIndex(),
}
local vizEntity = VizMarker(spec)
return vizEntity
end
function OnStart(self)
end
WARNING: Error running lua script: ...me commander - forged alliance\maps\11\11_script.lua(36): attempt to call method `GetArmyIndex' (a nil value)
stack traceback:
...me commander - forged alliance\maps\11\11_script.lua(36): in function <...me commander - forged alliance\maps\11\11_script.lua:24>
Sprouto wrote:The forkthread is not causing the error.
The error occurs because you're calling GetArmyIndex with a nil;
This means that vizArmy is nil, which means your code is not finding any units in the area you specified. Even worse, if it did find multiple units in the area, you would likely get a similar error, since GetArmyIndex will only function on a single entity.
Sprouto wrote:Well...this code will only run once - right at the start of the game. If the units are there to begin with, it might work, but otherwise you need to find the right place in the main code to insert it. Running it during OnPopulate() will not work beyond the very beginning of a map.
WARNING: Error running lua script: attempt to use as integer a table value
stack traceback:
[C]: in function `_c_CreateEntity'
...ed alliance\gamedata\mohodata.scd\lua\sim\entity.lua(11): in function `__init'
...alliance\gamedata\mohodata.scd\lua\sim\vizmarker.lua(15): in function `initfn'
... alliance\gamedata\mohodata.scd\lua\system\class.lua(258): in function <... alliance\gamedata\mohodata.scd\lua\system\class.lua:246>
...me commander - forged alliance\maps\11\11_script.lua(41): in function <...me commander - forged alliance\maps\11\11_script.lua:24>
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local TriggerFile = import('scenariotriggers.lua')
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')
local UnitUpgradeTemplates = import('/lua/upgradeTemplates.lua').UnitUpgradeTemplates
local ScenarioPlatoonAI = import('/lua/ScenarioPlatoonAI.lua')
local VizMarker = import('/lua/sim/VizMarker.lua').VizMarker
local SimCamera = import('/lua/SimCamera.lua').SimCamera
local Cinematics = import('/lua/cinematics.lua')
local SimUIVars = import('/lua/sim/SimUIState.lua')
function OnPopulate()
ScenarioUtils.InitializeArmies()
ForkThread(CreateVisibleAreaLocation)
end
local vizLocation
local vizArmy
local vizRadius
local vizLifetime
local X
local Z
local Radius
local LifeTime
local Army
function CreateVisibleAreaLocation(vizRadius, vizLocation, vizLifetime, vizArmy)
while true do
for k = 1, 1 do
vizLocation = ScenarioUtils.MarkerToPosition('vizLocation_' .. k)
vizArmy = GetUnitsInRect( Rect(vizLocation[1]-5, vizLocation[3]-5, vizLocation[1]+5, vizLocation[3]+5) )
if vizArmy then
for _, instigator in vizArmy do
if VDist3(instigator:GetPosition(), vizLocation) <= 5 then
vizRadius = 20
vizLifetime = 0
local spec = {
X = vizLocation[1],
Z = vizLocation[3],
Radius = vizRadius,
LifeTime = vizLifetime,
Army = vizArmy[1]:GetAIBrain(),
}
local vizEntity = VizMarker(spec)
return vizEntity
end
end
end
end
WaitSeconds(5)
end
end
function OnStart(self)
end
Sprouto wrote:The error is coming from your attempt to create a vision entity;
local vizEntity = VizMarker(spec)
Look carefully at what your putting into spec;
local spec = {
X = vizLocation[1],
Z = vizLocation[3],
Radius = vizRadius,
LifeTime = vizLifetime,
Army = vizArmy[1]:GetAIBrain(),
}
The error is telling you that some piece of data here is a table - look carefully at what your trying to pass along as Army...
You're not passing it's army index - but the entire brain that it belongs to. Try vizArmy[1]:GetAIBrain():GetArmyIndex()
WARNING: Invalid args to yield(); expected tick count
stack traceback:
Users browsing this forum: No registered users and 1 guest