hippokittie Posted December 7, 2014 Share Posted December 7, 2014 Hey guys we have made a good melee weapon code, with help of some people on the forums and some goofing around on our part. It was working fine up until about 2 weeks ago, then it had an error on line 28 in the code saying "attempting to compare nil value". If you guys could help tell me what I am doing wrong that would be amazing. This is part of a melee/rpg pack I am working on for you guys to be able to use (featured in my game). Here is the code, feel free to use it but do tell me how to fix it @.@ import "Scripts/AnimationManager.lua" Script.offset = Vec3(.5,-.5,.3) --vec3 "Offset" --used to set the location of the weapon in relationship to the fpsplayer's camera Script.bulletrange=3 Script.bulletforce=10 Script.bulletdamage=24 function Script:Start() --self.entity:SetRotation(45,180,0) --cant set it here unless you change the fpsplayer script -- fpsplayer script sets the weapons rotation to (0,0,0) after it has been loaded self.fired = 0 -- self.animationmanager = AnimationManager:Create(self.entity)--sets up animationmanager end function Script:Fire() --using this just so i dont have to mess with the fpsplayer script self.animationmanager:SetAnimationSequence("swing",0.05,300,1) --Parameters = (sequence, speed, blendtime, mode) -- sequence equal to "swing" animation in model -- speed controls how fast to play animation -- blendtime controls how fast it changes from the previous animation -- mode controls whether animation plays once or loops. --App.camera:Pick() if (App.window:MouseDown(1)) then --self.picksphere:Hide() local pickinfo = PickInfo() --local p = self:GetMousePosition() local p = App.window:GetMousePosition() if (self.entity.location < bulletrange) then if entity.script.enemy==true then entity.script:Hurt(self.bulletdamage) else System:Print("nope") end end end end function Script:Reload() --using this becaue inherent fpsplayer script calls this function when R is hit self.animationmanager:SetAnimationSequence("idle",0.05,300,1) end function Script:BeginJump() -- called from fpsplayer end function Script:BeginLand() -- called from fpsplayer end function Script:Draw() self.entity:SetRotation(45,180,0) --settting the model's rotation to be able to see it --Animate the weapon self.animationmanager:Update() end function Script:Release() end 2 Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
darklord987 Posted December 18, 2014 Share Posted December 18, 2014 In the Script:Start function right underneath it add self.entity:Hide() There is a ghost model and this removes it. Still trying to fix the left click error myself. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted December 20, 2014 Share Posted December 20, 2014 Sorry for the late reply, but I'd assume 'enemy' doesn't exist in the 'entity.script' table, I haven't tried but although not the cleanest thin to do you could make it into: if (self.entity.location < bulletrange) then if entity.script.enemy~=nil and entity.script.enemy==true then entity.script:Hurt(self.bulletdamage) else System:Print("nope") end end I don't really know when 'enemy' gets defined, so may as-well check to ensure it exists. But why build a Melee weapon object when Leadwerks comes with one? 1 Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 20, 2014 Author Share Posted December 20, 2014 Sorry for the late reply, but I'd assume 'enemy' doesn't exist in the 'entity.script' table, I haven't tried but although not the cleanest thin to do you could make it into: if (self.entity.location < bulletrange) then if entity.script.enemy~=nil and entity.script.enemy==true then entity.script:Hurt(self.bulletdamage) else System:Print("nope") end end I don't really know when 'enemy' gets defined, so may as-well check to ensure it exists. But why build a Melee weapon object when Leadwerks comes with one? I made this script before that, as well as event the built in melee script doesn't work (it doesn't show my weapon or do damage just makes sounds). This script(though no sounds) had the weapon showing and did damage to them. I would gladly use the bilt in one if it was able to hurt things and show my weapon in the proper way. 1 Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
acd009 Posted December 21, 2014 Share Posted December 21, 2014 did you set the weapons off set in the built in melee script for leadwerks as that might be the problem why the weapon isnt showing 1 Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 21, 2014 Author Share Posted December 21, 2014 did you set the weapons off set in the built in melee script for leadwerks as that might be the problem why the weapon isnt showing I set the same offset my code has, and its still not there. It may also be rotated wrong, but when I try to change them it still isnt visible. The biggest issue is that it doesn't do damage to anything (I know because I set a creature to have a total of 2 hp and the weapon to do 50 ran around it facing every direction I could to try to hit it and nothing. 1 Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
darklord987 Posted December 21, 2014 Share Posted December 21, 2014 I myself have been trying to modify the code cause the stock code does not work at all. I made one modification that worked, but I am stumped at the rest of the code. I hope we can get this working ASAP and then make them replace the stock code with this. Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 21, 2014 Author Share Posted December 21, 2014 I myself have been trying to modify the code cause the stock code does not work at all. I made one modification that worked, but I am stumped at the rest of the code. I hope we can get this working ASAP and then make them replace the stock code with this. I agree, but Josh is hard at work making sure the engine works properly so we will just have to mess around with the code till we get it working and give it out Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
Josh Posted December 21, 2014 Share Posted December 21, 2014 It works fine with the knife in the FPS weapons pack. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
darklord987 Posted December 21, 2014 Share Posted December 21, 2014 I tried using the code and it fails or crashes the game. I am using a very simple sword model. What exactly did you do that made yours work? Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted December 21, 2014 Share Posted December 21, 2014 I'm just working on networking, a UI library, and all the main things for my game right now: once I get to weapons and stuff I'd gladly post some tutorials. 1 Quote Link to comment Share on other sites More sharing options...
darklord987 Posted December 21, 2014 Share Posted December 21, 2014 I have had some progress with the melee code. Now the code I wrote is very similar to the default, but it shows the weapon. No animation yet though. Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 21, 2014 Author Share Posted December 21, 2014 I have had some progress with the melee code. Now the code I wrote is very similar to the default, but it shows the weapon. No animation yet though. what about putting int the set animation from my code to it? As well as the idle? Does it actually attack? Let me know bro!!! 1 Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
darklord987 Posted December 22, 2014 Share Posted December 22, 2014 I am matching the two codes together as we speak. currently it uses your Draw function and the default melee code. Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 22, 2014 Author Share Posted December 22, 2014 I am matching the two codes together as we speak. currently it uses your Draw function and the default melee code. Well that is good dark, with the default code it would add in sounds and adjust offset and rotation (based on what is in the code) but then again its possible that the fpsplayer script could have issues with weapons and changes their offset and rotation. It may also be because of the change in monster script that we are having issues with the damage. I did notice when I tried the default weapon script (melee) that it would produce code errors when you die looking for muzzle to hide. Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
Kotaros Posted February 12, 2015 Share Posted February 12, 2015 ty i try it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.