Data Realms Fan Forums
http://45.55.195.193/

I need help with a script I am making
http://45.55.195.193/viewtopic.php?f=73&t=17592
Page 1 of 3

Author:  Foogooman [ Sun Jan 17, 2010 8:55 am ]
Post subject:  I need help with a script I am making

My gun fires an MOPixel, and the MO pixel runs the lua script.

I want the script to spawn an emitter at the same velocity and direction as the original MOPixel. So far, I have that. What I don't have, is more than one object spawned. I want it to spawn 50 objects randomly within a certain field after the MOPixel. So let's so they randomly spawn between pixel 0 and 100. BUT I WOULD PREFER if I could get them to shoot out evenly spaced every time. So The first emitter spawns from the MOPixel, and another one spawns five pixels ahead, and then another one five pixels ahead, and so on.

Here is what I have so far. You can see I tried to use the random method, but I am terrible at lua. Once again I would prefer if they were evenly spaced every time.

Code:
function Create(self)
   local shot = CreateAEmitter("Justice Shot");
   shot.Pos = self.Pos, -math.random(150) - 50;
   shot.Vel = self.Vel;
   MovableMan:AddMO(shot);
end

Author:  PhantomAGN [ Sun Jan 17, 2010 12:55 pm ]
Post subject:  Re: I need help with a script I am making

If you want them all spawned at once, I would use a for-loop.
Code:
i = 0
for i < 50 do
   local emitter = CreateEmitter(<presetname of emitter>)
   emitter.Pos = <placement method>
   emitter.Vel = self.Vel
   MovableMan:AddParticle(emitter)
   i=i+1
end

I have not tested this code, it's just a tweak of something I wrote a while ago. There's probably a better way to do that too.

As for placement, do you want a straight line in front of the original MOPixel, or random emitters scattered all around?
I don't get it.
Please reiterate what you want most from this, I am confused by the way you initially say random, and then say evenly spaced.
Neither way is impossible, or even difficult, but we need to know exactly how to help.
Also, is this to use sparkle magic to make an effect look nice? I am a fan of prettiness in CC weapons.

Author:  Foogooman [ Sun Jan 17, 2010 9:26 pm ]
Post subject:  Re: I need help with a script I am making

PhantomAGN wrote:
If you want them all spawned at once, I would use a for-loop.
Code:
i = 0
for i < 50 do
   local emitter = CreateEmitter(<presetname of emitter>)
   emitter.Pos = <placement method>
   emitter.Vel = self.Vel
   MovableMan:AddParticle(emitter)
   i=i+1
end

I have not tested this code, it's just a tweak of something I wrote a while ago. There's probably a better way to do that too.

As for placement, do you want a straight line in front of the original MOPixel, or random emitters scattered all around?
I don't get it.
Please reiterate what you want most from this, I am confused by the way you initially say random, and then say evenly spaced.
Neither way is impossible, or even difficult, but we need to know exactly how to help.
Also, is this to use sparkle magic to make an effect look nice? I am a fan of prettiness in CC weapons.


Well thanks for the reply!

Well let's just focus on the "evenly spaced" method, because I would prefer that.

So it will look like this:

Image

The MOPixel is fired, and from that position it spawns the objects all directly ahead of each other with five pixels in between each spawned object. And I want them to spawn at the same time(or as close as possible). Also, refer to the GIF bellow, that's how it should work.

No sparkle magic required to make it look better, it already looks great:
Image
That version is bugged though, using ridiculous offsets and whatnot. It uses a high separation and and high muzzleoffset, but that causes some issues so I need to achieve that same effect with lua. But yeah, it's going to look like that.

Also, I tested that code and it said "=" or "in" expected near "<"

Author:  PhantomAGN [ Mon Jan 18, 2010 12:30 am ]
Post subject:  Re: I need help with a script I am making

I could watch that gif all day.
How far do you want it to fire?

I think a loop of using the particle's rotation (or that of its parent) and then measuring out an increasing distance and placing a dot there is all you need to do, to a limit of whatever range you want it to fire. Simple Trig stuff, I'll test it and show you shortly.

Got a lot of soldering to do on a real-world project first, should be done in a few hours.

Author:  Foogooman [ Mon Jan 18, 2010 1:03 am ]
Post subject:  Re: I need help with a script I am making

PhantomAGN wrote:
I could watch that gif all day.
How far do you want it to fire?

I think a loop of using the particle's rotation (or that of its parent) and then measuring out an increasing distance and placing a dot there is all you need to do, to a limit of whatever range you want it to fire. Simple Trig stuff, I'll test it and show you shortly.

