-------------------------------------------------------------- -- Script on the Binoculars -- plays an animation, the cinematic and updates the achievement -- -- updated Brandi... 1/28/10 -- updated Brandi... 3/17/10 -- updated mrb... 5/5/10 -- removed some extra lines that were crashing occasionally -------------------------------------------------------------- --To set up -- each binocular cinamatic must be named "binoc_##" -- on each binocular, config data must be set for "number" and "0:##" -- ## should corrispond with the binocular being used, and the cinematic you want to play -- ## must be unique for the achievments to work, and there must be an entry for the binoc in the player flag -- database table if that binoc is to be used for the achievement -- Entries in the player plag table -- Should corraspond with the map number -- so all the binocs in the spaceship should start at 1001,1002,1003,etc... -- AG with 1101,1102,1103, etc... ------------------------------------------------------------------------ -- turning on the effects on the binoculars based on whether the player has looked through -- them before or not function onRenderComponentReady(self,msg) -- get the player local player = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) if not player:Exists() then -- tell the zone control object to tell the script when the local player is loaded self:SendLuaNotificationRequest{requestTarget = GAMEOBJ:GetZoneControlID() , messageName="PlayerReady"} return end -- custom function CheckFlags(self,player) end -- the zone control object says the player is loaded function notifyPlayerReady(self,zoneObj,msg) -- get the player local player = GAMEOBJ:GetObjectByID(GAMEOBJ:GetLocalCharID()) if not player:Exists() then return end -- custom function to see if the players flag is set CheckFlags(self,player) -- cancel the notification request self:SendLuaNotificationCancel{requestTarget=player, messageName="PlayerReady"} end function CheckFlags(self,player) local map = LEVEL:GetCurrentZoneID() local number = self:GetVar('number') -- get the number on the binoc config data from HF self:SetVar("beingUsed",false) -- set to check to keep the cinematic from being played again if number then --make sure the script doesnt fail if the binoc doesnt have config data local flagNumber = tonumber(string.sub(map,0,2)..number) --make player flag number if map then --skips the rest of the function if the map wasnt loaded enough to get the map number if (player:GetFlag{iFlagID = flagNumber}.bFlag == false) then --if the player flag is false, the player hasnt looked though the binocs before -- turn on the binocular effect self:PlayFXEffect{ name = "binocular_alert" , effectType = "cast" } end end end end --make binocular interactable and set the interact icon function onGetPriorityPickListType(self, msg) local myPriority = 0.8 if ( myPriority > msg.fCurrentPickTypePriority ) then msg.fCurrentPickTypePriority = myPriority msg.ePickType = 14 -- Interactive pick type end return msg end function onCheckUseRequirements(self, msg) --check to make sure the player isnt currently using the binoculars if self:GetVar("beingUsed") then msg.bCanUse = false return msg end end function onClientUse(self,msg) --SetUserCtrlCompPause crashs the game when used in this function, so i moved everything to a onTimerDone function to avoid crashes --not ideal, but it works GAMEOBJ:GetTimer():AddTimerWithCancel( 0.1, "startBinoc",self ) self:SetVar("beingUsed", true) end function onFireEventClientSide(self,msg) if msg.args == "achieve" then self:StopFXEffect{ name = "binocular_alert" } end end function onTimerDone (self,msg) if (msg.name == "startBinoc" ) then local oDir = self:GetRotation() --self:GetObjectDirectionVectors().forward local player = GAMEOBJ:GetControlledID() GAMEOBJ:GetTimer():AddTimerWithCancel( 0.5, "lookanimation",self ) player:SetStunned{StateChangeType = "PUSH", bCantMove = true, bIgnoreImmunity = true, bCantTurn = true, bCantEquip = true} player:SetRotation{ x = oDir.x , y = oDir.y, z =oDir.z , w=oDir.w} player:PlayAnimation{animationID = "binoculars-idle"} --temp animation while we wait for an animation of the player looking through the binoculars elseif (msg.name == "lookanimation") then -- animation is done, play the cinematic local player = GAMEOBJ:GetControlledID() local number = self:GetVar('number') local cineTime = 1 --set so even if the binoc doesnt have a cinematic assoicated with it yet, it will show a 1 sec cinematic if number then local soundName = self:GetVar('sound') -- grab the sound set in the config data of the binoc in HF -- let the script run even if there isnt config data, or doesnt have a cinematic path local cTime = tonumber(LEVEL:GetCinematicInfo("binoc_"..number)) if cTime then --play cinematic player:PlayCinematic { pathName = "binoc_"..number } cineTime = cTime end end player:SetStunned{StateChangeType = "POP", bCantMove = true, bIgnoreImmunity = true, bCantTurn = true, bCantEquip = true} UI:SendMessage( "pushGameState", {{"state", "cinematic" }} ) GAMEOBJ:GetTimer():AddTimerWithCancel( cineTime, "cinematicTimer",self ) --let the script run even if the sound config data if soundName then self:PlayNDAudioEmitter{m_NDAudioEventGUID = soundName} end elseif (msg.name == "cinematicTimer") then local player = GAMEOBJ:GetControlledID() UI:SendMessage( "popGameState", {{"state", "cinematic"}} ) player:PlayAnimation{animationID = "ben_is_king"} --reset animation player:TerminateInteraction{type = 'fromInteraction', ObjIDTerminator = self} self:SetVar("beingUsed",false) end end