|
Page 1 of 1
|
[ 11 posts ] |
|
Author |
Message |
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
More Lua Trouble
I decided to mess around with some Sparkle Magic, and came up with this script. It is designed to animate a nearby gun until a certain frame, and then create some speeding particles at the said gun's position. Took me a while to iron the bugs out (believe me, there was a lot of them), and yet I can't make it work. It gives out no error, but, if I fire the gun, the game freezes instantly. Can anyone explain why? (Sorry for the lousy tabbing.) Code: function Create(self)
print ("IMMA FIRIN' MAH LAZOR!!!"); self.timer = Timer(); self.HasMOGun = 0; self.GunTOShoot = nil; self.GunHolder = nil;
end
function Update(self)
if self.HasMOGun == 0 then for mo in MovableMan.Particles do for i = 1, MovableMan:GetMOIDCount() - 1 do mo = MovableMan:GetMOFromID(i) if mo.PresetName == "Vocal-0-ID" then local avgx = mo.Pos.X - self.Pos.X; local avgy = mo.Pos.Y - self.Pos.Y; local maindist = math.sqrt(avgx ^ 2 + avgy ^ 2); if maindist < 100 then if mo.ID ~= mo.RootID then self.GunToShoot = ToAttachable(mo); for modude in MovableMan.Actors do modude = MovableMan:GetMOFromID(self.GunToShoot.RootID); self.GunHolder = ToActor(modude); end else self.ToDelete = true; end end end end end self.HasMOGun = 1; end
while self.GunToShoot.Frame < 38 do if self.timer:IsPastSimMS(370) then self.GunToShoot.Frame = self.GunToShoot.Frame + 1; self.timer:Reset() else self.Boom = CreateAEmitter("Sonic Burst Heavy"); self.Marker = CreateMOPixel("Sonic Burst Pixel Normal Heavy"); local theta = ToActor(self.GunHolder):GetAimAngle(true); self.Marker.Pos = self.GunHolder.Pos + Vector(math.cos(theta)*100,math.sin(theta)*-100); self.Boom.Pos = self.GunHolder.Pos + Vector(math.cos(theta)*50,math.sin(theta)*-50); self.Boom.Vel = (self.Boom.Pos - self.Marker.Pos) * 0.1; MovableMan:AddParticle(self.Boom); self.ToDelete = true; end end
end
|
Wed Dec 16, 2009 3:17 pm |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
Re: More Lua Trouble
So, what's running this script?
|
Wed Dec 16, 2009 3:53 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: More Lua Trouble
A particle, created when the weapon shoots. I may be illiterate in Lua, but not so much as to try to add a script to an attachable.
|
Wed Dec 16, 2009 5:09 pm |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: More Lua Trouble
Only had a quick look at it but that while-loop perhaps? The timer must pass 370ms 38 times for it exit so it looks to me like it will run indefinitely.
Some other things: Why are you iterating through all particles? If the script is attached to a particle you already know the position. I would recommend using Sunshines(?) method of finding an actor; spawn the bullet inside the gun and use SceneMan:GetMOIDPixel in the Create function.
|
Wed Dec 16, 2009 5:45 pm |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
Re: More Lua Trouble
My method: just fire a particle with a velocity of 1. Its Create script uses either its velocity (if it's an MOPixel or MOSParticle) or its RotAngle (if it's a MOSRotating or anything based off of it) to cast a ray backwards, which should find the weapon.
|
Wed Dec 16, 2009 7:39 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: More Lua Trouble
Abdul: Dang. Hadn't realised that. Will try to fix it now.
Darlos: That's actually a very good idea. I'll implement it if my script starts to cause too much lag.
|
Wed Dec 16, 2009 8:00 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: More Lua Trouble
More stuff happened. (DOUBLE POST I KNOW SORRY DON'T KILL ME) After fixing pretty much everything that needed to be fixed, I ended up with this: Code: function Create(self)
print ("Gun sequence initiated."); self.timer = Timer(); self.HasMOGun = 0; self.GunToShoot = nil; self.GunHolder = nil; self.FrameToGun = 0;
end
function Update(self)
if self.HasMOGun == 0 then for mo in MovableMan.Particles do for i = 1, MovableMan:GetMOIDCount() - 1 do mo = MovableMan:GetMOFromID(i) if mo.PresetName == "Vocal-0-ID" then local avgx = mo.Pos.X - self.Pos.X; local avgy = mo.Pos.Y - self.Pos.Y; local maindist = math.sqrt(avgx ^ 2 + avgy ^ 2); if maindist < 100 then if mo.ID ~= mo.RootID then self.GunToShoot = ToAttachable(mo); print ("Weapon found: " .. self.GunToShoot.PresetName .. " Number: " .. self.GunToShoot.ID); for modude in MovableMan.Actors do modude = MovableMan:GetMOFromID(self.GunToShoot.RootID); self.GunHolder = ToActor(modude); print ("Actor found: " .. self.GunHolder.PresetName); self.HasMOGun = 1; end else self.ToDelete = true; end end end end end end
local GunToFrame = self.GunToShoot.Frame; if GunToFrame < 37 then if self.timer:IsPastRealMS(37) and self.FrameToGun < 38 then -- print ("Current frame: " .. self.GunToShoot.Frame); -- print ("increasing frame by 1."); self.GunToShoot.Frame = self.FrameToGun; self.FrameToGun = self.FrameToGun + 1; self.timer:Reset() end else self.Boom = CreateAEmitter("Sonic Burst Heavy"); self.Marker = CreateMOPixel("Sonic Burst Pixel Normal Heavy"); local theta = ToActor(self.GunHolder):GetAimAngle(true); self.Marker.Pos = self.GunHolder.Pos + Vector(math.cos(theta)*100,math.sin(theta)*-100); self.Boom.Pos = self.GunHolder.Pos + Vector(math.cos(theta)*50,math.sin(theta)*-50); self.Boom.Vel = (self.Boom.Pos - self.Marker.Pos) * 0.1; MovableMan:AddParticle(self.Boom); print ("Adding particle: " .. self.Boom.PresetName); print ("IMMA FIRIN' MAH LAZOR!!!"); self.ToDelete = true; end end The actor/gun finding part is ok, all the print lines return the correct PresetNames, but the actual effect on the gun is far from perfect. When the fire key is pressed, the gun begins animating. The frames, although, keep resetting to the first one before advancing, creating an ugly, jagged animation. Surprisingly, if there are too many MOIDS in-game, the simulation will freeze for a couple of seconds, and then animate perfectly right, without the repeated frames. Plus, the frame check in the end always returns a zero, no matter which frame the gun is displaying. The particle it is supposed to create also appears only sporadically, sometimes at the right frame, sometimes right when you press the trigger. I suspect i'm running into some kind of hardcoded barrier, but I've got a whole 38 frames of animation and want to use them all, thank you. So, anyone got ideas on how to solve this?
|
Thu Dec 17, 2009 12:33 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: More Lua Trouble
Particles like hdfirearms and mosparticles constantly try to reset their frames. It's extremely difficult (impossible) to get them to consistently animate with Lua when they're not set to do so by .ini code.
|
Thu Dec 17, 2009 1:00 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: More Lua Trouble
Dang again. So I reckon it would require some fidgeting with the animmode and duration, right? I am unsure on how to proceed, though, as setting the animmode to 4 only lets it animate the first frames.
|
Thu Dec 17, 2009 1:54 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: More Lua Trouble
Uh.
Short of using guns with spinup, hdfirearms are hardcoded to only animate into their first and second frames "naturally", meaning that you're SOL, at least insofar as using an actual gun to do your animation.
|
Thu Dec 17, 2009 4:00 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: More Lua Trouble
Grif wrote: hdfirearms are hardcoded to only animate into their first and second frames "naturally". Not quite. Using AnimMode = 4, I was able to make another gun show a whole five frames when shooting. And spinup doesn't help anyway, as it always makes the animation play several times in a row, no matter what the duration variables are set to. Oh well, I guess I'll just follow your advice and transform the gun in a pseudo-attachable, then.
|
Thu Dec 17, 2009 6:26 pm |
|
|
|
|
Page 1 of 1
|
[ 11 posts ] |
|
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
|
|