View unanswered posts | View active topics It is currently Tue Apr 16, 2024 3:22 pm



Reply to topic  [ 13 posts ] 
 Raining bombs via grenade 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Raining bombs via grenade
I'm trying to create a flare which when destroyed makes bombs fall where it was. The code is not working, so I wanted to ask for help.

Code:
function Update(self)
   self.StoreX = self.Pos.X
   self.RotAngle = 0
   self.bombVar = 1
end
function Destroy(self)
   self.bombTime = Timer();
   self.bombingTime = Timer();

   if self.bombVar == 1 then
      if self.bombingTime:IsPastSimMS(500) then
         self.bomb = CreateTDExplosive("Anti-Bunker Bomb");
         self.bomb:Activate()
         MovableMan:AddItem(self.bomb);
         self.bomb.Pos = Vector(self.StoreX,-20);
         self.bombingTime:Reset();
      end
   end
   if self.bombTime:IsPastSimMS(5000) then
      self.bombVar = 0
   end
end


I'm not good at lua, but I'm not bad either, but this code is kicking my ass.


Sat Feb 05, 2011 2:22 am
Profile
User avatar

Joined: Wed May 20, 2009 3:10 pm
Posts: 366
Location: Ã…rhus, Denmark
Reply with quote
Post Re: Raining bombs via grenade
Destroy self only runs once, so it can't spawn bombs after a couple of secs. The way you want to do is by making a new object with the bomb spawning script which you spawn when the flare is destroyed. Hope it helps.


Sat Feb 05, 2011 10:55 am
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Raining bombs via grenade
Asklar wrote:
I'm trying to create a flare which when destroyed makes bombs fall where it was. The code is not working, so I wanted to ask for help.
*Code*
I'm not good at lua, but I'm not bad either, but this code is kicking my ass.

Code:
function Update(self)
   self.StoreX = self.Pos.X
   self.RotAngle = 0
   self.bombVar = 1
   
   if self.bombVar == 1 then
      if self.bombingTime:IsPastSimMS(500) then
      self.bomb = CreateTDExplosive("Anti-Bunker Bomb");
      self.bomb:Activate()
      MovableMan:AddItem(self.bomb);
      self.bomb.Pos = Vector(self.StoreX,-20);
      self.bombingTime:Reset();
      end
   end
   if self.bombTime:IsPastSimMS(5000) then
      self.bombVar = 0
   end
end

function Destroy(self)
   self.bombTime = Timer();
   self.bombingTime = Timer();
end

?


Sat Feb 05, 2011 11:24 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Raining bombs via grenade
I recommend spawning an object with the grenade that in turn spawn the bombs. This code is attached to the grenade:
Code:
function Update(self)
   if self.ToDelete then
      local BombSpawn = CreateMOPixel("Bomb Spawn", "ModName.rte")
      BombSpawn.Pos = Vector(self.Pos.X, -50)
      MovableMan:AddParticle(BombSpawn)
   end
end

This to a MOPixel with GlobalAccScalar = 0 called "Bomb Spawn":
Code:
function Create(self)
   self.SpawnTime = Timer()
end

function Update(self)
   if self.SpawnTime:IsPastSimMS(500) then
      self.SpawnTime:Reset()
      
      local Bomb = CreateTDExplosive("Anti-Bunker Bomb", "ModName.rte")
      Bomb.Pos = self.Pos + Vector(RangeRand(-50, 50), 0)
      Bomb:Activate()
      MovableMan:AddParticle(Bomb)
   end
end

The number of bombs dropped is regulated by the MOPixel's life time. Note that this code has not been tested.


Sat Feb 05, 2011 2:58 pm
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Raining bombs via grenade
Abdul Alhazred wrote:
Note that this code has not been tested.
On an Abdul Alhazred script of this size, you will probably be wanting to just chuck it in to the game rather than attempt to proof-read it.


Sat Feb 05, 2011 3:18 pm
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Raining bombs via grenade
Abdul Alhazred wrote:
I recommend spawning an object with the grenade that in turn spawn the bombs. This code is attached to the grenade:
Code:
function Update(self)
   if self.ToDelete then
      local BombSpawn = CreateMOPixel("Bomb Spawn", "ModName.rte")
      BombSpawn.Pos = Vector(self.Pos.X, -50)
      MovableMan:AddParticle(BombSpawn)
   end
end

This to a MOPixel with GlobalAccScalar = 0 called "Bomb Spawn":
Code:
function Create(self)
   self.SpawnTime = Timer()
end

function Update(self)
   if self.SpawnTime:IsPastSimMS(500) then
      self.SpawnTime:Reset()
      
      local Bomb = CreateTDExplosive("Anti-Bunker Bomb", "ModName.rte")
      Bomb.Pos = self.Pos + Vector(RangeRand(-50, 50), 0)
      Bomb:Activate()
      MovableMan:AddParticle(Bomb)
   end
end

The number of bombs dropped is regulated by the MOPixel's life time. Note that this code has not been tested.


And if instead of using 2 codes, I just use the second and attach it to a MOPixel gib with PinStrength = 9999?

EDIT: Alright, what I said worked. I attached it to a MOPixel gib with PinStrength = 9999, and it works perfect.


Last edited by Asklar on Sat Feb 05, 2011 10:15 pm, edited 1 time in total.



Sat Feb 05, 2011 10:10 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Raining bombs via grenade
We already went over this before.
Its a different way of making them spawn, but same concept.

viewtopic.php?f=73&t=20848


Sat Feb 05, 2011 10:13 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Raining bombs via grenade
I know that, I saw that post before like any responsible forum user when I was searching on how to do it.
That's why I made the new post.


Sat Feb 05, 2011 10:18 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Raining bombs via grenade
That would have been epic, but you know, modding everytime gets more complex and more sophisticated (if the word exists, and if I wrote it ok), so learning lua is really important right now.


Sat Feb 05, 2011 10:47 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Raining bombs via grenade
Dude, I love metaphors.
Yeah, you are right, I'm making an entire faction using as less lua as I can because:
1) I don't know much
2) Lua-filled mods sometimes make the game way to easy.


Sun Feb 06, 2011 2:50 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Raining bombs via grenade
However, don't forget that at Lua can be better even if ini can work.
Take for an example an acid bath, which I have still yet to make.
To do it in ini would require an emitter spawning a boatload of particles, which is very laggy(and crashy).
However, with Lua, I can do it with much less lag.

It's still good to know the ini way in those instances.


Sun Feb 06, 2011 3:09 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Raining bombs via grenade
Ini is the basic way to mod complex things.
Lua is the complex way to mod simple things ini's can't do (making a rocket gib in midair can only be done with luas and it's something quite simple, that is enough proof).


Sun Feb 06, 2011 4:35 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Raining bombs via grenade
Learn to sail on a lake first then on the sea you have less chance of crashing once you know how to sail??


Sun Feb 06, 2011 8:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.058s | 15 Queries | GZIP : Off ]