Search the Community
Showing results for tags 'lua'.
Found 3 results
-
I was trying to keep track of some status in gameplay and react as soon as certain condition's met, and I've written some code similar to that below. -- function to run on a unit of this type created function KeepTrackAndReactOnCreated(self) if unitCnt == nil then unitCnt = {} -- global variable end local plyr = ObjectTeamName(self) if unitCnt[plyr] == nil then unitCnt[plyr] = 1 else unitCnt[plyr] = unitCnt[plyr] + 1 end if unitCnt[plyr] >= 5 then ObjectGrantUpgrade(self, "Upgrade_SomeUpgrade") end end -- function to run on a unit of this type destroyed function KeepTrackAndReactOnDestroyed(self) local plyr = ObjectTeamName(self) unitCnt[plyr] = unitCnt[plyr] - 1 if unitCnt[plyr] < 5 then ObjectRemoveUpgrade(self, "Upgrade_SomeUpgrade") end end It's working just fine, until I saved the game and then loaded it...It seems that every time I load the SavedGame file, unitCnt doesn't exist, as if the global variable and its value were not saved to the SavedGame file. Does anyone has any idea of how I can solve this problem? Is there any way to save a global variable and its value to a SavedGame file and have them loaded later? Or is it just impossible to do so?
- 3 replies
-
- global variable
- coding
-
(and 1 more)
Tagged with:
-
How does the ScriptTimer in metaMod work?
pengion posted a topic in Tiberium Wars / Kane's Wrath Maps & Modding
I'm working on MetaMod_2.00 by Mjjstra, and I want to create a tower defense map using lua. And I have to evaluate whether timer equal to a specific value to excute some actions .I have found the lua function to judge whether timer equals to a spcific value like this function TimerCounterRefresh(self) for counter,value in TimerTable do if counter~="n" then if value == 0 then ExecuteAction("HIDE_COUNTER", counter) --tremove(TimerTable, counter) TimerTable[counter] = nil NumberTimers = NumberTimers - 1 if NumberTimers <= 0 then ExecuteAction("NAMED_DELETE", self) end break elseif value == 1201 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[20]) elseif value == 901 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[15]) elseif value == 601 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[10]) elseif value == 301 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[5]) elseif value == 181 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[3]) elseif value == 61 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerMin[1]) elseif value == 31 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerSec[30]) elseif value == 11 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerSec[10]) elseif value == 4 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[3]) elseif value == 3 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[2]) elseif value == 2 then ExecuteAction("PLAY_SOUND_EFFECT", VoiceTimerCount[1]) end ExecuteAction("COUNTER_MATH_COUNTER", counter, MathOpTable["Subtract"], CounterTable[1]) TimerTable[counter] = TimerTable[counter] - 1 end end end But I can't figure out how to execute the function every second in the game loop to .Can someone help me? -
Set PlayerSpecialPower's countdown timer in game?
ravage posted a topic in Tiberium Wars / Kane's Wrath Maps & Modding
I'm trying to set SpecialPower's countdown timer backward in game, with LUA code: ExecuteAction("NAMED_SET_SPECIAL_POWER_COUNTDOWN", self, "SpecialPowerGDI_APCMinefield", 10); it works fine with UnitAbility like APCMinefield, but doesn't affect PlayerSpecialPower like Ioncannon, nuke, etc. i guess it may has something to do with GDIPowerStore and/or PlayerSpellBook so i applied the same codes ---SpecialPower XMLs, and LUA scripts --- to them too, still not working. any ideas?