--if debug.server then -- debug.server("startpaused", 27726) -- print('kore start') --end -------------------------------------------------------------- -- Generic Survival Instance Client Zone Script: Including this -- file gives the custom functions for the Survival game. -- Updated mrb... 1/7/10 -------------------------------------------------------------- -------------------------------------------------------------- -- Includes -------------------------------------------------------------- require('o_mis') require('ai/L_ACTIVITY_MANAGER') --////////////////////////////////////////////////////////////////////////////////// -- local variables local teamScoreBoard = {} --------------------------------------------------------------- -- Startup of the object ----------------------------------------------------------------. function onStartup(self, msg) --print('set WaveUI state') UI:SendMessage( "pushGameState", {{"state", "WaveUI" }} ) end function checkScoreBoardTable(tScoreBoard, bRemoveTable) local t = teamScoreBoard local tTemp = {} local isUsed = false for k,v in ipairs(teamScoreBoard) do if v.nameVar ~= "No Player" and v.nameVar ~= tScoreBoard.nameVar and v.nameVar ~= '' then table.insert(tTemp,v) --print('add old player to used table ' .. v.nameVar) end if v.nameVar == tScoreBoard.nameVar and bRemoveTable then isUsed = true end end if not isUsed then table.insert(tTemp,tScoreBoard) --print('add new player to used table ' .. tScoreBoard.nameVar) end table.sort(tTemp, function(a,b) return a.nameVarb.smashVar end) table.sort(tTemp, function(a,b) return a.timeVar>b.timeVar end) while table.maxn(tTemp) < 4 do --tVaule = tValue + 1 table.insert(tTemp, { nameVar = "No Player", timeVar = 0, scoreVar = 0, smashVar = 0}) end --print('***************') --for k,v in ipairs(t) do -- print('*** player ' .. k .. ' ***') -- print(t[k].nameVar .. ' time: ' .. t[k].timeVar .. ' score: ' .. t[k].scoreVar .. ' smash: ' .. t[k].smashVar) -- print('***************') --end return tTemp end function SecondsToClock(sSeconds) local nSeconds = tonumber(sSeconds) if nSeconds == 0 or nSeconds == nil then return "00:00"; --return "00:00:00"; else nHours = string.format("%02.f", math.floor(nSeconds/3600)); nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours*60))); nSecs = string.format("%02.f", math.floor(nSeconds - nHours*3600 - nMins *60)); return nMins..":"..nSecs --return nHours..":"..nMins..":"..nSecs end end function numToString(iNum) if iNum == 0 or iNum == nil then return "**" end return tostring(iNum) end function showScoreBoard(self) p = teamScoreBoard if not p then print('missing scoreboard data') return end --for k,v in ipairs(p) do print(p[k].nameVar) end UI:SendMessage( "pushGameState", {{"state", "WaveUI" }} ) -- Hide timer ui UI:SendMessage( "TimedUI", {{"ishow", false }}) -- Show UI UI:SendMessage("UI_Wave", { { "waveui", "show" }, { "p1_check", "hide" }, -- checkmarks { "p2_check", "hide" }, { "p3_check", "hide" }, { "p4_check", "hide" }, { "p1_name", p[1].nameVar }, -- names { "p2_name", p[2].nameVar }, { "p3_name", p[3].nameVar }, { "p4_name", p[4].nameVar }, { "p1_time", SecondsToClock(p[1].timeVar) }, -- times { "p2_time", SecondsToClock(p[2].timeVar) }, { "p3_time", SecondsToClock(p[3].timeVar) }, { "p4_time", SecondsToClock(p[4].timeVar) }, { "p5_time", SecondsToClock(p[1].timeVar) }, { "p1_smash", numToString(p[1].smashVar) }, -- smash { "p2_smash", numToString(p[2].smashVar) }, { "p3_smash", numToString(p[3].smashVar) }, { "p4_smash", numToString(p[4].smashVar) }, { "p5_smash", numToString(p[1].smashVar + p[3].smashVar + p[2].smashVar + p[4].smashVar) }, { "p1_score", numToString(p[1].scoreVar) }, -- score { "p2_score", numToString(p[2].scoreVar) }, { "p3_score", numToString(p[3].scoreVar) }, { "p4_score", numToString(p[4].scoreVar) }, { "p5_score", numToString(p[1].scoreVar + p[3].scoreVar + p[2].scoreVar + p[4].scoreVar) }} ) end function PlayerConfirm(self, playerID) local playerNum = "" for k,v in ipairs(teamScoreBoard) do --print('my name is ' .. teamScoreBoard[k].nameVar) if playerID:GetName().name == teamScoreBoard[k].nameVar then playerNum = tostring(k) end end UI:SendMessage("UI_Wave", {{"p" .. playerNum .. "_check", "show" }} ) end function setTeamUI(self) local num = #self:MiniGameGetTeamPlayers{teamID = 1}.objects --print('set team ui') if num > 1 then for i = 1, #self:MiniGameGetTeamPlayers{teamID = 1}.objects do local player = self:MiniGameGetTeamPlayers{teamID = 1}.objects[i] if i == 1 then player:TeamAddPlayerMsg{name = self:MiniGameGetTeamPlayers{teamID = 1}.objects[1], bIsLeader = true} end player:TeamAddPlayerMsg{name = self:MiniGameGetTeamPlayers{teamID = 1}.objects[1]} player:RequestTeamUIUpdate{} end end end function freezePlayer(self, bFreeze) local playerID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) local eChangeType = "POP" if bFreeze then if playerID:IsDead().bDead then --print('frozen') GAMEOBJ:GetTimer():AddTimerWithCancel( 0.1 , "Try_Freeze_Again", self ) return end eChangeType = "PUSH" end playerID:SetStunned{ StateChangeType = eChangeType, bCantMove = true, bCantAttack = true, bCantInteract = true } --print('Player ' .. playerID:GetName().name .. ' ' .. eChangeType .. ' is frozen: ' .. tostring(self:GetVar('frozen')) .. ' ' .. tostring(playerID:GetStunned().bCanMove)) if playerID:GetStunned().bCanMove and eChangeType == "PUSH" then print(playerID:GetName().name .. ' is still able to move') GAMEOBJ:GetTimer():AddTimerWithCancel( 0.1, "Try_Freeze_Again", self ) end end function onNotifyClientZoneObject(self, msg) if msg.name == "SetGameState" then --print(UI:CallService{"getCurrentGameState"}) --print('Should have sent the current gamestate') UI:SendMessage( "pushGameState", {{"state", "WaveUI" }} ) elseif msg.name == "Start_Timer" then -- add ui timer UI:SendMessage( "TimedUI", {{"ishow", true }, {"itime", "00:00"}} ) --UI:SendMessage( "ToggleGenericTextField", {{"visible", false }}) elseif msg.name == "Update_Timer" then UI:SendMessage( "TimedUI", {{"ishow", true }, {"itime", SecondsToClock( msg.param1 ) } }) --UI:SendMessage( "ToggleGenericTextField", {{"visible", false }}) elseif msg.name == "Update_Default_Start_Timer" then --UI:SendMessage( "ToggleGenericTextField", {{"visible", true }, {"text", "Starts: " .. msg.param1 } }) UI:SendMessage( "UI_Wave", {{"countdownTime", msg.param1 }} ) elseif msg.name == "Kill_Default_Start_Timer" then --print('Kill Default Start Timer') --UI:SendMessage( "ToggleGenericTextField", {{"visible", false }}) UI:SendMessage( "UI_Wave", {{"countdownTime", " " }} ) elseif msg.name == "Kill_Timer" then -- remove ui timer UI:SendMessage( "TimedUI", {{"ishow", false }} ) --UI:SendMessage( "ToggleGenericTextField", {{"visible", false }}) elseif msg.name == "Reset_Timer" then -- remove ui timer UI:SendMessage( "TimedUI", {{"ishow", false }, {"itime", "00:00"}} ) UI:SendMessage( "UI_Wave", {{"p1_check", "hide" }, {"p2_check", "hide" }, {"p3_check", "hide" }, {"p4_check", "hide" }} ) --teamScoreBoard = {} elseif msg.name == "Wave_Message" then UI:SendMessage( "ToggleGenericTextField", {{"visible", true }, {"text", "Wave: " .. msg.paramStr } }) elseif msg.name == "Start_Wave_Message" then GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()):ShowActivityCountdown() UI:SendMessage( "TimedUI", {{"ishow", true }, {"itime", "00:00"}} ) setTeamUI(self) freezePlayer(self) --print(GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()):GetName().name) --UI:SendMessage( "ToggleGenericTextField", {{"visible", true }, {"text", msg.paramStr } }) elseif msg.name == "Define_Player_To_UI" then local playerID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) -- add player to the ui UI:SendMessage( "UI_Wave", {{"user", msg.paramObj }} ) -- set player to auto-respawn playerID:SetPlayerAllowedRespawn{dontPromptForRespawn=true} elseif msg.name == "Update_ScoreBoard" then --print('update player') local tempTable = { nameVar = msg.paramObj:GetName().name, timeVar = msg.param1, scoreVar = tonumber(msg.paramStr), smashVar = msg.param2} teamScoreBoard = checkScoreBoardTable(tempTable) elseif msg.name == "Show_ScoreBoard" then local playerID = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) --print(msg.paramStr .. ' ' .. playerID:GetID()) playerID:RequestTeamUIUpdate{} showScoreBoard(self) if msg.paramStr == playerID:GetID() then freezePlayer(self, true) end elseif msg.name == "PlayerConfirm_ScoreBoard" then PlayerConfirm(self, msg.paramObj) elseif msg.name == "Kill_ScoreBoard" then local player = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) --player:SetUserCtrlCompPause{bPaused = false} UI:SendMessage("UI_Wave", {{"waveui", "hide" }}) teamScoreBoard = {} elseif msg.name == "Exit_Waves" then local tempTable = { nameVar = msg.paramObj:GetName().name, timeVar = msg.param1, scoreVar = tonumber(msg.paramStr), smashVar = msg.param2} --UI:SendMessage( "ToggleGenericTextField", {{"visible", false }}) UI:SendMessage( "UI_Wave", {{"countdownTime", " " }} ) if GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()):GetName().name == tempTable.nameVar then UI:SendMessage("UI_Wave", {{"waveui", "hide" }}) UI:SendMessage( "popGameState", {{"state", "WaveUI"}} ) return end --print('remove player ' .. tempTable.nameVar) msg.paramObj:TeamRemovePlayerMsg{name = 'SurvivalTeam'} teamScoreBoard = checkScoreBoardTable(tempTable, true) showScoreBoard(self) end end ---------------------------------------------------------------- -- Sent from a player when responding from a messagebox ---------------------------------------------------------------- function onMessageBoxRespond(self, msg) -- Response to Exit activity dialog and user pressed OK if msg.identifier == "exit_screen" and msg.iButton == 1 then -- restart waves self:FireEventServerSide{senderID = msg.sender, args = 'start'} -- Response to Start activity dialog and ok is pressed and player is not in activity elseif msg.identifier == "exit_screen" and msg.iButton == 0 then -- remove ui timer UI:SendMessage( "TimedUI", {{"ishow", false }} ) -- exit instance self:FireEventServerSide{senderID = msg.sender, args = 'exit'} end end function onSendActivitySummaryLeaderboardData(self, msg) --print('Activity Summary Sent to client Zone') if (msg) then self:SetVar("HoldingTopScore", false) local player = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) local MaxCount = msg.leaderboardData["Result[0].RowCount"] n = 1 b = 1 q = 1 d = 1 tableValues = {} storedScore = {} finalTable = {} name_value = 0 score_value = 0 name = 0 score = 0 for i = 0, MaxCount do tableValues[(n)] = msg.leaderboardData["Result[0].Row["..i.."].name"] n = n + 1 tableValues[(n)] = msg.leaderboardData["Result[0].Row["..i.."].Score"] n = n + 1 if msg.leaderboardData["Result[0].Row["..i.."].Relationship"] then if msg.leaderboardData["Result[0].Row["..i.."].Relationship"] ~= 0 then self:SetVar("FoundFriendGuild", true ) end end end self:SetVar("LeaderTable", tableValues) wtf = implode(",",self:GetVar("LeaderTable")) self:SetVar("LeaderString", wtf) UI:SendMessage("TimedUI", { {"inextbestname", wtf} } ) for j = 1, #tableValues do if tableValues[j] == player:GetName().name then name = j score = (j + 1) if name ~= 1 then name_value = (j - 2) score_value = (j - 1) elseif name_value == 3 then name_value = 1 score_value = 2 elseif j == 1 then name_value = 1 score_value = 2 end self:SetVar("FoundPlayer", true ) break end end self:SetVar("name",name ) self:SetVar("score",score ) self:SetVar("tableValues",tableValues ) self:SetVar("name_value",name_value ) self:SetVar("score_value",score_value ) local uiName = tostring(tableValues[ self:GetVar("name")]) local uiScore = SecondsToClock(tableValues[self:GetVar("score")]) if uiName == 'nil' then uiName = player:GetName().name --print('name was nil adding in player name: ' .. uiName) end if self:GetVar("FoundPlayer") and self:GetVar("FoundFriendGuild") then UI:SendMessage("TimedUI", { {"inextbesttime", SecondsToClock(tableValues[score_value]) }, {"inextbestname", tostring(tableValues[name_value]) } } ) --print('Found Player and found Friend') else UI:SendMessage("TimedUI", { {"inextbesttime", uiScore }, {"inextbestname", uiName } } ) --print('Did not Friend using default') end UI:SendMessage("TimedUI", { {"iplayerName", uiName} } ) self:SetVar("NextBest", uiScore ) end end function onTimerDone(self, msg) if msg.name == "Try_Freeze_Again" then freezePlayer(self, true) end end