BUTT3RS Posted June 14, 2017 Share Posted June 14, 2017 im new to the modding and character creation, but i have made my first character but dont know how to add custom perks, for example how do i increase the rate of sanity and how fast the character gains it like maxwell, and or make it where if the character is next to another friend, his sanity will go up? thanks Link to comment Share on other sites More sharing options...
BigMommaWolf Posted June 14, 2017 Share Posted June 14, 2017 @BUTT3RS There's really not a simple answer to "how to add custom perks." To add custom perks you first have to figure out what you want the character's perks to be and then code those in. If you want to make custom character do something like a character already in the game, extract the game files of that character and read their code. If you want to make a character's sanity go up near another player, you can try using GetClosestInstWithTag(tag, inst, radius) to check for the closest player. You can find more information here: I hope that helps. I'm still pretty new to this stuff too. Link to comment Share on other sites More sharing options...
BUTT3RS Posted June 14, 2017 Author Share Posted June 14, 2017 1 hour ago, BigMommaWolf said: @BUTT3RS There's really not a simple answer to "how to add custom perks." To add custom perks you first have to figure out what you want the character's perks to be and then code those in. If you want to make custom character do something like a character already in the game, extract the game files of that character and read their code. If you want to make a character's sanity go up near another player, you can try using GetClosestInstWithTag(tag, inst, radius) to check for the closest player. You can find more information here: I hope that helps. I'm still pretty new to this stuff too. thanks very much i am currently looking into this, i tried finding the sanity stats for maxwell but cannot find how he gains 20 sanity a minute, is there a special way to extract the files or would you possibly know where to find the stats? i tried looking in maxwell.lue files but cannot find anything. thanks again Link to comment Share on other sites More sharing options...
BigMommaWolf Posted June 14, 2017 Share Posted June 14, 2017 (edited) @BUTT3RS From the wiki: "Maxwell's Sanity increases by 20 /min because of his dapper style." So you'll probably be looking for "dapperness" in data/scripts/prefabs/waxwell.lua Try: inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE See if that helps? It would go under the master_postinit. Edited June 14, 2017 by BigMommaWolf Link to comment Share on other sites More sharing options...
BUTT3RS Posted June 14, 2017 Author Share Posted June 14, 2017 25 minutes ago, BigMommaWolf said: @BUTT3RS From the wiki: "Maxwell's Sanity increases by 20 /min because of his dapper style." So you'll probably be looking for "dapperness" in data/scripts/prefabs/waxwell.lua Try: inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE See if that helps? It would go under the master_postinit. thanks again, i think the code you sent works, i just need to somehow combine it with player radius, do you have any knowledge with the get closestinwithtag command? im trying different things like GetClosestInstWithTag('player', ThePlayer, 10) inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE not realy sure how to add the command you told me? any ideas, lol sorry for more questions but thanks again Link to comment Share on other sites More sharing options...
BigMommaWolf Posted June 14, 2017 Share Posted June 14, 2017 This is going to be a situation of the blind leading the blind, but this is what I would try first: if local player = GetClosestInstWithTag("player", inst, MyRadius) then inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE end If that actually works, I'm going to poop cut stone. Link to comment Share on other sites More sharing options...
BUTT3RS Posted June 14, 2017 Author Share Posted June 14, 2017 (edited) 53 minutes ago, BigMommaWolf said: This is going to be a situation of the blind leading the blind, but this is what I would try first: if local player = GetClosestInstWithTag("player", inst, MyRadius) then inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE end If that actually works, I'm going to poop cut stone. lol thanks again again =P, ill have to try it tomorrow dont have anyone to test it with atm, ill let u know if it works update-i tried the command but it says "unexpected symblol near "local" but ill just try and mess around myself youve helped me enough lol dont want bother u any more, thanks Edited June 14, 2017 by BUTT3RS more information Link to comment Share on other sites More sharing options...
BigMommaWolf Posted June 14, 2017 Share Posted June 14, 2017 @BUTT3RS That thread I linked has a few different proximity checks you can try. I would keep testing them with the formula: if [check for proximity to player] then inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE end Try replacing the [check for proximity to player] with different ways to check for range and players until something works. I would love to figure out how to do this myself at some point, because this was almost exactly what I wanted to do on a character for a friend. I just have entirely too many irons in the fire right now, on top of the fact that I hardly have time to work on modding. It can be frustrating when you get errors, but once you have a success, it makes you feel like you're floating on air! I hope someone with more experienced comes along or you solve it yourself very soon! Good luck! Link to comment Share on other sites More sharing options...
alainmcd Posted June 14, 2017 Share Posted June 14, 2017 You can use the sanityaura component. Place this in your modmain.lua: local function playersanityaurafn(inst) if not GLOBAL.TheWorld.ismastersim then return end AddComponent("sanityaura") inst.components.sanityaura.aurafn = function(inst, observer) return not inst:HasTag("playerghost") and observer.prefab == "yourcharacter" and GLOBAL.TUNING.DAPPERNESS_LARGE or 0 end end AddPlayerPostInit(playersaniyaurafn) A little breakdown: modmain.lua has access to some special functions to manipulate prefabs and components (and other stuff), for example AddPlayerPostInit lets you modify player prefabs and its only argument (playersanityaurafn in this case) should be a function with how to do so. Going on to playersanityaurafn itself, checking whether it's the master simulation (i.e. the server) is very common; since most logic is only executed server side, we don't want clients to run this code, hence the return. So the component sanityaura is now applied to all player prefabs on the server. Finally, we assign a function to aurafn to determine what sanity bonus should be applied: in this case, if the player is alive (doesn't have the tag "playerghost") and the observer (the recipient) is "yourcharacter", the bonus will be TUNING.DAPPERNESS_LARGE, for all other cases it will be 0. Check the sanityaura component in data/scripts/components/sanityaura.lua to see why we use aurafn. Note: untested code, might not work. And as @BigMommaWolf said, there is no "magic recipe" to adding perks nor is there a single way to do so, you have to write code to your specific needs. It's always a good idea to poke around and look at similar prefabs and mods, to see how others do it. Link to comment Share on other sites More sharing options...
BUTT3RS Posted June 14, 2017 Author Share Posted June 14, 2017 54 minutes ago, alainmcd said: You can use the sanityaura component. Place this in your modmain.lua: local function playersanityaurafn(inst) if not GLOBAL.TheWorld.ismastersim then return end AddComponent("sanityaura") inst.components.sanityaura.aurafn = function(inst, observer) return not inst:HasTag("playerghost") and observer.prefab == "yourcharacter" and GLOBAL.TUNING.DAPPERNESS_LARGE or 0 end end AddPlayerPostInit(playersaniyaurafn) A little breakdown: modmain.lua has access to some special functions to manipulate prefabs and components (and other stuff), for example AddPlayerPostInit lets you modify player prefabs and its only argument (playersanityaurafn in this case) should be a function with how to do so. Going on to playersanityaurafn itself, checking whether it's the master simulation (i.e. the server) is very common; since most logic is only executed server side, we don't want clients to run this code, hence the return. So the component sanityaura is now applied to all player prefabs on the server. Finally, we assign a function to aurafn to determine what sanity bonus should be applied: in this case, if the player is alive (doesn't have the tag "playerghost") and the observer (the recipient) is "yourcharacter", the bonus will be TUNING.DAPPERNESS_LARGE, for all other cases it will be 0. Check the sanityaura component in data/scripts/components/sanityaura.lua to see why we use aurafn. Note: untested code, might not work. And as @BigMommaWolf said, there is no "magic recipe" to adding perks nor is there a single way to do so, you have to write code to your specific needs. It's always a good idea to poke around and look at similar prefabs and mods, to see how others do it. thanks alot i will look into this code and method, yea i know its not straight forward for code making just gonna have read and hope i start to understand how to make my own things. btw i just found a mod which has the command where it gives you sanity around others, im not sure how well it works but it does seem to work local function sanityfn(inst) local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local rad = 10 local rad_sq = rad*rad for k,v in pairs(AllPlayers) do if v ~= inst then local distsq = inst:GetDistanceSqToInst(v) if distsq < rad_sq then local sz = TUNING.SANITYAURA_TINY * rad delta = delta + sz/math.max(1, distsq) end end end return delta end inst.components.sanity.custom_rate_fn = sanityfn @BigMommaWolf thanks again both of you 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