Loken Posted October 6, 2014 Share Posted October 6, 2014 Hey all,I'm trying to make a character that, when he equips the different armours that are already in the game, receives different runspeeds and attack damages for it. I cannot figure out how to do it though and I am not entirely sure if I can without editing the games armour files (which I'd like to avoid doing). I've looked through the equipslot and equippable LUA files but there doesn't seem to be anything in there that helps.Thanks in advance for any help! Link to comment Share on other sites More sharing options...
_Q_ Posted October 6, 2014 Share Posted October 6, 2014 if item.components.equippable and item.components.equippable.equipslot == GLOBAL.EQUIPSLOTS.HEAD then if inst.components.pighats.playerhat then local current = inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD) if current then inst.components.inventory:DropItem(current) end if item.name == "Ice Cube" then item.components.perishable:SetOnPerishFn(ice_perish) elseif item.name == "Spider Hat" then item.components.fueled:SetDepletedFn(spider_remove) elseif item.name == "Moggles" then item.components.fueled:SetDepletedFn(mole_remove) elseif item.name == "Eyebrella" then item.components.fueled:SetDepletedFn(eyebrella_remove) elseif item.name ~= "Miner Hat" and item.components.fueled then item.components.fueled:SetDepletedFn(depletedfn) elseif item.components.perishable then item.components.perishable:SetOnPerishFn(depletedfn) end inst.components.inventory:Equip(item) inst.AnimState:Show("hat") else local current = inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD) if current then inst.components.inventory:RemoveItem(current) end if item.name == "Ice Cube" then item.components.perishable:SetOnPerishFn(ice_perish) elseif item.name == "Spider Hat" then item.components.fueled:SetDepletedFn(spider_remove) elseif item.name == "Moggles" then item.components.fueled:SetDepletedFn(mole_remove) elseif item.name == "Eyebrella" then item.components.fueled:SetDepletedFn(eyebrella_remove) elseif item.name ~= "Miner Hat" and item.components.fueled then item.components.fueled:SetDepletedFn(depletedfn) elseif item.components.perishable then item.components.perishable:SetOnPerishFn(depletedfn) end inst.components.inventory:Equip(item) inst.AnimState:Show("hat") inst.components.pighats.playerhat = true inst.components.pighats.randomhat = false end endendThis is what I use fof checking the name of a hat on a pigs, you can do the same way for player prefab for body slot, but I don't know how you wnat to do it.Anyway you can check the armor by getting player equip slots.If in mod main(needs that GLOBAL thing)local player = GLOBAL.GetPlayer()local item = player.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY) Link to comment Share on other sites More sharing options...
Loken Posted October 6, 2014 Author Share Posted October 6, 2014 This seems to be what I'm looking for, but I'm having trouble implementing it (sorry, I have very little coding experience, and none at all in lua), I've placed the two GLOBAL lines at the top of my modmain.lua and wrote this function from your code in modmain.lua: local function armourcheck(inst) if item.components.equippable and item.components.equippable.equipslot == GLOBAL.EQUIPSLOTS.BODY then if item.name == "Thukecite Suit" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) elseif item.name == "Scalemail" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) elseif item.name == "Marble Suit" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) elseif item.name == "Log Suit" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) elseif item.name == "Snurtle Shell Armor" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) elseif item.name == "Grass Armor" then inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 0.1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 0.1) else inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) end else inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) endendThen in my characters lua file I placed: inst:ListenForEvent("armourcheck", armourcheck)What I'm trying to get done there is that, when those armours are equipped my character has no movespeed. I'm sure my ListenForEvent function is wrong, but I'm not sure what event should be under within the quotation marks.Thanks again! Link to comment Share on other sites More sharing options...
_Q_ Posted October 6, 2014 Share Posted October 6, 2014 So you need other function that will return character speed to normal if he decides to unequip armor.The events you must listen to should be:"equipped" and "unequipped"Not sure if this would work:inst:ListenForEvent( "equipped", function(inst,data) armourcheck(data.slot) end ) Look at the events in equipable component. Link to comment Share on other sites More sharing options...
Loken Posted October 6, 2014 Author Share Posted October 6, 2014 Alright, I think I've figured it mostly out (thanks!), but cannot check it because the line of code local item = player.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY)is receiving the error "attempt to index local 'player' (a nil value), as well as the error; in main chunck =[C] in function 'xpcall' ( I did add the code local player = GLOBAL.GetPlayer() right above it). The error causes the game to crash. Commenting that section out causes the game to work fine, but also makes the game ignores all the lines of code I've added! I believe everything works though. Just one final problem! Link to comment Share on other sites More sharing options...
_Q_ Posted October 7, 2014 Share Posted October 7, 2014 No idea where you placed that code. Need to see the mod. Can you upload it here? Link to comment Share on other sites More sharing options...
Loken Posted October 7, 2014 Author Share Posted October 7, 2014 Of course! Though I cannot upload the entire mod since most of the art and sound is taken from other mods and I don't feel I have the right to distribute it. But I can upload the two files I've been editing to try and get this armour check to work. That being the modmain.lua as well as the characters lua since I wrote them (at least the parts that I didn't take from the template). Hopefully that's enough! The code for the armour check is between two long lines of --.https://dl.dropboxusercontent.com/u/14868726/tobb.luahttps://dl.dropboxusercontent.com/u/14868726/modmain.lua Link to comment Share on other sites More sharing options...
_Q_ Posted October 7, 2014 Share Posted October 7, 2014 I think the armor check function should be local function in player prefab. Link to comment Share on other sites More sharing options...
Loken Posted October 9, 2014 Author Share Posted October 9, 2014 Unfortunately that did not work either... I figured out a work around though. I can just add speed modifiers to the separate armour files from within my modmain.lua. Took a while to figure out how, but it actually works (and looks) better than expected! Thank you so much for your help and time though! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.