KainMorgen Posted March 18, 2016 Share Posted March 18, 2016 Which classes can have items that can be equipped in the players equipslots.hands? A script I am trying to bugfix is using these lines: Quote local wp = components.inventory:GetEquippedItem(GLOBAL.ITEMSLOTS.HANDS) local wp_damage = wp and wp.components.weapon and wp.components.weapon.damage or 0 I already added a nil check before these lines, so it won't crash if there is no item held in hands. So, if there is an item held in hands (wp has a value) and this item is a weapon (wp.components.weapon) and that weapon has a damage value (wp.components.weapon.damage) then wp_damage is set to this value. Else it is set to 0. Somehow the script crashed when I was holding an umbrella, probably in the part where the script compairs the damage values in pairs, because it assumes that the item held is a weapon. I guess an umbrella is not. Then again, the script works with tools like the pickaxe and switches to spears. So I guess DST has a tag in those 'tools' that they can be used as a weapon which the umbrella does not have, although you are able to slap enemies with it. (Even if that should be a bad idea in most cases) So I guess there are other classes of items that can be equipped to hands. I don't feel like guessing them and I don't know in which .lua file I could find them. Who knows which classes are viable or where to find the answer? Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/ Share on other sites More sharing options...
FlawlessHair Posted March 18, 2016 Share Posted March 18, 2016 (edited) Try checking for inst.components.weapon if inst.components.weapon then --If it has the weapon component end inst is the reference to the weapon prefab, if that wasn't clear Edited March 18, 2016 by FlawlessHair Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735615 Share on other sites More sharing options...
Muche Posted March 18, 2016 Share Posted March 18, 2016 When debugging, always look at what the log says (client_log.txt when on hosted world, server_log.txt+client_log.txt when on dedicated server), it should contain more details about the crash. The local wp = components.inventory... may look iffy. Is the components variable set, or should it say something like player.components.inventory...? I did not find any GLOBAL.ITEMSLOTS.HANDS, did you mean GLOBAL.EQUIPSLOTS.HANDS? The wp and wp.components.weapon check looks fine to me, it worked for me with nothing / axe / spear / umbrella equipped. As for what prefabs are equippable in the hand, any prefab that has equippable component with equippable.equipslot set to EQUIPSLOTS.HANDS (which is the default unless the prefab sets it otherwise). All prefabs are in the prefabs folder. Components they use are in the components folder. For a list of components frequently used you may want to refer to, for example, Food Values - Item Tooltips mod or Advanced Tooltips mod (they display various useful information based on items' components). For differences between a prefab and a component see e.g. Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735620 Share on other sites More sharing options...
KainMorgen Posted March 18, 2016 Author Share Posted March 18, 2016 (edited) @FlawlessHair Thank you for your reply. The script already does what you proposed and that's propably the reason why it crashes. Some equipable items do not have .components.weapon attribute, which then results in a nil error. But since I can attack with an umbrella for example, I assume it does have a damage value (maybe) and a type that is not 'weapon'. Maybe somethings like .components.stuff or components.utility or components.tool or ... or ... or. I'm looking for a list of these subclasses. @Muche Yes, you are right, I meant Equipslots, not Itemslots. I am trying to fix some bugs in Handymanness for DST and I was working on a port for RPG HUD to DST before, which used itemslots quite often. Handymanness uses Requires and shortcuts some referrers. That's why wp.components.weapon looks 'spiffy' but is still working fine. I'll try to reproduce the umbrella crash and read the client log as well as the mods you recommended then. General question is: Are there other "components" than "weapon"? There probably are quite some. If so, which are these? Edited March 18, 2016 by KainMorgen Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735621 Share on other sites More sharing options...
Muche Posted March 18, 2016 Share Posted March 18, 2016 (edited) Umbrella indeed does not have a weapon component. It seems its nopunch tag allows it to look like you are attacking with it. Since it has no weapon component, I assume this deals the same amount of damage as empty handed punch. There are many components. For example, both umbrella and axe have: equippable, inspectable and inventoryitem. For complete list see data/scripts/components folder. However, only some of them make sense for an equippable item. Edited March 18, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735630 Share on other sites More sharing options...
KainMorgen Posted March 18, 2016 Author Share Posted March 18, 2016 So, the error is reproducable. It's attacking with an umbrella. Handymanness does give it an wp_damage of 0 because not all conditions of the expression are true Quote local wp_damage = wp and wp.components.weapon and wp.components.weapon.damage or 0 That's fine so far. But later on it compares the wp_damage of your current 'weapon' (curr_damage, derived from wp_damage) and other weapons in your inventory Quote local min_damage = curr_damage + 1 local to_equip = components.inventory:FindItems(function(i) local ret = i.components.weapon and (HMM.weapon == 2 or not i.components.lighter) and min_damage <= i.components.weapon.damage if ret then min_damage = i.components.weapon.damage end return ret end) for _, v in pairs(to_equip) do if v.components.weapon.damage == min_damage and v.components.weapon.damage > curr_damage then components.inventory:Equip(v) break end end Since this uses the weapon component it will crash with all items that have the nopunch tag. And maybe more, if theres another tag that enables something to attack without being a weapon. Now, checking the files of every single item for the nopunch tag or something similar would be a bad idea. Instead I'd like to rework the to_equip part to work with a held 'nonweapon', too... Suggestions? Oh btw, the client.log: (At least the end of it) Quote [00:01:59]: Spawning player at: [Load] (15.65, -0.00, 117.54) [00:01:59]: ReceiveResumeNotification [00:01:59]: Validating portal[3] <-> <nil>[3] (inactive) [00:01:59]: Validating portal[5] <-> <nil>[5] (inactive) [00:01:59]: Loading minimap: session/2DE70B5427EA9ABA/OU_76561201244147145_/minimap [00:01:59]: Deserializing cached icon data: 2857 [00:01:59]: Deserializing tile data (400 x 400) [00:03:08]: [string "../mods/DST Handymanness/modmain.lua"]:248: attempt to index field 'weapon' (a nil value) LUA ERROR stack traceback: ../mods/DST Handymanness/modmain.lua:248 in (method) DoAttackButton (Lua) <230-286> self = DoAttackButton = function - ../mods/DST Handymanness/modmain.lua:230 DoAttackButton_before_handymanness = function - scripts/components/playercontroller.lua:984 isclientcontrollerattached = false predictionsent = false controller_target_age = 1.#INF draggingonground = false deploy_mode = true inst = 112347 - wilson (valid:true) remote_vector = (0.00, 0.00, 0.00) can_use_map = true OnRightClick = function - ../mods/DST Dont Drop Stuff While Planting/modmain.lua:53 attack_buffer = 2 map = Map (44868F60) is_map_enabled = true DoActionButton_before_handymanness = function - scripts/components/playercontroller.lua:1229 directwalking = false predictwalking = false dragwalking = false RestoreSavedItem = function - ../mods/DST Handymanness/modmain.lua:293 DoActionButton = function - ../mods/DST Handymanness/modmain.lua:301 time_direct_walking = 0 ismastersim = true handler = table: 552B0458 classified = 112348 - player_classified (valid:true) mousetimeout = 10 locomotor = table: 3BA7CEF8 remote_controls = table: 60897340 SortOutDarkness = function - ../mods/DST Handymanness/modmain.lua:96 res = nil in_darkness = false busy_slot = nil components = table: 3BA731C8 hm = 113446 - beefalohat(LIMBO) (valid:true) curr_damage = table: 56D20CA0 wp = 114919 - umbrella(LIMBO) (valid:true) wp_damage = 0 scripts/components/playercontroller.lua:1481 in (method) OnUpdate (Lua) <1399-1749> self = DoAttackButton = function - ../mods/DST Handymanness/modmain.lua:230 DoAttackButton_before_handymanness = function - scripts/components/playercontroller.lua:984 isclientcontrollerattached = false predictionsent = false controller_target_age = 1.#INF draggingonground = false deploy_mode = true inst = 112347 - wilson (valid:true) remote_vector = (0.00, 0.00, 0.00) can_use_map = true OnRightClick = function - ../mods/DST Dont Drop Stuff While Planting/modmain.lua:53 attack_buffer = 2 map = Map (44868F60) is_map_enabled = true DoActionButton_before_handymanness = function - scripts/components/playercontroller.lua:1229 directwalking = false predictwalking = false dragwalking = false RestoreSavedItem = function - ../mods/DST Handymanness/modmain.lua:293 DoActionButton = function - ../mods/DST Handymanness/modmain.lua:301 time_direct_walking = 0 ismastersim = true handler = table: 552B0458 classified = 112348 - player_classified (valid:true) mousetimeout = 10 locomotor = table: 3BA7CEF8 remote_controls = table: 60897340 SortOutDarkness = function - ../mods/DST Handymanness/modmain.lua:96 dt = 0.033333335071802 isenabled = true ishudblocking = nil scripts/update.lua:187 in () ? (Lua) <150-223> dt = 0.033333335071802 tick = 2031 k = 112347 v = 112347 - wilson (valid:true) cmp = table: 60897200 [00:03:08]: [string "../mods/DST Handymanness/modmain.lua"]:248: attempt to index field 'weapon' (a nil value) LUA ERROR stack traceback: ../mods/DST Handymanness/modmain.lua:248 in (method) DoAttackButton (Lua) <230-286> scripts/components/playercontroller.lua:1481 in (method) OnUpdate (Lua) <1399-1749> scripts/update.lua:187 in () ? (Lua) <150-223> [00:03:31]: Force aborting... Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735637 Share on other sites More sharing options...
Muche Posted March 18, 2016 Share Posted March 18, 2016 Well, not having access to the whole code, I was not able to infer which of the posted lines is the line 248 that is referenced in the crash log. It seems to me that the crash is occuring before them. I mean, the first line assigns a value to min_damage variable, but the crash log does not show it. Also, it would try to compute it using curr_damage, which seems to contain a table, not a number. Were the error be inside of function passed to FindItems, it would show up in the callstack. Were it be in the for loop, the variable to_equip, _ and v should have been in the log as well. Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735654 Share on other sites More sharing options...
KainMorgen Posted March 18, 2016 Author Share Posted March 18, 2016 (edited) @ Muche Maybe you are right and the error occured already somewhere in the wp_damage part. Seems like I fixed this with my latest edit to the code. Unfortunately, since my last edit began yesterday and I saved the script just now, I cannot figure anymore what line 248 was when the error still occured. But there's still alot to do: - Do not replace ranged weapons - If melee, do not equip ranged weapons - Add another shortcut key to equip a spear (if there's at least one in your inventory) to save time if you want to attack a non-hostile target which F does't react to. Feel free to have a look if you want to help to implement these features. I'd really appreciate it. DST Handymanness.rar Edited March 18, 2016 by KainMorgen Link to comment https://forums.kleientertainment.com/forums/topic/65535-subclasses-of-equipable-items/#findComment-735727 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