Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua - Damage Points and List of Sides

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua - Damage Points and List of Sides Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua - Damage Points and List of Sides - 9/6/2017 2:56:45 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
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?

< Message edited by apache85 -- 9/6/2017 2:58:40 AM >
Post #: 1
RE: Lua - Damage Points and List of Sides - 9/6/2017 9:27:51 AM   
Fer_Cabo

 

Posts: 111
Joined: 9/17/2015
Status: offline
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

(in reply to Rory Noonan)
Post #: 2
RE: Lua - Damage Points and List of Sides - 9/6/2017 9:34:47 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
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.

< Message edited by apache85 -- 9/6/2017 10:34:47 AM >

(in reply to Fer_Cabo)
Post #: 3
RE: Lua - Damage Points and List of Sides - 9/22/2017 7:45:22 PM   
fortyporkpies


Posts: 18
Joined: 4/8/2009
From: Washington DC
Status: offline

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?

(in reply to Rory Noonan)
Post #: 4
RE: Lua - Damage Points and List of Sides - 9/22/2017 7:58:13 PM   
fortyporkpies


Posts: 18
Joined: 4/8/2009
From: Washington DC
Status: offline
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




_____________________________


(in reply to fortyporkpies)
Post #: 5
RE: Lua - Damage Points and List of Sides - 9/25/2017 8:34:07 AM   
Fer_Cabo

 

Posts: 111
Joined: 9/17/2015
Status: offline
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.

(in reply to Rory Noonan)
Post #: 6
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua - Damage Points and List of Sides Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.266