-------------------------------------------------------------- -- Foot Race Goal script that the player will trigger. -- updated mrb... 1/14/10 -------------------------------------------------------------- local goalLot = 3890 -- 2691 local goalObjOffset = 5.2 -- how far right and left of the object to spawn in the goal posts. local nextEffectID = 503 local nextEffectType = "create" function onStartup(self) self:SetVisible{visible = false, fadeTime = 0} self:AddObjectToGroup{group = 'Goals_' .. self:GetVar('spawner_node_id') + 1} self:SetVar('NextGoal', 1) GAMEOBJ:GetTimer():AddTimerWithCancel(0.5, "spawnGoals", self ) end function onChildRenderComponentReady(self,msg) if self:GetVar('spawner_node_id') == 0 then GAMEOBJ:GetTimer():AddTimerWithCancel(2, "Play_Goal_Post_Effect", self ) end end function spawnGoalPosts(self) local oPos = {pos = self:GetPosition().pos} local gOffset = goalObjOffset --* self:GetObjectScale().scale local posOffset = -gOffset local oDir = self:GetObjectDirectionVectors() oPos.rot = self:GetRotation() local config = { {"groupID", "GoalPosts;Goals_" .. self:GetVar('spawner_node_id') + 1} } for i=1, 2 do --print('spawnGoalPost ' .. i .. ' @ ' .. posOffset) local newOffset = {x = oPos.pos.x + (oDir.right.x * posOffset), y = oPos.pos.y, z = oPos.pos.z + (oDir.right.z * posOffset)} RESMGR:LoadObject{ objectTemplate = goalLot, x= newOffset.x, y= newOffset.y , z= newOffset.z, rw = oPos.rot.w, rx = oPos.rot.x, ry = oPos.rot.y, rz = oPos.rot.z, owner = self, configData = config} posOffset = gOffset end end function PlayActiveEffect(self) local activeNode = self:GetVar('NextGoal') local nextObjs = self:GetObjectsInGroup{ group = 'Goals_' .. activeNode, ignoreSpawners = true }.objects for k,v in ipairs(nextObjs) do if v:GetID() ~= self:GetID() then v:PlayFXEffect{name = "ActiveEffect", effectType = nextEffectType, effectID = nextEffectID} end end end function onCollisionPhantom(self, msg) if not self:GetVar('isTriggered') then local nodeNum = self:GetVar('spawner_node_id') + 1 local activeNode = self:GetVar('NextGoal') if not activeNode then --print('activeNode = 1') activeNode = 1 end print(nodeNum .. ' ' .. activeNode) if nodeNum ~= activeNode then return end local nodeTotal = self:GetNetworkVar('total_spawner_nodes') local displayText = 'Good Job! You get 10 more seconds' --print('collided with node ' .. nodeNum .. ' out of ' .. nodeTotal) if nodeNum == 1 then displayText = 'First Goal! You get 10 more seconds' elseif nodeNum == nodeTotal then displayText = 'Final Goal! You won!!!' local mgr = self:GetObjectsInGroup{ group = 'Foot_Race_Mgr', ignoreSpawners = true }.objects[1] if mgr then mgr:FireEventServerSide{senderID = msg.objectID, args = 'Player_Won'} else print('missing Foot_Race_Mgr') end end local tGoalObjs = self:GetObjectsInGroup{ group = 'Goals', ignoreSpawners = true }.objects for k,v in ipairs(tGoalObjs) do v:SetVar('NextGoal', nodeNum + 1) --print(k .. ' out of ' .. #tGoalObjs) end msg.objectID:DisplayTooltip{ bShow = true, strText = displayText, iTime = 1 } self:SetVar('isTriggered', true) local killObjs = self:GetObjectsInGroup{ group = 'Goals_' .. nodeNum, ignoreSpawners = true }.objects for k,v in ipairs(killObjs) do --print('kill dem all ' .. k) GAMEOBJ:DeleteObject( v ) --unccomment this when testing/developement is done to remove object that is no longer needed. end PlayActiveEffect(self) end end function onTimerDone(self, msg) if msg.name == "spawnGoals" then spawnGoalPosts(self) elseif msg.name == "Play_Goal_Post_Effect" then PlayActiveEffect(self) end end