hippokittie Posted September 10, 2014 Share Posted September 10, 2014 So I have been working for a few weeks on making and fixing up this code, and am at an impasse. I have the weapon equipping and swinging, but nothing is happening to the monsters. I have the code broken into 2 parts, 1 for the swinging and equip, and 1 (attached to a collision entity on the weapons blade) that when it collides with an enemy ai it is supposed to remove health from them. The second code I also plan on tweaking to include everyone who touches it (for traps) but have no clue. The code that isn't working is here. import "Scripts/Objects/Player/FPSWeapon.lua" Script.damage=10 function Script:Start() self.enabled=true end function Script:Collision(entity, position, normal, speed) if self.enabled then self.component:CallOutputs("Collision") end end function Script:Fire() local enemy = self:FindScriptedParent(Collision.entity,"Hurt") if enemy.script.health>0 then enemy.script:Hurt(self.damage,self.player) end --Blood emitter e = self.emitter[2]:Instance() e = tolua.cast(e,"Emitter") e:Show() e:SetLoopMode(false,true) e:SetPosition(pickinfo.position+pickinfo.normal*0.1) e:SetVelocity(0,0,0) end I brought in collision code directly into it so it would know what it was looking for, and imported the script for fps weapon to get the damage system working. It is showing no errors but at the same time doesn't do anything. Any Ideas? I just want to get it working, so I can tweak it for each weapon and trap. Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
Rick Posted September 10, 2014 Share Posted September 10, 2014 You are firing an output in Collision() but you aren't doing any damage. Take a look at this script which gives you an OnEnter/OnLeave collision. http://leadwerks.wikidot.com/wiki:collision-enter-exit In the OnEnter is where you would want to call some sort of :Hurt() function on the entity passed into the collision (if the entity passed in is some sort of actor). Quote Link to comment Share on other sites More sharing options...
hippokittie Posted September 10, 2014 Author Share Posted September 10, 2014 Helpful, but confusing. So with this kinda code it should fire off everytime the blade makes contact? import "Scripts/Objects/Player/FPSWeapon.lua" Script.damage=10 Script.entered = false Script.exited = false Script.hadCollision = false function Script:Start() self.enabled=true end function Script:Fire() local enemy = self:FindScriptedParent(Collision.entity,"Hurt") if enemy.script.health>0 then enemy.script:Hurt(self.damage,self.player) end --Blood emitter e = self.emitter[2]:Instance() e = tolua.cast(e,"Emitter") e:Show() e:SetLoopMode(false,true) e:SetPosition(pickinfo.position+pickinfo.normal*0.1) e:SetVelocity(0,0,0) end function Script:UpdatePhysics() if self.entered then Fire=true end if self.hadCollision == false then if self.exited == false then self.exited = true self.component:CallOutputs("OnExit") self.entered = false end end end self.hadCollision = false end function Script:Collision(entity, position, normal, speed) self.hadCollision = true self.component:CallOutputs("OnCollide") if self.entered == false then self.component:CallOutputs("OnEnter") self.entered = true self.exited = false end end Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
Rick Posted September 10, 2014 Share Posted September 10, 2014 So if you have this attached to your weapon then whenever the weapon collides with some other physics the Script:Collision() function is called by the engine and passes in the entity it collided with (the first parameter). It calls the output OnEnter, but that's for the flowgraph which you probably don't have setup and really don't need it here, but it helps to point out OnCollide vs OnEnter. Under CallOutputs("OnEnter") you can get the entities script and see if it has a Hurt() function (if it's an "actor" which you have to implement or if you are already using the AI.lua script). if entity.script.Hurt ~= nil then entity.script:Hurt(10) end Quote Link to comment Share on other sites More sharing options...
hippokittie Posted September 10, 2014 Author Share Posted September 10, 2014 So I plugged the script into the the editor, and still nothing. I don't know what I am doing wrong.............. The ai script I am using for the test is just the default ai script, altered the name and animation sequences, from leadwerks. I took the hurt function directly from the fpsweapon (that I called) and the ai has functions for hurt. The collision is set on a collision box on the blade as a prop, and I even tried making the box larger to see if that would work but it didn't... I am so confused Quote Will Hall Morphodox Studios 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.