zUsername Posted July 20, 2015 Share Posted July 20, 2015 With Don't Starve we can use: GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40)But in DST how to use this?I'm starting to learn how to create MOD yesterday. And I'm not good at English.So hope everyone will understand what I said . Thanks in advance. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/ Share on other sites More sharing options...
DarkXero Posted July 20, 2015 Share Posted July 20, 2015 All player prefabs havelocal function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist)player.ShakeCamera = ShakeCameraSo for example,-- source inst = deerclops entityfor k, v in pairs(AllPlayers) do v:ShakeCamera(CAMERASHAKE.SIDE, .5, .05, .1, inst, 40)endTo reference concrete players you will need to get the concrete player via the targeting of whatever you are managing. A player can reference himself via using ThePlayer, instead of GetPlayer. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655831 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 All player prefabs havelocal function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist)player.ShakeCamera = ShakeCameraSo for example,-- source inst = deerclops entityfor k, v in pairs(AllPlayers) do v:ShakeCamera(CAMERASHAKE.SIDE, .5, .05, .1, inst, 40)endTo reference concrete players you will need to get the concrete player via the targeting of whatever you are managing. A player can reference himself via using ThePlayer, instead of GetPlayer. I'm put the code to modmain and error: "CAMERASHAKE.SIDE nil value".And I try to take the code from "camerashake.lua" then put to my modmain and new error come: local SIDE = { -------------------------------------------------------------------------- -- 0 S 1 -------------------------------------------------------------------------- GLOBAL.Vector3(-1, 0):GetNormalized(), GLOBAL.Vector3( 1, 0):GetNormalized(), },COROUTINE 100363 SCRIPT CRASH:[string "scripts/prefabs/player_common.lua"]:1065: calling 'set_local' on bad self (number expected, got table)LUA ERROR stack traceback: =[C] in function 'set_local' scripts/prefabs/player_common.lua(1065,1) in function 'ShakeCamera' ../mods/Auto Planting DST/modmain.lua(77,1) [00:00:36]: COROUTINE 100363 SCRIPT CRASH:[string "scripts/prefabs/player_common.lua"]:1065: calling 'set_local' on bad self (number expected, got table)LUA ERROR stack traceback: =[C] in function 'set_local' scripts/prefabs/player_common.lua(1065,1) in function 'ShakeCamera' ../mods/Auto Planting DST/modmain.lua(77,1)[00:00:36]: COROUTINE 100363 SCRIPT CRASH:[string "scripts/prefabs/player_common.lua"]:1065: calling 'set_local' on bad self (number expected, got table)LUA ERROR stack traceback: =[C] in function 'set_local' scripts/prefabs/player_common.lua(1065,1) in function 'ShakeCamera' ../mods/Auto Planting DST/modmain.lua(77,1) [00:00:36]: SCRIPT ERROR! Showing error screen [00:00:52]: Force aborting...And line 77 mine is:GLOBAL.ThePlayer:ShakeCamera(SIDE, .5, .05, .1, inst, 40) Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655839 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 Okay. Fixed.Just use this code: GLOBAL.ThePlayer:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, .25, inst, 40)Big thanks to DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655861 Share on other sites More sharing options...
DarkXero Posted July 20, 2015 Share Posted July 20, 2015 GLOBAL.ThePlayer Warning.That will only shake the host if the code is ran server side. ThePlayer will only reference clients if ran client side.(e.g using a netvar and making the client shake his screen based on the change) Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655916 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 Warning.That will only shake the host if the code is ran server side. ThePlayer will only reference clients if ran client side.(e.g using a netvar and making the client shake his screen based on the change) Thanks you for warning. But I don't know how to use netvar . Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655920 Share on other sites More sharing options...
DarkXero Posted July 20, 2015 Share Posted July 20, 2015 That's why I usedlocal inst = GLOBAL.SpawnPrefab("deerclops") -- example, entity is sourcefor k, v in pairs(GLOBAL.AllPlayers) do v:ShakeCamera(CAMERASHAKE.SIDE, .5, .05, .1, inst, 40)endSo you loop through AllPlayers, pick each player entity v by v, and shake their cameras. Else, you have to get the other player entities via context.Or via a function that returns the closest player to the entity that shakes the screen. For example, the spear has a functionlocal function onunequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal")endwhere inst is the spear, and owner is the player. So you put owner:ShakeCamera. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655922 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 That's why I usedlocal inst = GLOBAL.SpawnPrefab("deerclops") -- example, entity is sourcefor k, v in pairs(GLOBAL.AllPlayers) do v:ShakeCamera(CAMERASHAKE.SIDE, .5, .05, .1, inst, 40)endSo you loop through AllPlayers, pick each player entity v by v, and shake their cameras. Else, you have to get the other player entities via context.Or via a function that returns the closest player to the entity that shakes the screen. For example, the spear has a functionlocal function onunequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal")endwhere inst is the spear, and owner is the player. So you put owner:ShakeCamera. One more question. I want to Shake camera all player are in range so what function to get distance from inst to player.Thanks you. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655943 Share on other sites More sharing options...
DarkXero Posted July 20, 2015 Share Posted July 20, 2015 Well, to check for distances you havefor k, v in pairs(GLOBAL.AllPlayers) do -- v is a player entity -- inst is a source entity, another thing, like a deerclops -- distance is within 5 if v:GetDistanceSqToInst(inst) < (5 * 5) then v:ShakeCamera(GLOBAL.CAMERASHAKE.SIDE, .5, .05, .1, inst, 40) endendGetDistanceSqToInst gives the distance squared. So you either give another squared distance to compare or use math.sqrt. Still, pay attentionlocal function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist), maxDist)that's the parameter to adjust the max distance. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655951 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 (edited) Well, to check for distances you havefor k, v in pairs(GLOBAL.AllPlayers) do -- v is a player entity -- inst is a source entity, another thing, like a deerclops -- distance is within 5 if v:GetDistanceSqToInst(inst) < (5 * 5) then v:ShakeCamera(GLOBAL.CAMERASHAKE.SIDE, .5, .05, .1, inst, 40) endendGetDistanceSqToInst gives the distance squared. So you either give another squared distance to compare or use math.sqrt. Still, pay attentionlocal function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist), maxDist)that's the parameter to adjust the max distance. I have the original code like this:GLOBAL.ThePlayer:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, .25, inst, 40)So now I use this:for k, v in pairs(GLOBAL.AllPlayers) do -- v is a player entity -- inst is a source entity, another thing, like a deerclops -- distance is within 5 if v:GetDistanceSqToInst(inst) < (40 * 40) then v:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, .25, inst, 40) endendIt's mean all player in range 40 will shake camera right? Edited July 20, 2015 by zUsername Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655965 Share on other sites More sharing options...
DarkXero Posted July 20, 2015 Share Posted July 20, 2015 (edited) This is the function of player_common:local function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist) if source ~= nil and maxDist ~= nil then local distSq = inst:GetDistanceSqToInst(source) local k = math.max(0, math.min(1, distSq / (maxDist * maxDist))) scale = easing.outQuad(k, scale, -scale, 1) end --normalize for net_byte duration = math.floor((duration >= 16 and 16 or duration) * 16 + .5) - 1 speed = math.floor((speed >= 1 and 1 or speed) * 256 + .5) - 1 scale = math.floor((scale >= 8 and 8 or scale) * 32 + .5) - 1 if scale > 0 and speed > 0 and duration > 0 then if TheWorld.ismastersim then --Forces a netvar to be dirty regardless of value inst.player_classified.camerashakemode:set_local(mode) inst.player_classified.camerashakemode:set(mode) -- inst.player_classified.camerashaketime:set(duration) inst.player_classified.camerashakespeed:set(speed) inst.player_classified.camerashakescale:set(scale) end if inst.HUD ~= nil then TheCamera:Shake( mode, (duration + 1) / 16, (speed + 1) / 256, (scale + 1) / 32 ) end endendIf there is a source and maxDist, then the camera shake will be more or less intense depending on distance.e.g Deerclops stomps when you are near or away.In that case, you write:for k, v in pairs(GLOBAL.AllPlayers) do v:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, 0.25, inst, 40)endIf you want to check for the 40 distance and shake all cameras equally despite the distance, then we remove the source and maxDistance, but we have to check with another function, thus:for k, v in pairs(GLOBAL.AllPlayers) do if v:GetDistanceSqToInst(inst) < (40 * 40) then v:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, 0.25) endend Edited July 20, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655972 Share on other sites More sharing options...
zUsername Posted July 20, 2015 Author Share Posted July 20, 2015 This is the function of player_common:local function ShakeCamera(inst, mode, duration, speed, scale, source, maxDist) if source ~= nil and maxDist ~= nil then local distSq = inst:GetDistanceSqToInst(source) local k = math.max(0, math.min(1, distSq / (maxDist * maxDist))) scale = easing.outQuad(k, scale, -scale, 1) end --normalize for net_byte duration = math.floor((duration >= 16 and 16 or duration) * 16 + .5) - 1 speed = math.floor((speed >= 1 and 1 or speed) * 256 + .5) - 1 scale = math.floor((scale >= 8 and 8 or scale) * 32 + .5) - 1 if scale > 0 and speed > 0 and duration > 0 then if TheWorld.ismastersim then --Forces a netvar to be dirty regardless of value inst.player_classified.camerashakemode:set_local(mode) inst.player_classified.camerashakemode:set(mode) -- inst.player_classified.camerashaketime:set(duration) inst.player_classified.camerashakespeed:set(speed) inst.player_classified.camerashakescale:set(scale) end if inst.HUD ~= nil then TheCamera:Shake( mode, (duration + 1) / 16, (speed + 1) / 256, (scale + 1) / 32 ) end endendIf there is a source and maxDist, then the camera shake will be more or less intense depending on distance.e.g Deerclops stomps when you are near or away.In that case, you write:for k, v in pairs(GLOBAL.AllPlayers) do v:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, 0.25, inst, 40)endIf you want to check for the 40 distance and shake all cameras equally despite the distance, then we remove the source and maxDistance, but we have to check with another function, thus:for k, v in pairs(GLOBAL.AllPlayers) do if v:GetDistanceSqToInst(inst) < (40 * 40) then v:ShakeCamera(GLOBAL.CAMERASHAKE.FULL, 0.2, 0.02, 0.25) endend Wow. Really really thanks you for your details explanation.BIG THANKS sending to you <3. Link to comment https://forums.kleientertainment.com/forums/topic/56318-how-to-use-shakecamera/#findComment-655976 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