Jump to content

Recommended Posts

I forgot to mention I'd also like for the dialogue to be randomized and there to be 4 different lines maybe. Like how when  a character will carry a heavy statue they will say different lines occasionally.

I'd also like to know if I can make it so it can be placed and picked back up? If not, that's understandable. I tried googling it and nothing came up. 

(This is for a custom character btw, and they spawn with it)

Edited by Indi_
1 hour ago, _zwb said:

What do you mean by "when used"? When equipped? Or turned on? Or directly used like Wanda watches?

I wanted it to be like, when you used the item like if you left clicked for example. So the character would use the item and then say some dialogue, and then their sanity would go up a bit. 

5 minutes ago, Indi_ said:

I wanted it to be like, when you used the item like if you left clicked for example. So the character would use the item and then say some dialogue, and then their sanity would go up a bit. 

I might just make it so when you hold it, it makes you regain sanity slowly because I already know how to code that lol. Though I'd still like dialogue to occasionally happen. 

19 hours ago, Indi_ said:

I wanted it to be like, when you used the item like if you left clicked for example. So the character would use the item and then say some dialogue, and then their sanity would go up a bit.

So you want to activate the effect by right clicking or something similar? Then what? Is there a cool down? Does it have finite uses? Sorry I don't really understand what do you want it to do.

19 hours ago, Indi_ said:

I might just make it so when you hold it, it makes you regain sanity slowly because I already know how to code that lol. Though I'd still like dialogue to occasionally happen. 

If you do it this way then I've came up with something for the quotes

-- in your custom item file
-- you can probably optimise the code a bit but again I don't know what you want to achieve so I can't do that

local function say_random_quote(player)
    if player then
    	if player.components.talker then
      		player.components.talker:Say(--choose a random string from a table)
        end
    end
end

local function onequip(inst, owner)
    if owner.prefab == "your_custom_character_prefab" then
    	if owner.say_quote_task then
      		owner.say_quote_task:Cancel()
      		owner.say_quote_task = nil
   		end
       	-- replace 10 with the time between quotes in seconds
    	owner.say_quote_task = owner:DoPeriodicTask(10, say_random_quote, owner)
    end
end
  
local function onunequip(inst, owner)
    if owner.say_quote_task then
      owner.say_quote_task:Cancel()
      owner.say_quote_task = nil
    end
end

local function onequiptomodel(inst, owner, from_ground)
    -- this is for when item is equipped to mannequin
    -- do stuff depending on your item type
end
  
local function fn()
	inst = CreateEntity()
  	--[[
  		insert other stuff you want to do
  	--]]
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
  
  	inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    inst.components.equippable:SetOnEquipToModel(onequiptomodel)
  	
  	--[[ 
  		insert other stuff you want to do 
  	--]]
  	return inst
end

 

  • Like 1
8 hours ago, _zwb said:

So you want to activate the effect by right clicking or something similar? Then what? Is there a cool down? Does it have finite uses? Sorry I don't really understand what do you want it to do.

If you do it this way then I've came up with something for the quotes

-- in your custom item file
-- you can probably optimise the code a bit but again I don't know what you want to achieve so I can't do that

local function say_random_quote(player)
    if player then
    	if player.components.talker then
      		player.components.talker:Say(--choose a random string from a table)
        end
    end
end

local function onequip(inst, owner)
    if owner.prefab == "your_custom_character_prefab" then
    	if owner.say_quote_task then
      		owner.say_quote_task:Cancel()
      		owner.say_quote_task = nil
   		end
       	-- replace 10 with the time between quotes in seconds
    	owner.say_quote_task = owner:DoPeriodicTask(10, say_random_quote, owner)
    end
end
  
local function onunequip(inst, owner)
    if owner.say_quote_task then
      owner.say_quote_task:Cancel()
      owner.say_quote_task = nil
    end
end

local function onequiptomodel(inst, owner, from_ground)
    -- this is for when item is equipped to mannequin
    -- do stuff depending on your item type
end
  
local function fn()
	inst = CreateEntity()
  	--[[
  		insert other stuff you want to do
  	--]]
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
  
  	inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    inst.components.equippable:SetOnEquipToModel(onequiptomodel)
  	
  	--[[ 
  		insert other stuff you want to do 
  	--]]
  	return inst
end

 

Thank you!!!
Sorry what I was saying was unclear, I can try to explain it better. What I meant is, this item is basically something that my character will talk to and every time he does so he'll regain sanity, and it'll have infinite uses but a cooldown. My character loses sanity fast so I want an item to combat that. I'm sorry for the misunderstanding. And thank you so much for helping me out I really appreciate it!!!!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...