Author |
Message |
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
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.
|
Thu May 27, 2010 9:11 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Lua Command Problem
get the actor's controller object, like Code: local controller = someactor:GetController() then use http://wiki.datarealms.com/wiki/index.p ... Controller 's methods to check the BODY_CROUCH like Code: if controller:IsState(10) then --crouch was pressed do something end you'll have to set up the doubletab stuff yourself, it'll just be a timer check.
|
Thu May 27, 2010 9:42 pm |
|
|
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
Re: Lua Command Problem
Ermm...Right over my head. I don't really know anything about Lua in the slightest.
|
Thu May 27, 2010 9:59 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Lua Command Problem
Geti wrote: get the actor's controller object, like Code: local controller = someactor:GetController() then use http://wiki.datarealms.com/wiki/index.p ... Controller 's methods to check the BODY_CROUCH like Code: if controller:IsState(10) then --crouch was pressed do something end you'll have to set up the doubletab stuff yourself, it'll just be a timer check. 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?
|
Thu May 27, 2010 10:31 pm |
|
|
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
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
|
Thu May 27, 2010 11:05 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
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.
|
Fri May 28, 2010 1:53 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua Command Problem
It should also be Controller.BODY_CROUCH, not just Body_Crouch.
|
Fri May 28, 2010 3:10 am |
|
|
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
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
|
Fri May 28, 2010 3:26 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Lua Command Problem
Areku wrote: Actually, you can condense that, as in: Code: if someactor:GetController:IsState(BODY_CROUCH) then Yes, you can, though you'd need to do someactor:GetController():IsState(Controller.BODY_CROUCH) which is damned ugly. 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 hah, you missed the () on GetController(), it's a function.
|
Fri May 28, 2010 5:13 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Lua Command Problem
Geti wrote: hah, you missed the () on GetController(), it's a function. What?! Dang. Areku's bad memory strikes again.
|
Fri May 28, 2010 3:00 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Lua Command Problem
Hahah, never mind, it just pays to check those kinds of things before posting in the help forums.
|
Sat May 29, 2010 12:15 am |
|
|
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
Re: Lua Command Problem
It's still not working.
|
Sat May 29, 2010 11:49 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
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.
|
Sat May 29, 2010 1:59 pm |
|
|
Benpasko
Joined: Sun Aug 09, 2009 9:26 am Posts: 1633
|
Re: Lua Command Problem
No errors, and it just does nothing. I have it attached to an actor, could that be an issue?
|
Sun May 30, 2010 6:01 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Sun May 30, 2010 9:26 pm |
|
|
|
Who is online |
Users browsing this forum: No registered users |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|