Icerzz Posted February 18, 2015 Share Posted February 18, 2015 perks :* make my character shine with low health* make my character lose little sanity or regenerate sanity when morningThanks Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/ Share on other sites More sharing options...
Jjmarco Posted February 18, 2015 Share Posted February 18, 2015 (edited) make my character lose little sanity or regenerate sanity when morning Do you want it to be either one or the other, or based on random chance?Eitherway, here's the basic code to add to master_postinit:inst:WatchWorldState("startday", function(inst) inst.components.sanity:DoDelta(<sanity to add or substract>)end) About the shining when low on health, it's a bit more tricky.Start by creating a new prefab, which will be the entity holding the light, that you'll attach to your character:local function fn() local inst = CreateEntity() inst.entity:AddLight() -- adds light to the entity inst.entity:AddNetwork() inst:AddTag("FX") inst.Light:Enable(true) inst.Light:SetIntensity(.75) inst.Light:SetColour(197 / 255, 197 / 255, 50 / 255) -- colors in RGB inst.Light:SetFalloff(0.5) -- precentage of radius after which light will start fading inst.Light:SetRadius(2) if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst.persists = false return instendreturn Prefab("common/fx/characterlight", fn) Then, in your character's master_postinit, make your character listen to the healthdelta event:inst:ListenForEvent("healthdelta", function(inst, data) -- this event is triggered everytime your characters loses/gains health local threshold = <whatever you want> if data.newpercent <= threshold and not inst.light then inst.light = SpawnPrefab("characterlight") -- spawns light entity local follower = inst.light.entity:AddFollower() follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0) -- makes it follow your character's center of body elseif data.newpercent > threshold and inst.light then inst.light:Remove() -- remove light entity if life is above threshold inst.light = nil endend)Let me know if it works properly. This code is essentially adapted from how torch light is handled. Edited February 18, 2015 by Jjmarco Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614416 Share on other sites More sharing options...
Icerzz Posted February 19, 2015 Author Share Posted February 19, 2015 Err...Where do I create this new prebaf ?local function fn() local inst = CreateEntity() inst.entity:AddLight() -- adds light to the entity inst.entity:AddNetwork() inst:AddTag("FX") inst.Light:Enable(true) inst.Light:SetIntensity(.75) inst.Light:SetColour(197 / 255, 197 / 255, 50 / 255) -- colors in RGB inst.Light:SetFalloff(0.5) -- precentage of radius after which light will start fading inst.Light:SetRadius(2) if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst.persists = false return instendreturn Prefab("common/fx/characterlight", fn) Then, in your character's master_postinit, make your character listen to the healthdelta event:inst:ListenForEvent("healthdelta", function(inst, data) -- this event is triggered everytime your characters loses/gains health local threshold = <whatever you want> if data.newpercent <= threshold and not inst.light then inst.light = SpawnPrefab("characterlight") -- spawns light entity local follower = inst.light.entity:AddFollower() follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0) -- makes it follow your character's center of body elseif data.newpercent > threshold and inst.light then inst.light:Remove() -- remove light entity if life is above threshold inst.light = nil endend) Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614569 Share on other sites More sharing options...
Jjmarco Posted February 19, 2015 Share Posted February 19, 2015 @Icerzz, In the same directory as your character's prefab. You can name it whatever you like. Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614596 Share on other sites More sharing options...
Icerzz Posted February 19, 2015 Author Share Posted February 19, 2015 @Icerzz, In the same directory as your character's prefab. You can name it whatever you like.when I put the codes crashes my game , I think I 'm not doing it right ;-; Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614699 Share on other sites More sharing options...
Icerzz Posted February 19, 2015 Author Share Posted February 19, 2015 (edited) @Icerzz, In the same directory as your character's prefab. You can name it whatever you like.Sorry :v @Jjmarco ... pake.luapakelight.lua Edited February 19, 2015 by Icerzz Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614702 Share on other sites More sharing options...
Jjmarco Posted February 19, 2015 Share Posted February 19, 2015 @Icerzz, The link isn't working, it says the directory doesn't exist or I'm not allowed to see it...You can directly attach files to your posts. Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614715 Share on other sites More sharing options...
Icerzz Posted February 20, 2015 Author Share Posted February 20, 2015 @Icerzz, The link isn't working, it says the directory doesn't exist or I'm not allowed to see it...You can directly attach files to your posts.Here the files @Jjmarco:pake.luapakelight.lua Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614968 Share on other sites More sharing options...
Jjmarco Posted February 20, 2015 Share Posted February 20, 2015 (edited) @Icerzz, Hm, I see. You renamed the light entity's prefab pakelight, but you did not change that line:return Prefab("common/fx/characterlight", fn) You also have to change characterlight to pakelight. Also, why do you have 2's as parameters to these functions? They shouldn't be there:local inst = CreateEntity(2) inst.entity:AddLight(2)inst.entity:AddNetwork(2)same for 51 as parameter to inst.light:Remove. Remove doesn't take any parameter.local threshold = 50, not <50>, it should be a number! Sorry if "<whatever you want>" confused you. inst:ListenForEvent("healthdelta", function(inst, data) local threshold = <50> -- this should be 50, not <50> if data.newpercent <= threshold and not inst.light then inst.light = SpawnPrefab("pakelight") local follower = inst.light.entity:AddFollower() follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0) elseif data.newpercent > threshold and inst.light then inst.light:Remove(51) -- no 51 here! inst.light = nil endend).One last thing, did you register pakelight in your modmain? Don't forget! Prefabs = { "pake", "pakelight"} Edited February 20, 2015 by Jjmarco Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-614992 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 (edited) well , the game does not crashes , but my character is not shining when your life comes 50 .any ideas? Edited February 21, 2015 by Icerzz Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615140 Share on other sites More sharing options...
Jjmarco Posted February 21, 2015 Share Posted February 21, 2015 @Icerzz, In the light prefab, add inst:AddTransform() above inst.entity:AddLight() and inst.entity:AddNetwork(). Forgot about that.Also, you have to put a percentage as a threshold, like 0.25. Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615152 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 A monster attacked me and the game crashed with this message :attempt to call AddTransform (a nil value) Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615160 Share on other sites More sharing options...
Jjmarco Posted February 21, 2015 Share Posted February 21, 2015 inst.entity:AddTransform(), not inst:AddTransform()... Sorry Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615164 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 (edited) @Jjmarco it's working thx man has a small bug I found : light also activates when I eat something Edited February 21, 2015 by Icerzz Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615168 Share on other sites More sharing options...
Jjmarco Posted February 21, 2015 Share Posted February 21, 2015 @Icerzz, Great!Are you sure it's not because what you ate reduced your life? Like monster meat or red mushrooms. Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615179 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 @Icerzz, Great!Are you sure it's not because what you ate reduced your life? Like monster meat or red mushrooms.I had eaten a berry =/ Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615182 Share on other sites More sharing options...
Jjmarco Posted February 21, 2015 Share Posted February 21, 2015 @Icerzz, Huh... That's weird. I tried eating berries and could not reproduce the bug.Does it happen with other food items of just berries? Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615190 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 @Icerzz, Huh... That's weird. I tried eating berries and could not reproduce the bug.Does it happen with other food items of just berries?@, all edible itemsHere the files:pake.luapakelight.lua Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615192 Share on other sites More sharing options...
Jjmarco Posted February 21, 2015 Share Posted February 21, 2015 (edited) @Icerzz, Alright. You are putting numbers as parameters to functions that don't need them:local inst = CreateEntity(1) -- no 1 here inst.entity:AddLight(1) -- and hereinst.entity:AddTransform(0.25) -- no 0.25 hereinst.entity:AddNetwork(1) -- no 1 hereThere should never be numbers there. What I meant by percentage as a threshold was here, in healthdelta:local threshold = 0.25That means that your character will shine when its life gets below 25% of max. You can change that to whatever other percentage you want, like 30% or 10%. You can't put 50 because healthdelta gives you the percentage of health, not the number value. So if you put 50, it's way bigger than 1 (100%), so the light will always be lit. Edited February 21, 2015 by Jjmarco Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615196 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 @Jjmarcoworked , thank you helped me a lot : DI'm sorry if I made many questions and took his time , because I do not know much about codes ...Really , thnx \o . Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615202 Share on other sites More sharing options...
Icerzz Posted February 21, 2015 Author Share Posted February 21, 2015 I was with a doubt here ...is to make different faces to when it is shining ? Link to comment https://forums.kleientertainment.com/forums/topic/51139-someone-help-me-with-extended-sample-characters/#findComment-615206 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