Data Realms Fan Forums
http://45.55.195.193/

LUA: Using JoyButtonReleased for burst mode
http://45.55.195.193/viewtopic.php?f=1&t=45548
Page 1 of 1

Author:  numanair [ Fri Jan 17, 2014 8:50 am ]
Post subject:  LUA: Using JoyButtonReleased for burst mode

I am trying to create a burst mode pistol that is not fully automatic. This means when you hold the trigger it will only fire one burst (3 rounds). I am using UInputMan:JoyButtonReleased in a modified version of the Burst.lua from the coalition autopistol.

The problem is getting it to work with the current player's controller instead of only player 1's controller.

Code:
if self.canBurst == false then
   self:Deactivate();
   if UInputMan:JoyButtonReleased(0,5) then
      self.canBurst = true;

Author:  Vlads [ Fri Jan 17, 2014 12:45 pm ]
Post subject:  Re: LUA: Using JoyButtonReleased for burst mode

Umm....Isn't there's already a burst-fire script for the Coalition auto pistol?

Author:  Bad Boy [ Fri Jan 17, 2014 4:18 pm ]
Post subject:  Re: LUA: Using JoyButtonReleased for burst mode

This seems like a very silly way of doing it, using only the joybutton means it'll only work for controllers, whereas if you use the actor's lua controller (the lua interface rather not the physical controller) you can probably make it work with any control scheme.
Either way, you'd need to get the actor holding the gun and get his player or controller. So something like the following would probably help:
Code:
function Create(self)
self.Parent = nil;
self.ParentPlayer = nil;
function Update(self)
  --If it's not being held by an actor, set its parent and parent player to nil
  if self.ID == self.RootID then
    self.Parent = nil;
    self.ParentPlayer = nil;
  --If it is being held, give it a parent and find the parent's player
  else
    if self.Parent == nil or self.ParentPlayer == nil then
    self.Parent = MovableMan:GetMOFromID(self.ID);
    self.ParentPlayer = self.Parent:GetController().Player;
  end
  --Your stuff follows, except the 0 in joybuttonreleased is changed to self.ParentPlayer
  --Also, you should consider using self.Parent:GetController():IsState(Controller.RELEASE_PRIMARY) instead of uinputman stuff
end

By the way, this should probably have been in the lua scripting subforum.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/