Wonderlarr Posted November 23, 2020 Share Posted November 23, 2020 Hello! I'm making a Hat for the game that has the ability to freeze nearby enemies, but I can't seem to define the Owner of the item properly, and I'm resorting to disgusting local variables that I don't wanna use. How can I properly define the owner of an item, and then use that to see if the owner has a certain tag? In this case, the tag is WearingIceHat. Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 @DocterRedstone inventoryitem:GetGrandOwner() 1 Link to comment Share on other sites More sharing options...
Wonderlarr Posted November 23, 2020 Author Share Posted November 23, 2020 3 minutes ago, penguin0616 said: @DocterRedstone inventoryitem:GetGrandOwner() How do I use this line? Where do I put it? Link to comment Share on other sites More sharing options...
penguin0616 Posted November 23, 2020 Share Posted November 23, 2020 (edited) 1. inventoryitem is a component. Use it on instances that are inventory items (which means they have the inventoryitem component). 2. Wherever you need it. Edited November 23, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
Yakuzashi Posted November 23, 2020 Share Posted November 23, 2020 Howdy! Inside OnUnequip function Quote owner:RemoveTag("WearingIceHat") Inside OnEquip function Quote owner:AddTag("WearingIceHat") Above main function: local function ayylmao(inst) local owner = inst.components.inventoryitem.owner local pt = inst:GetPosition() local range = 15 -- range of spell local tags = { "monster", "character", "hostile" } local canthavetags = {"WearingIceHat"} local targets = TheSim:FindEntities(pt.x,pt.y,pt.z, range, nil, canthavetags, tags) for _,ent in ipairs(targets) do if ent.components.freezable ~= nil then ent.components.freezable:AddColdness(5) ent.components.freezable:SpawnShatterFX() end end end local function fugg(inst) local owner = inst.components.inventoryitem.owner if not owner.components.health:IsDead() and not owner:HasTag("playerghost") and owner:HasTag("WearingIceHat") then ayylmao(inst) end end Inside main function: Quote inst:DoPeriodicTask(10, fugg, nil, inst) Cheers! 1 1 Link to comment Share on other sites More sharing options...
Wonderlarr Posted November 24, 2020 Author Share Posted November 24, 2020 51 minutes ago, Yakuzashi said: Howdy! Inside OnUnequip function Inside OnEquip function Above main function: local function ayylmao(inst) local owner = inst.components.inventoryitem.owner local pt = inst:GetPosition() local range = 15 -- range of spell local tags = { "monster", "character", "hostile" } local canthavetags = {"WearingIceHat"} local targets = TheSim:FindEntities(pt.x,pt.y,pt.z, range, nil, canthavetags, tags) for _,ent in ipairs(targets) do if ent.components.freezable ~= nil then ent.components.freezable:AddColdness(5) ent.components.freezable:SpawnShatterFX() end end end local function fugg(inst) local owner = inst.components.inventoryitem.owner if not owner.components.health:IsDead() and not owner:HasTag("playerghost") and owner:HasTag("WearingIceHat") then ayylmao(inst) end end Inside main function: Cheers! Wow! This worked wonders on what I'm trying to do! Thanks for the help, though I have one more question. If I wanted to do the freeze when I pressed a key instead of on a timer like it is in your code, how would I do so? Right now I have this TheInput:AddKeyDownHandler(304,fugg(inst)) But all this does is cause errors, because inst doesn't technically exist outside of a function, so then how do I declare it in this instance? Link to comment Share on other sites More sharing options...
Yakuzashi Posted November 24, 2020 Share Posted November 24, 2020 (edited) User named Ysovuka/Kzisor made awesome keyhandler system long time ago, it was attached to transformation tutorial. If I remember correctly the download link from tutorial was expired. Edit: Edited November 24, 2020 by Yakuzashi Link to comment Share on other sites More sharing options...
Mobbstar Posted November 24, 2020 Share Posted November 24, 2020 In my HUD Hotkey mod I did this: GLOBAL.TheInput:AddKeyDownHandler(GetModConfigData("key"), function() local wilson = GLOBAL.ThePlayer if wilson and wilson.HUD then if wilson.HUD:IsVisible() then wilson.HUD:Hide() else wilson.HUD:Show() end end end) This only works because HUD is purely client-side (i.e. it only affects the person pressing the key). For your case, a RPC or alike would be needed. Kzisor's code seems to use RPC under the hood too. By copying from Kzisor's RPC Handler example and my Key Handler example, you should almost have everything needed. However, you'd also have to send the RPC in the Key Handler function. I cannot recall how that works. To clarify, it would look something like this, I imagine: GLOBAL.TheInput:AddKeyDownHandler(GetModConfigData("key"), function() local player_character = GLOBAL.ThePlayer if player_character ~= nil and player_character.prefab == "yourcharacter" then --TODO send RPC "yourhotkeyname" for player_character end end) AddModRPCHandler("yourmodname", "yourhotkeyname", fugg) 1 Link to comment Share on other sites More sharing options...
Wonderlarr Posted November 26, 2020 Author Share Posted November 26, 2020 On 11/24/2020 at 3:27 AM, Mobbstar said: In my HUD Hotkey mod I did this: GLOBAL.TheInput:AddKeyDownHandler(GetModConfigData("key"), function() local wilson = GLOBAL.ThePlayer if wilson and wilson.HUD then if wilson.HUD:IsVisible() then wilson.HUD:Hide() else wilson.HUD:Show() end end end) This only works because HUD is purely client-side (i.e. it only affects the person pressing the key). For your case, a RPC or alike would be needed. Kzisor's code seems to use RPC under the hood too. By copying from Kzisor's RPC Handler example and my Key Handler example, you should almost have everything needed. However, you'd also have to send the RPC in the Key Handler function. I cannot recall how that works. To clarify, it would look something like this, I imagine: GLOBAL.TheInput:AddKeyDownHandler(GetModConfigData("key"), function() local player_character = GLOBAL.ThePlayer if player_character ~= nil and player_character.prefab == "yourcharacter" then --TODO send RPC "yourhotkeyname" for player_character end end) AddModRPCHandler("yourmodname", "yourhotkeyname", fugg) Are there any examples of RPC's bound to an item, like I'm trying to do? Or do I need to consolidate all of my abiltiy code into modmain to make it work properly? I've been trying to get this to work for a couple of days and keep running into problems, and I think I'm also missing a core RPC line as well. Link to comment Share on other sites More sharing options...
Wonderlarr Posted November 27, 2020 Author Share Posted November 27, 2020 I actually figured out how to do this properly earlier today, and I figured I should leave this here as a resource. Awesome tutorial about RPC's and how to use them! 1 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