Mose Posted October 21, 2015 Share Posted October 21, 2015 Can someone check this for me? I'm not sure what I'm doing wrong. I don't actually know much about coding. I'm attempting to make "tactical clothing" or "cargo clothing." I basically want to make it so the clothing I add has storage. To do this I attempted to give containers with "CanBeEquipped = Top" the ability to be right clicked for the Wear context menu option. I tried to base it off of the back equipable items but make it so they get equipped to the clothing slots instead of the back slot. So far here is what I've done. I've also attached the files if that makes things easier. module Test{ item TacticalVest { Palettes = Vest_Black, BodyLocation = Top, PalettesStart = Vest_, Type = Container, Temperature = 5, SpriteName = Vest, DisplayName = Tactical Vest, Icon = Vest, Capacity = 10, WeightReduction = 75, CanBeEquipped = Top, } }I've modified "ISInventoryPaneContextMenu.lua" (around line 330) if instanceof(testItem, "InventoryContainer") and testItem:canBeEquipped() == "Top" then canBeEquippedTop = true; end if instanceof(testItem, "InventoryContainer") and testItem:canBeEquipped() == "Bottoms" then canBeEquippedBottom = true; end if canBeEquippedTop and not unequip and not getSpecificPlayer(player):getClothingItem_Torso() then context:addOption(getText("ContextMenu_Wear"), items, ISInventoryPaneContextMenu.onWearItems, player); end if canBeEquippedBottom and not unequip and not getSpecificPlayer(player):getClothingItem_Legs() then context:addOption(getText("ContextMenu_Wear"), items, ISInventoryPaneContextMenu.onWearItems, player); endThen changed "ISWearClothing.lua" (around line 27)function ISWearClothing:perform() self.item:getContainer():setDrawDirty(true); self.item:setJobDelta(0.0); if instanceof(self.item, "InventoryContainer") and self.item:canBeEquipped() == "Back" then self.character:setClothingItem_Back(self.item); getPlayerData(self.character:getPlayerNum()).playerInventory:refreshBackpacks(); elseif instanceof(self.item, "InventoryContainer") and self.item:canBeEquipped() == "Top" then self.character:setClothingItem_Torso(self.item); getPlayerData(self.character:getPlayerNum()).playerInventory:refreshBackpacks(); elseif instanceof(self.item, "InventoryContainer") and self.item:canBeEquipped() == "Bottoms" then self.character:setClothingItem_Legs(self.item); getPlayerData(self.character:getPlayerNum()).playerInventory:refreshBackpacks(); else if self.item:getBodyLocation() == ClothingBodyLocation.Top then self.character:setClothingItem_Torso(self.item); elseif self.item:getBodyLocation() == ClothingBodyLocation.Shoes then self.character:setClothingItem_Feet(self.item); elseif self.item:getBodyLocation() == ClothingBodyLocation.Bottoms then self.character:setClothingItem_Legs(self.item); end end self.character:initSpritePartsEmpty(); triggerEvent("OnClothingUpdated", self.character)--~ self.character:SetClothing(self.item:getBodyLocation(), self.item:getSpriteName(), self.item:getPalette()); -- needed to remove from queue / start next. ISBaseTimedAction.perform(self);endTacticalClothing.zip Link to comment Share on other sites More sharing options...
MisterInSayne Posted October 21, 2015 Share Posted October 21, 2015 I'm not sure what I'm doing wrong. Well, it might be usefull to explain what it is that does go wrong, and in what way it isn't working. Error, crash, not doing anything, only working sometimes, it's not showing x on y, etc. If it gives an error, show us what error is in your log. Link to comment Share on other sites More sharing options...
Mose Posted October 21, 2015 Author Share Posted October 21, 2015 I'm not sure what I'm doing wrong. Well, it might be usefull to explain what it is that does go wrong, and in what way it isn't working. Error, crash, not doing anything, only working sometimes, it's not showing x on y, etc. If it gives an error, show us what error is in your log. Right sorry. With what I've done so far, I think the TacticalVest should have the context menu option "Wear" but it doesn't. I didn't receive any errors though. Link to comment Share on other sites More sharing options...
MisterInSayne Posted October 21, 2015 Share Posted October 21, 2015 Right sorry. With what I've done so far, I think the TacticalVest should have the context menu option "Wear" but it doesn't. I didn't receive any errors though.Okay. First of all, testItem shouldn't be at line 330, line 330 is a different function that doesn't have that variable. it should be at line 140. Link to comment Share on other sites More sharing options...
Mose Posted October 21, 2015 Author Share Posted October 21, 2015 Right sorry. With what I've done so far, I think the TacticalVest should have the context menu option "Wear" but it doesn't. I didn't receive any errors though.Okay. First of all, testItem shouldn't be at line 330, line 330 is a different function that doesn't have that variable. it should be at line 140. Sorry! They are actually at different places in the file. I just pasted in what I added to those files so I wasn't pasting hundreds of lines of code. If you end up looking in the files I attached, I added "--TacticalClothing" before the lines I added so they can easily be found. Link to comment Share on other sites More sharing options...
Hydromancerx Posted October 22, 2015 Share Posted October 22, 2015 If you get anything to work I would be very interested since in my experience there are only a limited amount of slots; Chest, Back, Legs, Feet, Primary, Secondary and Head (cannot seem to get it to work). Link to comment Share on other sites More sharing options...
Mose Posted October 22, 2015 Author Share Posted October 22, 2015 When I finally got a container item into the torso slot, I got this error repeatedly. -----------------------------------------STACK TRACE-----------------------------------------Callframe at: setClothingItem_Torsofunction: perform -- file: ISWearClothing.lua line # 58java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at se.krka.kahlua.integration.expose.caller.MethodCaller.call(MethodCaller.java:61)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:199)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:189)at se.krka.kahlua.vm.KahluaThread.callJava(KahluaThread.java:182)at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:983)at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1642)at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:72)at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:74)at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:8667)at zombie.characters.IsoPlayer.update(IsoPlayer.java:2708)at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:1336)at zombie.iso.IsoCell.update(IsoCell.java:5164)at zombie.iso.IsoWorld.update(IsoWorld.java:2354)at zombie.gameStates.IngameState.update(IngameState.java:1216)at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)at zombie.GameWindow.logic(GameWindow.java:636)at zombie.GameWindow.run(GameWindow.java:1187)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168)Caused by: java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoGameCharacter.setClothingItem_Torso(IsoGameCharacter.java:1622)... 25 moreOct 22, 2015 11:22:36 AM zombie.GameWindow runSEVERE: nulljava.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoPlayer.save(IsoPlayer.java:908)at zombie.iso.IsoCell.savePlayer(IsoCell.java:5357)at zombie.GameWindow.savePlayer(GameWindow.java:1731)at zombie.iso.IsoWorld.render(IsoWorld.java:2043)at zombie.gameStates.IngameState.renderframe(IngameState.java:769)at zombie.gameStates.IngameState.render(IngameState.java:913)at zombie.gameStates.GameStateMachine.render(GameStateMachine.java:37)at zombie.GameWindow.render(GameWindow.java:685)at zombie.GameWindow.run(GameWindow.java:1193)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168) Does "java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothing" mean it's currently impossible? Link to comment Share on other sites More sharing options...
MisterInSayne Posted October 22, 2015 Share Posted October 22, 2015 When I finally got a container item into the torso slot, I got this error repeatedly. -----------------------------------------STACK TRACE-----------------------------------------Callframe at: setClothingItem_Torsofunction: perform -- file: ISWearClothing.lua line # 58java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at se.krka.kahlua.integration.expose.caller.MethodCaller.call(MethodCaller.java:61)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:199)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:189)at se.krka.kahlua.vm.KahluaThread.callJava(KahluaThread.java:182)at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:983)at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1642)at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:72)at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:74)at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:8667)at zombie.characters.IsoPlayer.update(IsoPlayer.java:2708)at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:1336)at zombie.iso.IsoCell.update(IsoCell.java:5164)at zombie.iso.IsoWorld.update(IsoWorld.java:2354)at zombie.gameStates.IngameState.update(IngameState.java:1216)at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)at zombie.GameWindow.logic(GameWindow.java:636)at zombie.GameWindow.run(GameWindow.java:1187)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168)Caused by: java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoGameCharacter.setClothingItem_Torso(IsoGameCharacter.java:1622)... 25 moreOct 22, 2015 11:22:36 AM zombie.GameWindow runSEVERE: nulljava.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoPlayer.save(IsoPlayer.java:908)at zombie.iso.IsoCell.savePlayer(IsoCell.java:5357)at zombie.GameWindow.savePlayer(GameWindow.java:1731)at zombie.iso.IsoWorld.render(IsoWorld.java:2043)at zombie.gameStates.IngameState.renderframe(IngameState.java:769)at zombie.gameStates.IngameState.render(IngameState.java:913)at zombie.gameStates.GameStateMachine.render(GameStateMachine.java:37)at zombie.GameWindow.render(GameWindow.java:685)at zombie.GameWindow.run(GameWindow.java:1193)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168) Does "java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothing" mean it's currently impossible? There is no such thing as impossible in coding. "Impossible" is a term used to describe a situation where "something takes more effort and time than it's worth". Your error means the item type "Clothing" is the only 'java object class' that can be equiped on the torso etc in the way your code currently works. Aniketos 1 Link to comment Share on other sites More sharing options...
Mose Posted October 22, 2015 Author Share Posted October 22, 2015 When I finally got a container item into the torso slot, I got this error repeatedly. -----------------------------------------STACK TRACE-----------------------------------------Callframe at: setClothingItem_Torsofunction: perform -- file: ISWearClothing.lua line # 58java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at se.krka.kahlua.integration.expose.caller.MethodCaller.call(MethodCaller.java:61)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:199)at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:189)at se.krka.kahlua.vm.KahluaThread.callJava(KahluaThread.java:182)at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:983)at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1642)at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:72)at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:74)at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:8667)at zombie.characters.IsoPlayer.update(IsoPlayer.java:2708)at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:1336)at zombie.iso.IsoCell.update(IsoCell.java:5164)at zombie.iso.IsoWorld.update(IsoWorld.java:2354)at zombie.gameStates.IngameState.update(IngameState.java:1216)at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)at zombie.GameWindow.logic(GameWindow.java:636)at zombie.GameWindow.run(GameWindow.java:1187)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168)Caused by: java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoGameCharacter.setClothingItem_Torso(IsoGameCharacter.java:1622)... 25 moreOct 22, 2015 11:22:36 AM zombie.GameWindow runSEVERE: nulljava.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothingat zombie.characters.IsoPlayer.save(IsoPlayer.java:908)at zombie.iso.IsoCell.savePlayer(IsoCell.java:5357)at zombie.GameWindow.savePlayer(GameWindow.java:1731)at zombie.iso.IsoWorld.render(IsoWorld.java:2043)at zombie.gameStates.IngameState.renderframe(IngameState.java:769)at zombie.gameStates.IngameState.render(IngameState.java:913)at zombie.gameStates.GameStateMachine.render(GameStateMachine.java:37)at zombie.GameWindow.render(GameWindow.java:685)at zombie.GameWindow.run(GameWindow.java:1193)at zombie.GameWindow.maina(GameWindow.java:991)at zombie.gameStates.MainScreenState.main(MainScreenState.java:168) Does "java.lang.ClassCastException: zombie.inventory.types.InventoryContainer cannot be cast to zombie.inventory.types.Clothing" mean it's currently impossible? There is no such thing as impossible in coding. "Impossible" is a term used to describe a situation where "something takes more effort and time than it's worth". Your error means the item type "Clothing" is the only 'java object class' that can be equiped on the torso etc in the way your code currently works. I was just curious if that particular error that was caused by something I can't modify through lua. The only reason I thought that might be the case is that the game became unresponsive while repeatedly giving that error. So far I've only had minor non-game-crashing bugs. Link to comment Share on other sites More sharing options...
Aniketos Posted October 23, 2015 Share Posted October 23, 2015 If it does prove to be something that you can't modify using LUA, it may still be possible with some creativity... Say, an invisible, weightless container item in the player's inventory (or perhaps referenced only in the player's modData?) along with an associated clothing item that has the invisible container's contents' weight attributed to it. When the clothing item is equipped, equip the container as well, and adjust the clothing item's weight to reflect the container's weight reduction factor. When the clothing item is removed, unequip the container and update the clothing item to remove the weight reduction factor adjustment. Of course, you'd have to adjust the clothing item's weight every time items are moved in and out of the invisible container, as well.I'm not sure if this exact approach is plausible, just giving an example of a creative solution Sykriss and Mose 2 Link to comment Share on other sites More sharing options...
Mose Posted October 28, 2015 Author Share Posted October 28, 2015 I am still working on something similar to this. I would like to go through the player's inventory and compare the modData of each item to something. If possible I'd like to do something like this for each item in the inventoryif item.getModData().foo = foo then return true;endHow would I go about it? 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