Author |
Message |
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Burst Fire Script
I want to make a burst fire script. It is attached to the tracer round of the gun, and it stops the actor firing the gun. So the actor should fire for example three rounds and prevents the actor from firing for a while. But the script is not working. Ideas? Code: function Create(self) self.TimerL = Timer() self.Fire = 0 local curdist = 500; for actors in MovableMan.Actors do local avgx = actors.Pos.X - self.Pos.X; local avgy = actors.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist and actor:HasObject("Assault Rifle Ex.") then curdist = dist; self.parent = actors;
end end
end
function Update(self) if self.TimerL:IsPastSimMS(500) then self.Fire = 1 end if self.Fire == 0 then self.parent:GetController():SetState(14,false) end end Thanks.
|
Sat Jul 23, 2011 4:26 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Burst Fire Script
Well, one problem could be that the round settles/deletes before the timer ends.
You could also try disabling the firearm instead of the actor's ability to fire, that might get it to work.
|
Sat Jul 23, 2011 6:54 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
And how would I disable the firearm?
Aside from getting the gun as parent, which is the specific command to disable it?
|
Sat Jul 23, 2011 10:09 pm |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Burst Fire Script
You would need to get the firearm first (In which CC48 has some fancy way of getting it by getting all the MO's and Checking if a certain one is equiped by your defined parent, Which is still beyond me) and just add: Actually, would self.RootID work? This is how you Disable any Device. Code: yourweapon:Deactivate()
|
Sat Jul 23, 2011 11:15 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
Code: function Create(self) self.TimerR = Timer() local curdist = 150; for i = 1,MovableMan:GetMOIDCount()-1 do gun = MovableMan:GetMOFromID(i); if gun.PresetName == "Assault Rifle Ex." and gun.ClassName == "HDFirearm" and (gun.Pos-self.Pos).Magnitude < curdist then actor = MovableMan:GetMOFromID(gun.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentgun = ToHDFirearm(gun); end end end end
function Update(self) if self.TimerR:IsPastSimMS(400) then self.parentgun:Activate() else self.parentgun:Deactivate() end end Tried this code, but it doesn't work. It's not giving me errors either.
|
Sat Jul 23, 2011 11:40 pm |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Burst Fire Script
Check if it even gets the weapon.
|
Sat Jul 23, 2011 11:44 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
Got two errors after adding the print, I didn't notice the first one though, so I had to take a screen shot to read it. So it means that it is not recognizing the gun.
|
Sun Jul 24, 2011 1:16 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Burst Fire Script
Dont use this: Code: (gun.Pos-self.Pos).Magnitude < curdist It doesn't check scene wrapping very well and can mess it up. SceneMan:ShortestDistance() works better.
|
Sun Jul 24, 2011 1:41 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
Not working, I get the same error. Made a couple of tweakings, but I can't get it to work. Code: function Create(self) self.TimerR = Timer() local curdist = 150; for i = 1,MovableMan:GetMOIDCount()-1 do gun = MovableMan:GetMOFromID(i); if gun.PresetName == "Assault Rifle Ex." and gun.ClassName == "HDFirearm" and SceneMan:ShortestDistance(self.Pos,self.gun.Pos,self.mapwrapx).Magnitude < curdist then actor = MovableMan:GetMOFromID(gun.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); self.parentgun = ToHDFirearm(gun); end end end print(self.parentgun) end
function Update(self) if not self.TimerR:IsPastSimMS(400) then self.parentgun:Deactivate() end end This is the script currently.
|
Sun Jul 24, 2011 2:05 am |
|
|
Coops
Joined: Wed Feb 17, 2010 12:07 am Posts: 1545 Location: That small peaceful place called Hell.
|
Re: Burst Fire Script
First Argument for ShortestDistance() is the starting Position Second is the ending Position Third is a boolean (True or False) for whether to check if the passed in points are outside the scene, and to wrap them if they are.
Not only that but you got self.gun.Pos when you should be using just gun.Pos.
|
Sun Jul 24, 2011 2:16 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
Let me copy that part of the code from a script of CaveCricket. (Please?) EDIT: Code: function Create(self) self.TimerR = Timer()
self.mainweaponname = "Assault Rifle Ex."; self.mainweaponclass = "HDFirearm";
for i = 1,MovableMan:GetMOIDCount()-1 do self.gun = MovableMan:GetMOFromID(i); if self.gun.PresetName == self.mainweaponname and self.gun.ClassName == self.mainweaponclass and SceneMan:ShortestDistance(self.Pos,self.gun.Pos,true).Magnitude < 120 then self.parentgun = ToHDFirearm(self.gun); end end print(self.parentgun.PresetName) end function Update(self) if not self.TimerR:IsPastSimMS(400) then self.parentgun:Deactivate() end end Well, now it does print the gun's preset name, so I suppose that everything on the create function is working. But nothing else works and I'm not getting errors.
|
Sun Jul 24, 2011 2:22 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Burst Fire Script
Code: function Create(self)
self.lifeTimer = Timer();
local curdist = 120; for i = 1, MovableMan:GetMOIDCount()-1 do local gun = MovableMan:GetMOFromID(i); if gun.ClassName == "HDFirearm" and gun.PresetName == "Assault Rifle Ex." and SceneMan:ShortestDistance(self.Pos,ToHDFirearm(gun).MuzzlePos,SceneMan.SceneWrapsX).Magnitude < curdist then self.parentgun = ToHDFirearm(gun); local actor = MovableMan:GetMOFromID(gun.RootID); if MovableMan:IsActor(actor) then self.parent = ToActor(actor); end break; end end
end
function Update(self)
if self.lifeTimer:IsPastSimMS(400) == false and self.parentgun ~= nil and self.parentgun.ID ~= 255 then self.parentgun:Deactivate(); if MovableMan:IsActor(self.parent) then self.parent:GetController():SetState(Controller.WEAPON_FIRE,false); end end
end
I forgot that player controls sometimes override Lua 'controls'. So now the script disables both the firearm AND the actor's firing. Also, like I said earlier, there's the issue were shooting at something will cause the particle to delete, prematurely ending the delay timer. I can get a better method for you, but this is how you initially wanted it.
|
Sun Jul 24, 2011 8:13 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Burst Fire Script
That works overly perfect.
Thanks for the help Coops and CC.
|
Wed Jul 27, 2011 9:08 pm |
|
|
|