Jump to content

Melee code for you guys!


hippokittie
 Share

Recommended Posts

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

  • Upvote 2

Will Hall

Morphodox Studios

Link to comment
Share on other sites

  • 2 weeks later...

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?

  • Upvote 1
Link to comment
Share on other sites

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.

  • Upvote 1

Will Hall

Morphodox Studios

Link to comment
Share on other sites

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.
  • Upvote 1

Will Hall

Morphodox Studios

Link to comment
Share on other sites

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 :)

Will Hall

Morphodox Studios

Link to comment
Share on other sites

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!!!
  • Upvote 1

Will Hall

Morphodox Studios

Link to comment
Share on other sites

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.

Will Hall

Morphodox Studios

Link to comment
Share on other sites

  • 1 month later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...