Lua - Damage Points and List of Sides (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


Rory Noonan -> Lua - Damage Points and List of Sides (9/6/2017 2:56:45 AM)

I'm looking at a script that checks each unit on a particular side for damage and then resets its damage status.

Below is the code that I think would be 'ideal', however the damage table in the unit wrapper is 'read only' so the changes made in the code below aren't actually saved. I have tried using the SetUnitDamage function but that appears to only influence component damage, fire and flood--not damage points.

Also, I was wondering if there's a way to return all the sides that are in a scenario? Something like: ScenEdit_ListSides() --returns a table of sides with name and guid

p_side = ScenEdit_PlayerSide()
side = VP_GetSide({name=p_side})
for i = 1,#side.units do
	unit = ScenEdit_GetUnit({guid=side.units[i].guid})
	damage = unit.damage
	damage_start = tonumber(damage.startdp)
	damage_current = tonumber(damage.dp)
		if damage_current < damage_start then
			ScenEdit_SetUnit({guid=unit.guid,damage={dp=damage_start}})
		end
end


Any suggestions?




Fer_Cabo -> RE: Lua - Damage Points and List of Sides (9/6/2017 9:27:51 AM)

Hi Apache,

A few months back i was looking at the possibility to use as condition for an event-trigger the TOTAL AMOUNT OF DPs of one side going over a certain % of that side's DPs.

For instance, GRANT USE OF NUCLEAR WEAPONS for DPRK Side when that side's DPs go over 75% of total DPs of its start-scenario-units.

I understand, i could use the first (most of it really) part of your above script:

p_side = ScenEdit_PlayerSide()
side = VP_GetSide({name=p_side})
for i = 1,#side.units do
unit = ScenEdit_GetUnit({guid=side.units.guid})
damage = unit.damage
damage_start = tonumber(damage.startdp)
damage_current = tonumber(damage.dp)

But... still i cannot find the way to ADD-UP the DPs for all units of a given Side. Your script sorts of "checks" every unit's DPs.

Any idea how i could achieve my goal?

Thanks and sorry to take profit of your consultation to try to achieve a useful answer to my old one ;-)

Best regards!!

Fernando




Rory Noonan -> RE: Lua - Damage Points and List of Sides (9/6/2017 9:34:47 AM)

p_side = ScenEdit_PlayerSide()
side = VP_GetSide({name=p_side})
side_damage = 0
side_dps = 0
for i = 1,#side.units do
	unit = ScenEdit_GetUnit({guid=side.units[i].guid})
	damage = unit.damage
	damage_start = tonumber(damage.startdp)
side_dps = side_dps + damage_start
	damage_current = tonumber(damage.dp)
side_damage = side_damage + (damage_start - damage_current)

end
print (p_side..' has sustained a total of '..side_damage..' damage points, out of a total of '..side_dps..' beginning damage points')


That should do it. If you want more utility you could store side_dps early on as a key value, because one of the limitations of the above code is that it doesn't count 'dead' units that don't exist anymore.




fortyporkpies -> RE: Lua - Damage Points and List of Sides (9/22/2017 7:45:22 PM)


quote:

ORIGINAL: apache85


Also, I was wondering if there's a way to return all the sides that are in a scenario? Something like: ScenEdit_ListSides() --returns a table of sides with name and guid

p_side = ScenEdit_PlayerSide()
side = VP_GetSide({name=p_side})
for i = 1,#side.units do
	unit = ScenEdit_GetUnit({guid=side.units[i].guid})
	damage = unit.damage
	damage_start = tonumber(damage.startdp)
	damage_current = tonumber(damage.dp)
		if damage_current < damage_start then
			ScenEdit_SetUnit({guid=unit.guid,damage={dp=damage_start}})
		end
end


Any suggestions?

Hi Apache-
As a crude workaround, could you briefly switch the player's side awareness to omniscient , grab all the contacts from that side, parse all those contacts with a for..do loop, get each contact's side and side guid info, add this info to a table - checking for duplicates, then switch the side back to normal awareness? This is suboptimal because a)every side would have to have at least one unit when the routine is run; b) the map would have to be zoomed somewhere that wouldn't reveal "spoilers" for the player-side;
Is something like that feasible?




fortyporkpies -> RE: Lua - Damage Points and List of Sides (9/22/2017 7:58:13 PM)

Something like
local Pside= ScenEdit_PlayerSide()
ScenEdit_SetSideOptions('{side=PSide,awareness='OMNI'}') 
side = VP_GetSide({name=Pside})
local cp = side.contacts --List Of contacts
for i = 1,#side.contacts do
    local guid = cp[i].objectid -- a specific contact
    local contact = VP_GetContact({guid=guid}) -- details of contact as distinct to unit details

--INSERT CODE HERE Interrogate contact with getUnit, derive side info and guid, place that info into a table that excludes duplicate entries
end

--INSERT CODE Change Playerside back to normal awareness






Fer_Cabo -> RE: Lua - Damage Points and List of Sides (9/25/2017 8:34:07 AM)

Hi apache,

You say "one of the limitations of the above code is that it doesn't count 'dead' units that don't exist anymore", but i guess i'm missing something...since the final printout is "print (p_side..' has sustained a total of '..side_damage..' damage points, out of a total of '..side_dps..' beginning damage points')"

On top of that, ain't "damage_start = tonumber(damage.startdp) " the real "START= Time 0" total DP for the checked side? When you say that "Dead Units" do not count, you mean they don't count for the DP INFLICTED or that they no longer count for the TOTAL START DP of that side?

Thanks!

Fernando.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
6.203125