SteelCrow Posted May 11, 2017 Share Posted May 11, 2017 I'm trying to create a program whose PWR cost is based on the player's current PWR. I've been trying to activate triggers to keep the program's PWR cost updated, but the new triggers I've been trying aren't working. The only one that's made a difference is the existing one "TRG_START_TURN", but I need this program to update more often than that. I've been trying to alter the function addCpus() so that every change to the player's PWR makes my program update. Is there any important difference between dispatchEvent() and triggerEvent() that I need to know about? My mainframe_abilities.lua and the addCpus() entries at the moment: Spoiler steelcrow_flood = util.extend( DEFAULT_ABILITY ) { name = STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.NAME, desc = STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.DESC, huddesc = STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.HUD_DESC, shortdesc = STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.SHORT_DESC, tipdesc = STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.TIP_DESC, icon = "gui/icons/programs_icons/icon-program-powerdrip.png", icon_100 = "gui/icons/programs_icons/store_icons/StorePrograms_drip.png", cpu_cost = 1, value = 600, equip_program = true, equipped = false, PROGRAM_LIST = 10, onSpawnAbility = function( self, sim ) DEFAULT_ABILITY.onSpawnAbility( self, sim ) self._sim = sim sim:addTrigger( simdefs.TRG_CPU_CHANGE_FLOOD, self ) end, onDespawnAbility = function( self, sim ) DEFAULT_ABILITY.onDespawnAbility( self, sim ) sim:removeTrigger( simdefs.TRG_CPU_CHANGE_FLOOD, self ) end, onTrigger = function( self, sim, evType, evData ) DEFAULT_ABILITY.onTrigger( self, sim, evType, evData ) if evType == simdefs.TRG_CPU_CHANGE_FLOOD then self.break_firewalls = math.max(math.ceil(sim:getPC():getCpus() ),1) self.cpu_cost = math.max(math.ceil(sim:getPC():getCpus() ),1) self.tipdesc = string.format(STRINGS.SCMODS_PROGRAM.PROGRAMS.FLOOD.TIP_DESC2,self.break_firewalls) end end, }, Spoiler local simplayer = include( "sim/simplayer" ) local simdefs = include( "sim/simdefs" ) function simplayer:addCPUs( delta, sim,x,y, delay ) local old_cpus = self._cpus self._cpus = math.max( 0, self._cpus + delta ) self._cpus = math.min( self:getMaxCpus( ), self._cpus ) local actual_delta = self._cpus - old_cpus if delta < 0 then self._sim:dispatchEvent( simdefs.EV_HUD_SUBTRACT_CPU, {delta = delta} ) end if actual_delta > 0 then self._sim._resultTable.pwr_gained = self._sim._resultTable.pwr_gained and self._sim._resultTable.pwr_gained + delta or delta elseif actual_delta < 0 then self._sim._resultTable.pwr_used = self._sim._resultTable.pwr_used and self._sim._resultTable.pwr_used - delta or -delta end sim:dispatchEvent( simdefs.TRG_CPU_CHANGE_FLOOD ) if x and y then local sound = "SpySociety/HUD/gameplay/gain_pwr" local floatTxt if delta < 0 then sound = "SpySociety/HUD/gameplay/lose_pwr" floatTxt = util.sformat( STRINGS.FORMATS.PWR, delta ) else floatTxt = util.sformat( STRINGS.FORMATS.PLUS_PWR, delta ) end sim:dispatchEvent( simdefs.EV_UNIT_FLY_TXT, {txt=floatTxt, x=x,y=y, color={r=1,g=1,b=1,a=1}, sound=sound, soundDelay=0.1, delay=delay } ) --1.5 else self._sim:dispatchEvent( simdefs.EV_PLAY_SOUND, "SpySociety/HUD/gameplay/gain_pwr" ) end end Link to comment Share on other sites More sharing options...
PrismaticPhoton Posted May 11, 2017 Share Posted May 11, 2017 I don't think triggers are what you want. I would think the simplest approach would be to override the "getCpuCost" function for the program. This is what Rapier does: Spoiler getCpuCost = function( self ) local trackerStage = 0 if self._sim then trackerStage = self._sim:getTrackerStage( math.min( simdefs.TRACKER_MAXCOUNT, self._sim:getTracker() )) end self.cpu_cost = 1 + trackerStage return DEFAULT_ABILITY.getCpuCost( self ) end, Link to comment Share on other sites More sharing options...
SteelCrow Posted May 12, 2017 Author Share Posted May 12, 2017 22 hours ago, PrismaticPhoton said: I don't think triggers are what you want. I would think the simplest approach would be to override the "getCpuCost" function for the program. This is what Rapier does: Okay. So this is exactly what I needed. Working perfectly now. Thank you! I'm planning out a small Programs mod now. I was on the hunt for the perfect breaker to match with Seed. On the other hand, triggers still have some mystery about them. Question stands. Link to comment Share on other sites More sharing options...
Cyberboy2000 Posted May 12, 2017 Share Posted May 12, 2017 I'm guessing that your addCPUs function is not being called. You see, simplayer is not used in itself, it's only purpose is for pcplayer and aiplayer to inherit from. What this means is that if those two are loaded before your mod function, it will not cause any change to pcplayer and aiplayer, and in this case you are looking to change pcplayer. The difference between dispatchEvent() and triggerEvent() is that triggers can be used on any table as long as you can pass it to the sim, and events are only passed to hud and boardig (which in turn passes them to unitrigs). Only triggers can be used for gameplay purposes, events are for sound and visuals only. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.