All Objects and Buildings on the map

Go down

All Objects and Buildings on the map Empty All Objects and Buildings on the map

Post by TemplarGFX on Wed 23 Dec 2015, 02:11

Hi Everyone! 

Ive been messing with particles, and one thing I wanted to do was spawn one when I destroyed a prop, including any predefined props already on the map.  Turned out that was not so easy!


I built a file called object_list.txt which contains the guid, xPos, zPos, friendlyName of each object on the map.  All the data for these items is recorded in XML files for the editor to display them, but the guid was unknown.  there is a function OFP:getBuildingGuid() which takes the editor name of a building as its input.  This actually takes any object you see already on the map with a label.  So I read the data out of the XML files, retreived its guid and then reformatted it.

There is about 4000 objects in total, and trying to play with that in a table was just not going to happen, so using an external file is the only way.  Luckily io.lines() is extremely quick, and runs over these in no time at all.

object_list.txt on Google Drive

for the example below, the file should be placed in the game installation folder. could easily be stored in the mission folder after exporting to keep your mission standalone

Code:

function onObjectDamage(guid)
  local set_count = 0
  local set_table = {}
  for line in io.lines("object_list.txt") do
    if set_count < 4 then
      set_count = set_count + 1
      table.insert(set_table, line)      
    else
      if set_table[1] == guid then
        --doLog(set_table[1]..set_table[2]..set_table[3]..set_table[4])
        --doLog("guid".."xPos".."yPos".."objName")
        return
      end
      set_count = 1
      set_table = {line}
    end
  end
end


The above function will allow you to get the position of the object that was damaged, including its friendly name!

using string.find you can search the name for things like '_ob' for an object '_bd' for a building. Words like 'barn', 'pole', 'stump', 'wall' etc can let you know what was damaged.

Its important to remember that only those objects with names in the Map are recognized. not all objects are in there unfortunately, if I find the data on the others Ill update it


Last edited by TemplarGFX on Wed 23 Dec 2015, 14:18; edited 2 times in total

TemplarGFX
Veteran

Points : 159
Reputation : 18
Join date : 2013-02-20

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by runerback on Wed 23 Dec 2015, 03:47

Wow, that's great.

runerback

Location : China
Points : 153
Reputation : 5
Join date : 2014-06-18

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by TemplarGFX on Wed 23 Dec 2015, 14:31

runerback wrote:Wow, that's great.

Thanks!

I updated the object_list as it was missing a few (thats what I get for doing it manually :p)


Here is a little function that will cause objects and buildings to really explode!   Best part is you can drop it into almost any mission as no one uses onObjectDamage()

the fire and smoldering debri fizzle out after a few minutes, but the big plume of smoke does not. it never goes away (including moving really far away).  Something that always annoyed me about battles was that after a minute or so the smoke went away.

