Jump to content

killing spawned ships won't get rid of them


Lineaxe

Recommended Posts

Hi , I have spawned a couple of ships using MOOSE engine. 

I kill the ships off and a message comes up saying they are 70% 80% 90% and then it says the ship is destroyed.  So after finding out the ship is still there after the message!!  All of it works fine until I kill one off.  Anyhow, here is the code that I use to spawn the ships .

 

 

_____________________________________________________

redShipAsciiChrIndex = randmathORos(3, 2)
redShipSpawnName = "RedShipSpawn" ..string.char(64+redShipAsciiChrIndex) 
     
Spawn_VehicleTemp = SPAWN:New(redShipSpawnName) 
      :InitLimit( 1, 5 )
      :InitRandomizeRoute( 1, 11, 550 )
      :InitRandomizeTemplate(redShipTemplateTbl) -- the other choice is  --:InitRandomizeZones( ZoneTable )
      :SpawnScheduled( 3 + ii, .5 )

 

 

 

_____________________________________________________

 I Now  am trying to destroy the ship using a Handler to the unit . here is my code based on the examples I found based on Handlers. 

_____________________________________________________

-- here we are creating handlers to some enemy ships  --needs to be declared ahead of their handler functions??
-- code below this came from eds forums, it is setup first for UNIT SET 
RedShip1 = UNIT:FindByName( "RedShipSpawnA" )  

RedShip2 = UNIT:FindByName( "RedShipSpawnB" )

RedShip3 = UNIT:FindByName( "RedShipSpawnC" )  

 

 -- and Here we subscribe to the Dead events. So, if one of these Ships dies, the RedShip1 or RedShip2 objects will be notified.
 RedShip1:HandleEvent( EVENTS.Dead )

RedShip2:HandleEvent( EVENTS.Dead )

 RedShip3:HandleEvent( EVENTS.Dead )
_____________________________________________________

-- the functions to kill of the ship  are here (off the sample at ed forums)

--- This function is an Event Handling function that will be called when Ship1 is Dead.
 -- @param Wrapper.Unit#UNIT self  

-- @param Core.Event#EVENTDATA EventData
 function RedShip1:OnEventDead( EventData )

   self:SmokeGreen()
   self:Destroy()
 end

 --- function that will be called when Ship2 is Dead.
 -- @param Wrapper.Unit#UNIT self  -- @param Core.Event#EVENTDATA EventData
 function RedShip2:OnEventDead( EventData )

   self:SmokeBlue()
   self:Destroy()
 end

 --- function that will be called when Ship3 is Dead.
function RedShip3:OnEventDead( EventData )

   self:SmokeGreen()
   self:Destroy() --die die die go away !!!!!
 end

_____________________________________________________

 

So what did I do wrong ,why aren't the ships being removed from the map after they are killed. I know I keep telling 'em to...!!!


 

 

_____________________________________________________


Edited by Lineaxe
oops
Link to comment
Share on other sites

I had been wondering if I am killing of the Spawn template and should be killing off the actual ship , by name,  or something else?? 

Also,

Now the ship objects that Tacview shows are very strange as well. You see, Tacview shows the others ships from the table that did not get selected-- and they are moving along some pathways. They even go through the mountains. hehehe. So , is that some kinda bug somewhere as well. But they do not show up while playing the game , so that doesn't really bother me , it's just something to note.      

 

Link to comment
Share on other sites

  • 4 weeks later...

Not sure at all I can help, but let's try.

 

My very first question: why do you want to destroy units you've just been told they were dead ? If you go into the DEAD event then your unit is dead and should just disappear by itself ?

What is randmathORos, a function you've defined somewhere ?

SpawnScheduled( 3 + ii, .5 ) : what is "+ii" ?

RedShip1 = UNIT:FindByName( "RedShipSpawnA" )    I think "RedShipSpawnA" is a group name, not a unit name

 

Would need the actual mission to go further 

 

