-------------------------------------------------------------------------------------------------------- -- NOTE: -- If you would like to add flowers to a new level, -- then your server-side zone script will need to let the flowers know when a new player is loaded. -- That way the newly-loaded client will see the proper flower state. -- The zone script wouldn't need to be involved if there were a way for the client-side flower script -- to ask the server-side for the state. -- Currently we have FireEventServerSide to use from client to server scripts but are trying to avoid -- having something similar to use from server side to client side. -- So, we use the server-side zone script to let this script know when we have a new client. -- When adding flowers to a new level, the only place you need to make changes is in your server-side zone script. -- You can look at scripts\ai\YRK\L_SKUNK_EVENT.lua for an example. Search for FLOWERS. -- The code you need is also here for reference... -- Declare an array to hold the flower objects: --FLOWERS = {} -- onObjectLoaded will need to keep track of each flower loaded up: --if ( msg.templateID == 3646 ) then --local nextFlower = #FLOWERS + 1 --FLOWERS[nextFlower] = msg.objectID:GetID() --end -- onPlayerLoaded will need to tell each flower when a new player is loaded: --for flowerID = 1, #FLOWERS do --local flower = GAMEOBJ:GetObjectByID(FLOWERS[flowerID]) --flower:NotifyObject{ ObjIDSender = msg.playerID, name = "playerLoaded" } --end -------------------------------------------------------------------------------------------------------- CONSTANTS = {} CONSTANTS["SEEDLING"] = 0 CONSTANTS["GROWING_STEMS"] = 1 CONSTANTS["STEMS"] = 2 CONSTANTS["GROWING_BLOOMS"] = 3 CONSTANTS["BLOOMS"] = 4 CONSTANTS["WILTING"] = 5 CONSTANTS["TIME_BEFORE_WILTING"] = 30 -- if the blooms are left unwatered for this long, the flower wilts function onStartup(self) -- print( "--------------------------------------" ) --print( "FLOWER: onStartup") --print( "--------------------------------------" ) -- remember how long each of the anims is local animLength = self:GetAnimationTime{ animationID = "stalk" }.time self:SetVar( "ANIM_LENGTH_GROW_STEMS", animLength ) local animLength = self:GetAnimationTime{ animationID = "petals" }.time self:SetVar( "ANIM_LENGTH_GROW_BLOOMS", animLength ) local animLength = self:GetAnimationTime{ animationID = "wilt" }.time self:SetVar( "ANIM_LENGTH_WILT", animLength ) -- start out as the seedling ( stud shape ) -- note: for each client, the initial anim will be started by the client-side script, based on the current state ResetWaterFlags( self ) self:SetVar( "growthState", CONSTANTS["SEEDLING"] ) -- let the zone script know this is loaded GAMEOBJ:GetZoneControlID():ObjectLoaded{ objectID = self, templateID = self:GetLOT().objtemplate } end function onTimerDone( self, msg ) --print( "--------------------------------------" ) --print( "FLOWER: onTimerDone: " .. msg.name ) --print( "--------------------------------------" ) -- if the anim of the stems growing just finished, go to stems state -- unless they watered again while the stems anim was playing, then start up the anim of the blooms growing if (msg.name == "stemsAnimTimer") then if ( self:GetVar( "wateredWhileGrowingStems" ) == true ) then GrowBlooms( self ) else ShowStems( self ) end end -- if the anim of the blooms growing just finished, go to the blooms state -- and start the timer for when to wilt if (msg.name == "bloomsAnimTimer") then ShowBlooms( self ) end -- if the blooms have been too long without watering, wilt if (msg.name == "bloomToWiltTimer") then WiltFlower( self ) end -- if the wilt anim just finished, go back to seedling state -- unless they watered it while the wilt anim was playing, then start up the anim of the stems growing if (msg.name == "wiltAnimTimer") then if ( self:GetVar( "wateredWhileWilting" ) == true ) then GrowStems( self ) else ShowSeedling( self ) end end end function onSquirtWithWatergun( self, msg ) --print( "--------------------------------------" ) --print( "FLOWER: onSquirtWithWatergun" ) --print( "--------------------------------------" ) -- if it's a seedling, grow it up into a stem if ( self:GetVar( "growthState" ) == CONSTANTS["SEEDLING"] ) then GrowStems( self ) -- updates flower watering achievements and gives coins --this is hacky and not the right way we should be doing this, but it works, non the less -- Using the "Kill" mission type in the DB, we are able to update the mission through the objects by calling --the "kill" tasktype with calues of one. The downfall is that this will only allow one mission on the designated objects that --use the kill type. The commented out updatemissiontask functions are the way we should be doing this but is broken. msg.shooterID:UpdateMissionTask {target = self, value = 1, value2 = 1, taskType = "kill"} -- msg.shooterID:UpdateMissionTask {target = self, value = 143, value2 = 1, taskType = "complete"} -- msg.shooterID:UpdateMissionTask {target = self, value = 152, value2 = 1, taskType = "complete"} -- msg.shooterID:UpdateMissionTask {target = self, value = 153, value2 = 1, taskType = "complete"} local currencyMsg = self:RollCurrency{iTable = 1, iLevel = 1} self:DropLoot{iCurrency = currencyMsg.iCurrency, owner = msg.shooterID, rerouteID = msg.shooterID, sourceObj = self} return end -- if it's growing the stems, remember to grow the blooms as soon as the stalk finishes if ( self:GetVar( "growthState" ) == CONSTANTS["GROWING_STEMS"] ) then self:SetVar( "wateredWhileGrowingStems", true ) -- updates flower watering achievements and gives coins --this is hacky and not the right way we should be doing this, but it works, non the less -- Using the "Kill" mission type in the DB, we are able to update the mission through the objects by calling --the "kill" tasktype with calues of one. The downfall is that this will only allow one mission on the designated objects that --use the kill type. The commented out updatemissiontask functions are the way we should be doing this but is broken. msg.shooterID:UpdateMissionTask {target = self, value = 1, value2 = 1, taskType = "kill"} -- msg.shooterID:UpdateMissionTask {target = self, value = 143, value2 = 1, taskType = "complete"} -- msg.shooterID:UpdateMissionTask {target = self, value = 152, value2 = 1, taskType = "complete"} -- msg.shooterID:UpdateMissionTask {target = self, value = 153, value2 = 1, taskType = "complete"} local currencyMsg = self:RollCurrency{iTable = 1, iLevel = 1} self:DropLoot{iCurrency = currencyMsg.iCurrency, owner = msg.shooterID, rerouteID = msg.shooterID, sourceObj = self} return end -- if it's already the stems, grow the blooms if ( self:GetVar( "growthState" ) == CONSTANTS["STEMS"] ) then GrowBlooms( self ) -- updates flower watering achievements and gives coins --this is hacky and not the right way we should be doing this, but it works, non the less -- Using the "Kill" mission type in the DB, we are able to update the mission through the objects by calling --the "kill" tasktype with calues of one. The downfall is that this will only allow one mission on the designated objects that --use the kill type. The commented out updatemissiontask functions are the way we should be doing this but is broken. msg.shooterID:UpdateMissionTask {target = self, value = 1, value2 = 1, taskType = "kill"} --msg.shooterID:UpdateMissionTask {target = self, value = 143, value2 = 1, taskType = "complete"} --msg.shooterID:UpdateMissionTask {target = self, value = 152, value2 = 1, taskType = "complete"} --msg.shooterID:UpdateMissionTask {target = self, value = 153, value2 = 1, taskType = "complete"} local currencyMsg = self:RollCurrency{iTable = 1, iLevel = 1} self:DropLoot{iCurrency = currencyMsg.iCurrency, owner = msg.shooterID, rerouteID = msg.shooterID, sourceObj = self} return end -- if it's growing the blooms, then ignore the water because -- the wilt time isn't set until the blooms finish growing anyways -- if it's already blooming, extend the time before it wilts if ( self:GetVar( "growthState" ) == CONSTANTS["BLOOMS"] ) then ResetWiltTime( self ) return end -- if it's wilting, remember to grows the stems back again once the wilt anim finishes if ( self:GetVar( "growthState" ) == CONSTANTS["WILTING"] ) then self:SetVar( "wateredWhileWilting", false ) return end end function ResetWaterFlags( self ) self:SetVar( "wateredWhileGrowingStems", false ) self:SetVar( "wateredWhileWilting", false ) end function ShowSeedling( self ) --print( "--------------------------------------" ) --print( "FLOWER: ShowSeedling" ) --print( "--------------------------------------" ) ResetWaterFlags( self ) self:SetVar( "growthState", CONSTANTS["SEEDLING"] ) self:PlayAnimation{ animationID = "idle-stud" } end function GrowStems( self ) --print( "--------------------------------------" ) --print( "FLOWER: GrowStems" ) --print( "--------------------------------------" ) self:SetVar( "growthState", CONSTANTS["GROWING_STEMS"] ) self:PlayAnimation{ animationID = "stalk" } GAMEOBJ:GetTimer():AddTimerWithCancel( self:GetVar( "ANIM_LENGTH_GROW_STEMS" ), "stemsAnimTimer", self ) end function ShowStems( self ) --print( "--------------------------------------" ) --print( "FLOWER: ShowStems" ) --print( "--------------------------------------" ) ResetWaterFlags( self ) self:SetVar( "growthState", CONSTANTS["STEMS"] ) self:PlayAnimation{ animationID = "idle-stem" } end function GrowBlooms( self ) --print( "--------------------------------------" ) --print( "FLOWER: GrowBlooms" ) --print( "--------------------------------------" ) self:SetVar( "growthState", CONSTANTS["GROWING_BLOOMS"] ) self:PlayAnimation{ animationID = "petals" } GAMEOBJ:GetTimer():AddTimerWithCancel( self:GetVar( "ANIM_LENGTH_GROW_BLOOMS" ), "bloomsAnimTimer", self ) end function ShowBlooms( self ) --print( "--------------------------------------" ) --print( "FLOWER: ShowBlooms" ) --print( "--------------------------------------" ) ResetWaterFlags( self ) self:SetVar( "growthState", CONSTANTS["BLOOMS"] ) self:PlayAnimation{ animationID = "idle-flowers" } GAMEOBJ:GetTimer():AddTimerWithCancel( CONSTANTS["TIME_BEFORE_WILTING"], "bloomToWiltTimer", self ) end function WiltFlower( self ) --print( "--------------------------------------" ) --print( "FLOWER: WiltFlower" ) --print( "--------------------------------------" ) self:SetVar( "growthState", CONSTANTS["WILTING"] ) self:PlayAnimation{ animationID = "wilt" } GAMEOBJ:GetTimer():AddTimerWithCancel( self:GetVar( "ANIM_LENGTH_WILT" ), "wiltAnimTimer", self ) end function ResetWiltTime( self ) --print( "--------------------------------------" ) --print( "FLOWER: ResetWiltTime" ) --print( "--------------------------------------" ) GAMEOBJ:GetTimer():CancelTimer( "bloomToWiltTimer", self ) GAMEOBJ:GetTimer():AddTimerWithCancel( CONSTANTS["TIME_BEFORE_WILTING"], "bloomToWiltTimer", self ) end -------------------------------------------------------------- -- Notification to object -------------------------------------------------------------- function onNotifyObject( self, msg ) if ( msg.name == "playerLoaded" ) then -- tell the client-side script for the just-loaded player to use the appropriate anim based on the flower's status self:NotifyClientRebuildSectionState{ rerouteID = msg.ObjIDSender, iState = self:GetVar( "growthState" ) } end end