Joined: Sat Nov 10, 2012 3:31 pm Posts: 114 Location: Australia
Eye lasers
I wish to use eye lasers for an ahuman (the head is where the gun is. I can't seem to attach the arms to the head), but I don't want it to be a continuous laser. I'm using an old laser script posted ages ago, as such:
Code:
function Create(self) local thisID = ToActor(self).ID local MoObj for i = 1, MovableMan:GetMOIDCount() do if (i ~= thisID) and (MovableMan:GetRootMOID(i) == thisID) then -- an obj without a parent has ID == RootID MoObj = MovableMan:GetMOFromID(i) if MoObj.PresetName == "Pod Head A" then -- Name of the actor's HEAD here. self.Head = ToAttachable(MoObj) break end end end end
function Update(self) if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() then local Emitter = CreateAEmitter("TA Laser", "Terran Alliance.rte") -- Name of the emitter and .rte here. Emitter.Vel = self.Vel
if self.HFlipped then Emitter.RotAngle = self.Head.RotAngle + 3.1415 else Emitter.RotAngle = self.Head.RotAngle end
Emitter.Pos = self.Head.Pos + self.Head:RotateOffset(Vector(40, 12)) -- Use self.EyePos instead? Probably no need. MovableMan:AddParticle(Emitter) end end
What would I add to this to space out the shots more? And, as an aside, how would I go about making this spawn MOSParticles rather than AEmitters? Sorry if this question is easily answered, I am not good with LUA.
Fri Nov 01, 2013 9:30 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Eye lasers
I'm not sure what you mean by space the shots out more? The script seems to fire one TA Laser every time you press the fire button. To make it fire MOSParticles, just change this line:
Code:
local Emitter = CreateAEmitter("TA Laser", "Terran Alliance.rte")
to this:
Code:
local Emitter = CreateMOSParticle("TA Laser", "Terran Alliance.rte")
You can also change the local Emitter to local MOSParticle (or whatever you want), but make sure to change the other places where Emitter is used as well.
Simply defines a local variable with the name \var\.
Sat Nov 02, 2013 8:14 pm
omegadrace
Joined: Sat Nov 10, 2012 3:31 pm Posts: 114 Location: Australia
Re: Eye lasers
It doesn't fire a single shot, it fires a steady stream as long as the button is pressed. I want to add a small space between the shots.
And thank you, I'll get to changing it to mosparticle.
Sun Nov 03, 2013 2:16 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Eye lasers
Code:
function Create(self)
self.ShootTimer = Timer(); --define a timer to self.ShootTimer
local thisID = ToActor(self).ID local MoObj for i = 1, MovableMan:GetMOIDCount() do if (i ~= thisID) and (MovableMan:GetRootMOID(i) == thisID) then -- an obj without a parent has ID == RootID MoObj = MovableMan:GetMOFromID(i) if MoObj.PresetName == "Pod Head A" then -- Name of the actor's HEAD here. self.Head = ToAttachable(MoObj) break end end end end
function Update(self)
if self.ShootTimer:IsPastSimMS(100) then --change the number here to make the delay shorter/longer, currently set to 0.1 second
if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() then local MOSParticle = CreateMOSParticle("TA Laser", "Terran Alliance.rte") -- Name of the emitter and .rte here. MOSParticle.Vel = self.Vel
if self.HFlipped then MOSParticle.RotAngle = self.Head.RotAngle + 3.1415 else MOSParticle.RotAngle = self.Head.RotAngle end
MOSParticle.Pos = self.Head.Pos + self.Head:RotateOffset(Vector(40, 12)) -- Use self.EyePos instead? Probably no need. MovableMan:AddParticle(MOSParticle)
self.ShootTimer:Reset(); --reset the timer after the shot has been fired end end end
This code should work to add a delay to the shots, you'll just need to adjust the time to whatever you want.
Sun Nov 03, 2013 3:49 am
omegadrace
Joined: Sat Nov 10, 2012 3:31 pm Posts: 114 Location: Australia
Re: Eye lasers
Alright, that works perfectly! Thank you. My next question is, how would I go about having certain parts of that script active when the actor is holding a certain weapon? Set out probably like this:
Code:
if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() and (Detect specific gun?) then (do that specific laser firing) end if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() and (Detect another specific gun?) then (do another specific laser firing) end if self.Head:IsAttached() and (Neither of those guns?) then (Drop whatever is being held) end end
Is this possible?
Sun Nov 03, 2013 2:03 pm
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Eye lasers
Yup, self.EquippedItem.PresetName("GunNameHere") is what you want to use in the if statements. For the last one you can do
Code:
if self.Head:IsAttached() and not self.EquippedItem.PresetName("GunNameHere1") and not self.EquippedItem.PresetName("GunNameHere2") then self:GetController():SetState(Controller.WEAPON_DROP,true) end
Again, untested code written from memory in 3 minutes, so don't sue me if it doesn't work .
Sun Nov 03, 2013 3:53 pm
omegadrace
Joined: Sat Nov 10, 2012 3:31 pm Posts: 114 Location: Australia
Re: Eye lasers
I had to remove the brackets for it to detect the guns for the different laser types like so:
Code:
if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() and self.EquippedItem.PresetName == "Pulse Laser Module" then
But the dropping part didn't work. The actor can still pick up things with reckless abandon, with no errors in sight.
Mon Nov 04, 2013 6:29 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Eye lasers
Oops, I completely forgot about this thread, sorry about that!
Anyway, glad that you managed to correct my bad code for the equipped weapon name thingy. On the weapon drop part: You could try dropping in a print after the if statement, just to check that the code is actually getting to the weapon drop part. Also, that code, if it was working, would just tell the actor to drop what ever he's holding, it doesn't stop the actor from immediatedly picking the weapon up again, that would require a bit more code.
Let me know if you still need help, or already managed to figure it out yourself.
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