Got a lot of soldering to do on a real-world project first, should be done in a few hours.


Alright, cool. Are we talking distance in pixels?

Maybe somewhere around 1000 pixels.

Author:  PhantomAGN [ Mon Jan 18, 2010 12:03 pm ]
Post subject:  Re: I need help with a script I am making

Spent three hours on stupid stupid errors, have to temporarily admit defeat.
There is something very wrong here, and it's missing some of what is supposed to be there, but it's code you can look at I suppose.
http://pastebin.com/d111c685e
The error is with AddParticle., if anyone has any idea why this fails to work, let me know.
It's is letter for latter the same code I have used in another script.

Author:  CaveCricket48 [ Mon Jan 18, 2010 5:32 pm ]
Post subject:  Re: I need help with a script I am making

I've had some problems where if there is an "if" or "for" statement between the to-be-spawned MO definition and the spawning part when using "local" variables. Change it to "self" and it should work.

Author:  Grif [ Mon Jan 18, 2010 7:04 pm ]
Post subject:  Re: I need help with a script I am making

It's because you only have one 'beam' particle that you're attempting to create fifty times in different spots. If you define it as local inside the if it should work fine.

Author:  PhantomAGN [ Mon Jan 18, 2010 8:46 pm ]
Post subject:  Re: I need help with a script I am making

Ahhahahaha
This is why I should not be allowed to code after 15 hours of consciousness.

Pulled the junk out, reorganized, here's something you can try to use.
http://pastebin.com/m76411ebc
This script is attached to a null bullet the gun fires, which must have a lifetime of 1 and a high pinstrength.
Then of course you need to define
Code:
AddAmmo = MOPixel
   InstanceName = Beam Dot
   blah blah blah
   etc
   ScreenEffect = ContentFile
      FilePath = glow you want to see


You will probably want to make the glows move or something too.
I'm fiddling with making the spawned glows disperse nicely now.

Author:  Foogooman [ Tue Jan 19, 2010 1:18 am ]
Post subject:  Re: I need help with a script I am making

PhantomAGN wrote:
Ahhahahaha
This is why I should not be allowed to code after 15 hours of consciousness.

Pulled the junk out, reorganized, here's something you can try to use.
http://pastebin.com/m76411ebc
This script is attached to a null bullet the gun fires, which must have a lifetime of 1 and a high pinstrength.
Then of course you need to define
Code:
AddAmmo = MOPixel
   InstanceName = Beam Dot
   blah blah blah
   etc
   ScreenEffect = ContentFile
      FilePath = glow you want to see


You will probably want to make the glows move or something too.
I'm fiddling with making the spawned glows disperse nicely now.


Well... the good news is that it works.

The bad news is that it doesn't work right...
Image
(And they are appearing so far out front because the muzzleoffset, not the script, so don't worry about that part)

I was kinda hoping it would fire in a straight line despite the aiming direction :P

And even so, firing horizontally, all the emitters travel at a downward angle(which you can see in that gif too)

Thanks for all the effort so far though, gosh, you've put a lot of time into this already :P

Thank you

Author:  PhantomAGN [ Tue Jan 19, 2010 1:35 am ]
Post subject:  Re: I need help with a script I am making

Hah, I bet it was not able to find the actor that fired it.
Fix the offset, and then tell me if it still does that, I can also just change how it finds him.

If anyone knows a way to make the fired emitters defeat gravity without attaching Lua to all of them, please speak up.

Author:  TheLastBanana [ Tue Jan 19, 2010 1:42 am ]
Post subject:  Re: I need help with a script I am making

Add this line to the emitters' code:
Code:
GlobalAccScalar = 0

Author:  Foogooman [ Tue Jan 19, 2010 1:50 am ]
Post subject:  Re: I need help with a script I am making

PhantomAGN wrote:
Hah, I bet it was not able to find the actor that fired it.
Fix the offset, and then tell me if it still does that, I can also just change how it finds him.

If anyone knows a way to make the fired emitters defeat gravity without attaching Lua to all of them, please speak up.


OH GOD FUUUUUUUUU-
Image

I only changed the muzzleoffset by like, 20 pixels that's all D:

Author:  PhantomAGN [ Tue Jan 19, 2010 2:05 am ]
Post subject:  Re: I need help with a script I am making

This is THE best fail ever.
I suspect you placed the offset 20 px behind the gun, or something crazy.

Can I work on the code directly?
Then I'll fix the getting-of-aim-angle thing too.

Author:  TorrentHKU [ Tue Jan 19, 2010 2:21 am ]
Post subject:  Re: I need help with a script I am making

I suspect gravity and a map that loops very quickly happened.

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