And on a more general note: I am not an expert, but my piece of advice would be: make it work simple. Forget about all random stuff, scheduled spawns etc. to start with. Make it work with minimal options, then add things one by one.

Link to comment
Share on other sites

oh ,heh, that is what I had done when I first wrote the logic, made it simple.  it all has Worked for like the last 8 months of the project lifecycle. Now I do have some problems destroying ships. They seem to want to exist in the exact same place. even after one of them did bring up a "Destroyed" message. In fact a "dead' ship attacked another ship. Stuff like that. Of course, this is all part of the moose framework code.

-- now ,the template ship used was created inside mission editor & created just like any templated unit type. This is where I do get a bit unsure about what syntax I should use to access this templated object. I believe the example I had found on Dead eveny handlers uses the Unitname (which in my case , Groupname is the unit name as well. All my templated units have only 1  in them.) 

 

To answer the questions: 

 1) randmathORos is a function .  you can find it here at ed forums ,just by searching for it by that name.

2) ii ,as usual, is used inside a range, in this case, the Schedule  will run in  3 + ii seconds --which can be up a a few minutes

3) the code below the "- the functions to kill of the ship  are here (off the sample at ed forums)" was originally found here . The code  handler was created to detect dead tank units and I changed it over to handle a ship, I then cloned it to handle other ship templates. That is the extent of any changes I had made to the original example.  Never did get back to the testing to see if the original , late activated objects need to be destroyed ,rather than the templates which get spawned. 

Anyhow, it's just strange seeing 2 ships occupying the same spot..

Still a bit new to coding lua and to coding for this environment. 

I will post the latest version of the Chop-U mission if you want to take a look at it . 

 

 

 

Link to comment
Share on other sites

You have a "SpawnScheduled", meaning you are going to spawn objects forever every x seconds. On another hand you have InitLimit( 1, 5 ), which means you cannot have more than 1 unit alive or more than 5 groups alive at the same time of this template (which is weird to me, generally the first number is higher than the second but never mind). So in my opinion, as it is written, you're going to spawn 1 ship but as soon as this ship is destroyed you're going to spawn another one immediately, and this, forever.

 

PS: made a search, couldn't find randmathORos (?)

Link to comment
Share on other sites

Hi, Yes, I do want to create only 1 ship . Once it gets killed spawn a new one. I had copied the code from a working example and left the  5 (groups)  in , as it really didn't affect anything. Not sure why the original code was setup that way.   

randmathORos :

Now, I dug this out of one of my posts. I would have thought searching through all posts by content would have located it for you, but found out I have renamed it in this mission project.    This code uses OS.time and thus the whole dcs needs to allow this (by uncommenting a line in a lua script).   The code originally came from the LUA developers website,( I modified it to add in some more options) and thus the code could run in any lua project not just ones for DCS.

 

 

function randOSnumber(inpNumber,inpType) -- valid integers 1 thru 4 for now

bflagit=false; inpType =math.abs(math.floor(inpType)) -- validation - absolute of integer portion only

if (inpType>4 or inpType<1) then BASE:T({"inpType is not a 1,2,3 or 4: "..tostring(inpNumber)}) return end

 

while (bflagit==false ) do

 

if (inpType==1) then return ( tonumber(tostring(os.time()):reverse():sub(1,6)) )% inpNumber +1

elseif (inpType==2) then return math.random(inpNumber)

elseif (inpType==3) then xx=( tonumber(tostring(os.time()):reverse():sub(1,6)) ) return math.random(xx)% inpNumber +1

elseif (inpType==4) then inpType=( tonumber(tostring(os.time()):reverse():sub(1,6)) )% 3 +1

end

end

bflagit=true -- never should get here , just returns in types 1,2 or 3

end --ENDOF randOSnumber


Edited by Lineaxe
Link to comment
Share on other sites

  • 3 months later...

I should mention here that I have resolved the problem.  I rewrote my lua code and created some core functions I could use on all vehicle types. And when I tested the code with the  enemy ships 

I could respawn them a random period after they die. The code works pretty decent with the templated shipping vehicles so far. 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...