the effect is variable. on buildings (and building-like objects) it produces fires and smoldering debri smoke around the area. Certain large objects (like big fuel tanks and warehouses have more fire and smoke to compensate for their size.   Other objects create "battle smoke" which adds to the atmosphere as its builds up. it lasts ages

Code:

function onObjectDamage(guid)
  OFP:displaySystemMessage(guid.." destroyed")
  local set_count = 0
  local set_table = {}
  for line in io.lines("object_list.txt") do
    if set_count < 4 then
      set_count = set_count + 1
      table.insert(set_table, line)      
    else
      if set_table[1] == guid then
        doEffect(set_table[4], set_table[2], OFP:getTerrainHeight(set_table[2], set_table[3]), set_table[3])
        return
      end
      set_count = 1
      set_table = {line}
    end
  end
end


function doEffect(objectName, posX, posY, posZ)
  if string.find(objectName,"_bd",1,true) ~= nil or string.find(objectName,"drum",1,true) ~= nil or string.find(objectName,"freight",1,true) ~= nil or string.find(objectName,"pallet",1,true) ~= nil or string.find(objectName,"bunker",1,true) ~= nil or string.find(objectName,"oil",1,true) ~= nil or string.find(objectName,"mon",1,true) ~= nil then
    rand = math.random(1,3)
    rand2 = math.random(2,6)
    dist = 4
    dist2 = 12
    if string.find(objectName, "whs", 1, true) ~= nil or string.find(objectName, "brn", 1, true) ~= nil or string.find(objectName, "barn", 1, true) ~= nil then --warehouse or barn
      rand = math.random(3,4)
      rand2 = math.random(5,12)
      dist = 14
      dist2 = 20
    end
    if string.find(objectName, "hng", 1, true) ~= nil or string.find(objectName, "crush", 1, true) ~= nil then --hanger
      rand = math.random(5,9)
      rand2 = math.random(5,12)
      dist = 15
      dist2 = 25
    end
    if string.find(objectName, "tankb", 1, true) ~= nil then --large fuel tank
      rand = math.random(3,7)
      rand2 = math.random(2,9)
      dist = 8
      dist2 = 15
    end
    if string.find(objectName, "tanka", 1, true) ~= nil or string.find(objectName, "bridge", 1, true) ~= nil then --med fuel tank
      rand = math.random(3,7)
      rand2 = math.random(2,6)
      dist = 5
      dist2 = 10
    end
    for i=1, rand do
      position = {doPositionByDirection({posX, posY, posZ},{math.floor(dist / 3), dist},{0, 359})}
      if position[2] < 42 then
        position[2] = 42
      end
      OFP:particleEffect("X_FIRE_WREK_Master1_Small", position[1], position[2]-1, position[3] )
    end
    for i=1, rand2 do
      position = {doPositionByDirection({posX, posY, posZ},{math.floor(dist2 / 3), dist2},{0, 359})}
      if position[2] < 42 then
        position[2] = 42
      end
      OFP:particleEffect("X_SMOK_VHCL_Master1", position[1], position[2], position[3] )
    end
    OFP:displaySystemMessage("Deployed "..rand.." Fires at "..dist.."m and "..rand2.." smoking debri at "..dist2.."m")
    OFP:particleEffect("X_SMOK_END_Master1", posX, posY, posZ )
    OFP:particleEffect("X_ENV_SMOK_Master1", posX, posY, posZ )
  else
    rand = math.random(1,3)
    for i=1, rand do
      position = {doPositionByDirection({posX, posY, posZ},{0, 10},{0, 359})}
      if position[2] > 42 then
        OFP:particleEffect("X_SMOK_ABS_Master1", position[1], position[2]-0.5, position[3] )
      end
    end
  end
end
NOTE : this requires  doPositionByDirection from AutoHelp 1.0


you can call doEffect() from onPlaceableKill to get the effect on placed props

heres some screenies
All Objects and Buildings on the map C9TOQGY
All Objects and Buildings on the map HC3rhfX
All Objects and Buildings on the map IxO9rMu
All Objects and Buildings on the map 9tCcols
All Objects and Buildings on the map LR18XcD


Last edited by TemplarGFX on Wed 23 Dec 2015, 14:51; edited 1 time in total

TemplarGFX
Veteran

Points : 159
Reputation : 18
Join date : 2013-02-20

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by runerback on Wed 23 Dec 2015, 14:46

I always want to make a RPG mission... This will make it more closer.Very Happy

runerback

Location : China
Points : 153
Reputation : 5
Join date : 2014-06-18

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by runerback on Thu 24 Dec 2015, 01:05

I want to know whether event function can be fired in waypoints.lua. If it is, maybe can put this "onObjectDamage" function into waypoints.lua, then with EDX, load the guid table file in onCreate() event function, when the original "onObjectDamage" fired, search for item in table, and then use EDX:distributeFunction to fire a new function "onObjectDamage2" or others: onObjectDamage2(objName, xPos, yPos).

runerback

Location : China
Points : 153
Reputation : 5
Join date : 2014-06-18

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by tvig0r0us on Thu 24 Dec 2015, 01:26

There is a function within the EDX that you can use to register functions and events. Then they will be available to any script. If you look at the missile module you can see examples for how to set it up.

The missile module is [url=https://www.dropbox.com/s/qw9hbbt3dy4jafd/tvigs OFDR repository.zip?dl=0]here[/url].


All Objects and Buildings on the map Nst_tv10
tvig0r0us
tvig0r0us
Admin

Location : Nky
Points : 266
Reputation : 29
Join date : 2013-10-16

http://www.moddb.com/members/tvig0r0us

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by runerback on Sat 26 Dec 2015, 06:02

I saved all object_list data to a table, the format is as below:
Code:
object_list[guid] = { name, x, y, z}

then I saved this table to a txt file, like this:
Code:
object_list = {}
object_list['0xa724b355']={['name']='x09_y11_ob20_rubbleb_01_03',['x']=9394.059,['y']=0,['z']=-11479.4 }
object_list['0x4cab5436']={['name']='x24_y08_ob13_drumb_01_47',['x']=24527.66,['y']=0,['z']=-8577.504}
object_list['0x0fa9afcc']={['name']='x02_y13_bd16_empla_01_01',['x']=2754.595,['y']=0,['z']=-13066.25}

But, when I use lua loadfile("path")() to load it into memory, there is an error stoped everything. I thought maybe the file is too large, so I cut it to 6 files, every one has a different table name such as object_list_1, object_list_2, ect. Still throw an error.

runerback

Location : China
Points : 153
Reputation : 5
Join date : 2014-06-18

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by tvig0r0us on Sat 26 Dec 2015, 14:44

Looks like you'll have to use io.lines to run through the lines in the file until you find the guid, then parse the line for the data you want.

--tvig


All Objects and Buildings on the map Nst_tv10
tvig0r0us
tvig0r0us
Admin

Location : Nky
Points : 266
Reputation : 29
Join date : 2013-10-16

http://www.moddb.com/members/tvig0r0us

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by TemplarGFX on Sat 26 Dec 2015, 22:43

runerback wrote:I saved all object_list data to a table, the format is as below:
Code:
object_list[guid] = { name, x, y, z}

then I saved this table to a txt file, like this:
Code:
object_list = {}
object_list['0xa724b355']={['name']='x09_y11_ob20_rubbleb_01_03',['x']=9394.059,['y']=0,['z']=-11479.4 }
object_list['0x4cab5436']={['name']='x24_y08_ob13_drumb_01_47',['x']=24527.66,['y']=0,['z']=-8577.504}
object_list['0x0fa9afcc']={['name']='x02_y13_bd16_empla_01_01',['x']=2754.595,['y']=0,['z']=-13066.25}

But, when I use lua loadfile("path")() to load it into memory, there is an error stoped everything. I thought maybe the file is too large, so I cut it to 6 files, every one has a different table name such as object_list_1, object_list_2, ect. Still throw an error.

Like everything in Operation Flashpoint Dragon Rising,  the Lua Interpreter is assigned a fixed amount of memory during gameplay (hardcoded into  data\config.dat)

There is a limit that is hit when attempting to use such large tables.  creating the effect_list.txt was the result of hitting this limit for the first time!  In my testing, anything over about 600 entries caused the game to simply not load level.lua (or a secondary script) at all.  Unfortuntely it does not seem to matter if they are the split accross mulitple tables and/or multiple files.

TemplarGFX
Veteran

Points : 159
Reputation : 18
Join date : 2013-02-20

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by runerback on Sun 27 Dec 2015, 04:38

TemplarGFX wrote:Like everything in Operation Flashpoint Dragon Rising,  the Lua Interpreter is assigned a fixed amount of memory during gameplay (hardcoded into  data\config.dat)
In "Lua for windows", everything worked. Evil or Very Mad


How about changing some value in config.dat? But I guess it doesn't work, as usual.

runerback

Location : China
Points : 153
Reputation : 5
Join date : 2014-06-18

Back to top Go down

All Objects and Buildings on the map Empty Re: All Objects and Buildings on the map

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum