Data Realms Fan Forums http://45.55.195.193/ |
|
Burst Fire Script http://45.55.195.193/viewtopic.php?f=73&t=24750 |
Page 1 of 1 |
Author: | Asklar [ Sat Jul 23, 2011 4:26 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Sat Jul 23, 2011 6:54 am ] |
Post subject: | 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. |
Author: | Asklar [ Sat Jul 23, 2011 10:09 pm ] |
Post subject: | 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? |
Author: | Coops [ Sat Jul 23, 2011 11:15 pm ] |
Post subject: | Re: Burst Fire Script |
Actually, would self.RootID work? This is how you Disable any Device. Code: yourweapon:Deactivate() |
Author: | Asklar [ Sat Jul 23, 2011 11:40 pm ] |
Post subject: | 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. |
Author: | Coops [ Sat Jul 23, 2011 11:44 pm ] |
Post subject: | Re: Burst Fire Script |
Check if it even gets the weapon. |
Author: | Coops [ Sun Jul 24, 2011 1:41 am ] |
Post subject: | 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. |
Author: | Asklar [ Sun Jul 24, 2011 2:05 am ] |
Post subject: | 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. |
Author: | Coops [ Sun Jul 24, 2011 2:16 am ] |
Post subject: | 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. |
Author: | Asklar [ Sun Jul 24, 2011 2:22 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Sun Jul 24, 2011 8:13 pm ] |
Post subject: | 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. |
Author: | Asklar [ Wed Jul 27, 2011 9:08 pm ] |
Post subject: | Re: Burst Fire Script |
That works overly perfect. Thanks for the help Coops and CC. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |