DoktorHolmes Posted May 3, 2016 Share Posted May 3, 2016 Hello everyone, I have a question which should be quite easy to answer, and yet I cannot seem to find the answer anywhere. My question is this: How do I reference a player who activated an object with the activatable component? I simply cannot find a variable that references the user of an object. The problem lies in my file maxwellthrone.lua, in the line inst.components.activatable.OnActivate = inst.components.throne:makeNewKing() This line pretty much screws up the rest of the code as I do not know what to place in the brackets at the end. Whatever I try based on the activatable.lua component simply references the object itself. If you would like to see my full code, here it is: maxwellthrone.lua local assets = { Asset("ANIM", "anim/maxwell_throne.zip"), Asset("SOUND", "sound/sanity.fsb"), Asset("SOUND", "sound/common.fsb"), Asset("SOUND", "sound/wilson.fsb") } local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() local shadow = inst.entity:AddDynamicShadow() inst.entity:AddNetwork() shadow:SetSize( 3, 2 ) anim:SetBank("throne") anim:SetBuild("maxwell_throne") anim:PlayAnimation("idle") inst:AddTag("maxwellthrone") inst:AddComponent("inspectable") inst:AddComponent("activatable") inst:AddComponent("throne") inst.components.activatable.OnActivate = inst.components.throne:makeNewKing() return inst end return Prefab( "common/characters/maxwellthrone", fn, assets, prefabs) throne.lua local throne = Class(function(self, inst) self.inst = inst end) function fn(inst) inst:AddComponent("throneruler") inst.components.throneruler.makeKing() end function throne:removeOldKings(inst) if inst.components.throneruler.isKing then c_despawn(inst) end end function throne:makeNewKing(pl) for k,v in pairs(AllPlayers) do throne:removeOldKings(v) end pl:AddComponent("throneruler") pl.components.throneruler:makeKing() end return throne throneruler.lua throneruler = Class(function(self, inst, isKing) self.inst = inst end) function throneruler:makeKing(inst) inst.components.builder:GiveAllRecipes() inst.components.health:SetMaxHealth(1000) inst.components.sanity:SetMax(2000) inst.components.hunger:Pause(true) end return throneruler Link to comment Share on other sites More sharing options...
Aquaterion Posted May 3, 2016 Share Posted May 3, 2016 inst.components.activatable.OnActivate = function(inst, doer) inst.components.throne:makeNewKing(doer) end the above should work, if not local function onactivate(inst, doer) inst.components.throne:MakeNewKing(doer) end inst.components.activatable.OnActivate = onactivate Link to comment Share on other sites More sharing options...
DoktorHolmes Posted May 3, 2016 Author Share Posted May 3, 2016 Thank you so much! It works perfectly. Kudos to you, good sir! One final question - what is the name of the event that is pushed when a new day occurs? TY! Link to comment Share on other sites More sharing options...
Muche Posted May 4, 2016 Share Posted May 4, 2016 3 hours ago, DoktorHolmes said: One final question - what is the name of the event that is pushed when a new day occurs? TY! I believe it's phasechanged (with parameter "day") from components/clock|OnUpdate(). Also there is inst:WatchWorldState("startday", fn) and/or inst:WatchWorldState("startcaveday", fn). Link to comment Share on other sites More sharing options...
DoktorHolmes Posted May 4, 2016 Author Share Posted May 4, 2016 19 hours ago, Muche said: I believe it's phasechanged (with parameter "day") from components/clock|OnUpdate(). Also there is inst:WatchWorldState("startday", fn) and/or inst:WatchWorldState("startcaveday", fn). Thank you kindly! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now