Augustusc Posted February 16, 2016 Share Posted February 16, 2016 (edited) how would you make it so an item does different things depending on who uses it. , I made m to be able to use it, but granting different affects. for example, the character who can craft it pull beefalo to him. BUT if say, willow uses it, it causes fire to start somewhere randomly, or if webber uses it, spiders will appear. each idea for what happens is a coding question in its own, but the biggest problem i see with this idea is, what about other modded characters, i already have an idea for what my other modded character would cause if he used it, but what about other modded character, would i set a base If statement for if its anyone, and then have if "willow, if "webber" etc. Or would that not work. also, how would i make it so instead of using it, they will just say "i can't use this" and don't use any durability (i'm thinking wickerbottom might use this as an affect, plus i can put this on other items) Edited February 17, 2016 by Augustusc I might not have been clear enough Link to comment Share on other sites More sharing options...
Augustusc Posted February 18, 2016 Author Share Posted February 18, 2016 Is this just a task too great for code to handle? if it is, then at least what is some code that makes it so only one person can use the item Link to comment Share on other sites More sharing options...
Kzisor Posted February 18, 2016 Share Posted February 18, 2016 6 minutes ago, Augustusc said: Is this just a task too great for code to handle? if it is, then at least what is some code that makes it so only one person can use the item It's not that huge of an issue honestly. Some threads get lost due to the amount of posts in this section. On 2/16/2016 at 0:11 PM, Augustusc said: how would you make it so an item does different things depending on who uses it. , I made m to be able to use it, but granting different affects. for example, the character who can craft it pull beefalo to him. BUT if say, willow uses it, it causes fire to start somewhere randomly, or if webber uses it, spiders will appear. each idea for what happens is a coding question in its own, but the biggest problem i see with this idea is, what about other modded characters, i already have an idea for what my other modded character would cause if he used it, but what about other modded character, would i set a base If statement for if its anyone, and then have if "willow, if "webber" etc. Or would that not work. also, how would i make it so instead of using it, they will just say "i can't use this" and don't use any durability (i'm thinking wickerbottom might use this as an affect, plus i can put this on other items) You add the following code to the initialize prefab function in the prefab file: inst:OnBuilt(function( builder ) if builder:HasTag("wilson") then -- Make wilson blow up. elseif builder:HasTag("webber") then -- Make webber get consumed by spiders. end end) Link to comment Share on other sites More sharing options...
Augustusc Posted February 18, 2016 Author Share Posted February 18, 2016 wow! is it really that simple? sweet! but it looks like that for on built. would i just swap out the build related code for on use? sorta change the code to look like this? inst:OnUse(function( user ) if user:HasTag("wilson") then -- Make wilson blow up. elseif user:HasTag("webber") then -- Make webber get consumed by spiders. end end) Link to comment Share on other sites More sharing options...
Kzisor Posted February 18, 2016 Share Posted February 18, 2016 20 minutes ago, Augustusc said: wow! is it really that simple? sweet! but it looks like that for on built. would i just swap out the build related code for on use? sorta change the code to look like this? No you cannot simply do that because that function isn't called anywhere. Each function is different based on what type of item you're using. An example is, if your item has the 'usable' component then you would need to set the usable.onusefn to the function you want to be called upon usage. prefab file local function onuse(user) if user:HasTag("wilson") then -- Blow up player. elseif user:HasTag("webber") then -- Spiders consumes player. end end master_postinit function inst:AddComponent("usableitem") inst.components.usableitem:SetOnUseFn( onuse ) 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