[CLOSED] For NightShift Project - Smart SearchLight Switching
#21
Posted 27 March 2006 - 06:59 PM
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#22
Posted 27 March 2006 - 07:37 PM
function Util_GetIniSetting(sFile, sVal, sDef) local ini = nil ini = io.open(sFile, "r") if(ini ~= nil) then for line in ini:lines() do for k, v in string.gfind(line, "(%w+)=(%w+)") do if(k == sVal) then return v end end end end return sDef end function GetActiveDowMod() return Util_GetIniSetting("Local.ini", "currentmod", "w40k") end function GetActiveWxpMod() return Util_GetIniSetting("Local.ini", "currentmodwa", "wxp") end function ModIsActive(module_file, iswa) if(iswa == true) then if(string.lower(GetActiveWxpMod()) == string.lower(module_file)) then return true else return false end else if(string.lower(GetActiveDowMod()) == string.lower(module_file)) then return true else return false end end end function ModIsPresent(module_file, iswa) local file_id = nil file_id = pcall(io.open, module_file .. ".module", "r")) if (file_id ~= nil) then file_id:close() return true else return false end end
Above goes in RaceLoader.ai ? I take it no editing to it is necessary as it will auto-detect the .module files dynamically?
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#23
Posted 27 March 2006 - 08:15 PM
So in conclusion, as long as the bug does not bring up the error reporting thingy then pcall will help.
Thanks Corsix. It might be worth a try...
Above goes in RaceLoader.ai ? I take it no editing to it is necessary as it will auto-detect the .module files dynamically?
I would have guessed that it belongs in utility.ai
#24
Posted 28 March 2006 - 01:58 AM
local file_id = nil file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r") if (file_id ~= nil) then if self.squad_ai:GetTactic():HasAbility( "marines_searchlight_dreadnought" ) then local light1_id = cpu_manager.stats:GetAbilityID( "marines_searchlight_dreadnought" ) Ability.DoAbilitySearchLight( self.squad_ai, light1_id, " vehicle" )
I think the problem is in the tactic.ai for GetTactic():HasAbility:
function Tactic:HasAbility( ability_id ) -- Get Ability ID local iAbilityID = cpu_manager.stats:GetAbilityID( ability_id ) if (iAbilityID == ability_id ) then return true end return false endDoes that look correct? Its just not passing it thru.
Btw.. thanks Corsix for the utility.ai code! Its in and works fine with pcall.
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#25
Posted 28 March 2006 - 08:43 PM
local file_id = nil file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r") if (file_id ~= nil) then local iAbilityID = cpu_manager.stats:GetAbilityID("marines_searchlight_dreadnought") if (iAbilityID ~= nil) then Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" ) end end
or if GetAbilityID() crashes...
local file_id = nil file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r") if (file_id ~= nil) then local iAbilityID = pcall(cpu_manager.stats:GetAbilityID, "marines_searchlight_dreadnought") if (iAbilityID ~= nil) then Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" ) end end
In this case you wouldn't need Tactic:HasAbility()!
#26
Posted 28 March 2006 - 09:08 PM
I'll test it and see what pcall does if it can prevent the crash AND pass the command over.
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#27
Posted 29 March 2006 - 02:07 AM
local iAbilityID = pcall(cpu_manager.stats:GetAbilityID( "marines_searchlight_dreadnought" )) if (iAbilityID ~= nil) then Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" )I tried it on its own as above here and its a no go. Its the pcall that is blocking something here and not passing it over to the Ability.DoAbilitySearchLight line below. Any thoughts?
Btw, thanks you guys for the help in figuring this out. This is MASSIVELY HELPFUL and I seriously believe will be important to know in time. Yes its more a "research project" but its practical application is more than mere logic.
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#28
Posted 29 March 2006 - 11:15 AM
I'll add a custom folder to the AI folder where every mod can place a custom ai file. The name has to be modname.ai, where 'modname' is the same string used for the module file of the mod. If such a file exists, I'll run an Init method of the class in this file which has to exist and which name must also be the module name.
You can then, for example, create a nightshift.ai file (Provided that the module file is called nightshift.module) which has just a parameter NightShiftIsActive = true and a nightshift class with just a lonly init.
You can then use the nightshift abilities everywhere like that:
if (NightShiftIsActive ~= nil) then local iAbilityID = cpu_manager.stats:GetAbilityID("marines_searchlight_dreadnought") Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" ) end
I'll send you a mail this evening/night when I'm finished...
#29
Posted 29 March 2006 - 12:42 PM
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
#30
Posted 26 April 2006 - 03:14 AM
Dawn of War Advanced AI Headquarters
Latest DoW Advanced AI Download!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users