View unanswered posts | View active topics It is currently Mon Dec 30, 2024 11:05 pm



Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
 Lua Command Problem 
Author Message
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua Command Problem
It should also be Controller.BODY_CROUCH, not just Body_Crouch.


Fri May 28, 2010 3:10 am
Profile
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post Re: Lua Command Problem
It's still not working.


Sat May 29, 2010 11:49 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Aug 09, 2009 9:26 am
Posts: 1633
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.062s | 16 Queries | GZIP : Off ]