Data Realms Fan Forums http://45.55.195.193/ |
|
Lua Command Problem http://45.55.195.193/viewtopic.php?f=73&t=18844 |
Page 1 of 2 |
Author: | Benpasko [ Thu May 27, 2010 9:11 pm ] |
Post subject: | Lua Command Problem |
Okay, how do I check if a certain button is pressed? In this case, I need to double-tap crouch to use an attack. |
Author: | Geti [ Thu May 27, 2010 9:42 pm ] |
Post subject: | Re: Lua Command Problem |
get the actor's controller object, like Code: local controller = someactor:GetController() Code: if controller:IsState(10) then --crouch was pressed do something end |
Author: | Benpasko [ Thu May 27, 2010 9:59 pm ] |
Post subject: | Re: Lua Command Problem |
Ermm...Right over my head. I don't really know anything about Lua in the slightest. |
Author: | Areku [ Thu May 27, 2010 10:31 pm ] |
Post subject: | Re: Lua Command Problem |
Geti wrote: get the actor's controller object, like Code: local controller = someactor:GetController() Code: if controller:IsState(10) then --crouch was pressed do something end Actually, you can condense that, as in: Code: if someactor:GetController:IsState(BODY_CROUCH) then And you don't even need the numeric code, just type the state's name. Oh, and Ben, I'm sure there are a few Lua tutorials around, you'd better check into that. But what exactly are you gonna use the script for? |
Author: | Benpasko [ Thu May 27, 2010 11:05 pm ] |
Post subject: | Re: Lua Command Problem |
I'm gonna attach the neck breaker script to an actor, instead of the glove. What do I put for "Someactor"? Is it self.ID? Edit: No luck. Here's the script, as I said, I have no experience. function Update(self) if self.IF:GetController:IsState(BODY_CROUCH) then --Cast a MO ray, from that ID, get the matching MO local x = MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*0.2), self.ID, 0, true, 0)) if x.ClassName == "Attachable" then local head = ToAttachable(x); head.RotAngle = math.pi/2; local actor = ToActor(MovableMan:GetMOFromID(head.RootID)); if actor.ClassName == "AHuman" then actor:SetAimAngle(math.pi/2); actor.Health = 0 - math.random(100); snap = CreateAEmitter("NB Sound FX","Neck Breaker.rte"); snap.Pos = actor.Pos; MovableMan:AddParticle(snap); end end end |
Author: | Areku [ Fri May 28, 2010 1:53 am ] |
Post subject: | Re: Lua Command Problem |
Well, first of all, you don't need the self.ID: just "self" is enough. Actually, self.ID will most likely mess up your code if used in the wrong places. Second, the math.random is (as far as I know) missing an argument. The correct would be math.random(0,100), to define the upper and lower number limits. Third, I'm really inexperienced with raycasting, so I'm not sure if your MORay is being used properly, but it looks sound enough to me. So yeah, it's probably the self.ID what's causing the problem. |
Author: | Grif [ Fri May 28, 2010 3:10 am ] |
Post subject: | Re: Lua Command Problem |
It should also be Controller.BODY_CROUCH, not just Body_Crouch. |
Author: | Benpasko [ Fri May 28, 2010 3:26 am ] |
Post subject: | Re: Lua Command Problem |
Still nothing. I'm not sure why it won't work. Complete Current Code: Code: function Update(self) if self:GetController:IsState(Controller.BODY_CROUCH) then --Cast a MO ray, from that ID, get the matching MO local x = MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*2.0), self.ID, 0, true, 0)) if x.ClassName == "Attachable" then local head = ToAttachable(x); head.RotAngle = math.pi/2; local actor = ToActor(MovableMan:GetMOFromID(head.RootID)); if actor.ClassName == "AHuman" then actor:SetAimAngle(math.pi/2); actor.Health = 0 - math.random(100); snap.Pos = actor.Pos; end end end |
Author: | Geti [ Fri May 28, 2010 5:13 am ] |
Post subject: | Re: Lua Command Problem |
Areku wrote: Actually, you can condense that, as in: Code: if someactor:GetController:IsState(BODY_CROUCH) then It's faster to use a local variable and nicer on the eyes to use the numeration, as well as netting you a pointer to the actor's controller which would be handy if you needed to check anything else or apply some other control states. Code: function Update(self) if self:GetController():IsState(Controller.BODY_CROUCH) then --Cast a MO ray, from that ID, get the matching MO local x = MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*2.0), self.ID, 0, true, 0)) if x.ClassName == "Attachable" then local head = ToAttachable(x); head.RotAngle = math.pi/2; local actor = ToActor(MovableMan:GetMOFromID(head.RootID)); if actor.ClassName == "AHuman" then actor:SetAimAngle(math.pi/2); actor.Health = 0 - math.random(100); snap.Pos = actor.Pos; end end end |
Author: | Areku [ Fri May 28, 2010 3:00 pm ] |
Post subject: | Re: Lua Command Problem |
Geti wrote: hah, you missed the () on GetController(), it's a function. What?! Dang. Areku's bad memory strikes again. |
Author: | Geti [ Sat May 29, 2010 12:15 am ] |
Post subject: | Re: Lua Command Problem |
Hahah, never mind, it just pays to check those kinds of things before posting in the help forums. |
Author: | Benpasko [ Sat May 29, 2010 11:49 am ] |
Post subject: | Re: Lua Command Problem |
It's still not working. |
Author: | Areku [ Sat May 29, 2010 1:59 pm ] |
Post subject: | Re: Lua Command Problem |
How exactly is it not working? Does it give any error message at all? Try popping up the Lua console (depending on your system language, might be the ~, ; or ' key) and seeing what it shows. |
Author: | Benpasko [ Sun May 30, 2010 6:01 pm ] |
Post subject: | Re: Lua Command Problem |
No errors, and it just does nothing. I have it attached to an actor, could that be an issue? |
Author: | Geti [ Sun May 30, 2010 9:26 pm ] |
Post subject: | Re: Lua Command Problem |
-> debug like the pros do, chuck print("casting ray"), print("neckbreak") etc in every spot there could be trouble and see how far it gets. Also it's meant to be attached to an actor, don't worry about that. We've probably just done something wrong. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |