noTeamDamage
Posted: 10 Dec 2008, 06:57
For weapons, it'd be nice to not only avoid damage to the Unit that fired the weapon, but to any members of the Team.
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
Code: Select all
function gadget:GetInfo()
return {
name = "TeamDamage",
desc = "P.U.R.E. Team Damage Prevention",
author = "Argh",
date = "December 10th, 2008",
license = "Public Domain, or the least-restrictive rights in your country of residence",
layer = 0,
enabled = true,
}
end
local Health, maxHealth, paralyzeDamage = 0,0,0
local SetUnitHealth = Spring.SetUnitHealth
local GetUnitHealth = Spring.GetUnitHealth
if (gadgetHandler:IsSyncedCode()) then
function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
if unitTeam == attackerTeam then
Health, maxHealth, paralyzeDamage = GetUnitHealth(unitID)
if paralyzer then
SetUnitHealth(unitID,{paralyze = damage + paralyzeDamage})
else
if Health + damage < maxHealth then
SetUnitHealth(unitID,{health = Health + damage})
else
SetUnitHealth(unitID,{health = maxHealth})
end
end
end
end
end
I think KP T has a dormant no-FF gadget because I wanted to use a ballistic AOE weapon as in Patch-Con for Reimu at first...lurker wrote:I thought you actually wanted it as an engine feature so it would be faster. >_>
CA has it already coded in lua in unit_nofriendlyfire if you're okay with gpl. If you're coding yourself remember to take paralyzation into account.
No it wouldn't. It would make sense to make a well-organized repository of gadgets so modders can filch this code easily. In cases where gadgets are high-performance and effective, engine stuff is a waste of everyone's time.REVENGE wrote:It would seem sensible to make this an engine addition.
That assumes that anyone who is modding is sufficiently versant in Lua to identify the required part(s) of a lua gadget(s) and configure/modify it/them to produce the required behaviour. Simple game behaviours (such as explosions not damaging friendlies) really should be engine-side imo, with Lua used to provide additional, customised stuff. Lua hacks to remove hardcoded retardedness shouldnt be required to make a game that doesn't precisely follow the TA model.Pxtl wrote:No it wouldn't. It would make sense to make a well-organized repository of gadgets so modders can filch this code easily. In cases where gadgets are high-performance and effective, engine stuff is a waste of everyone's time.
It would seem sensible to make this an engine addition.
Yes it would!No it wouldn't
No need. I really doubt if it'd be a whole lot faster engine-only, and this is 100% optional.It would seem sensible to make this an engine addition.
It's already happened, you just aren't aware of it. Spring uses a TDF-->Lua parser now, it's all basically Lua.or at this rate all the FBI and TDF will be replaced by LUA... or has it already happened?
While I think that would be great in theory, it would require somebody willing to maintain such a repository, and make it useful enough that it was worth the effort, which requires knowing how things work well enough to provide useful information.It would make sense to make a well-organized repository of gadgets so modders can filch this code easily. In cases where gadgets are high-performance and effective, engine stuff is a waste of everyone's time.
That's called a game-design mistake, and it happens no matter how carefully we think that we've tested stuff.I am also concerned by what happens when you have several gadgets modify the damage recieved via that LUA gadget:UnitDamaged, and the modder doesn't pay enough attention to the layers.
If they were both acting like this one, then yes, they would.For instance, if you have two different gadgets to counter damage, do units get healed by shots?
Widgets cannot do this stuff. That would be a cheat.If you have something like KP firewall and some nodamage widget, do units explode for shooting units they didn't hurt?
Nobody's putting a gun to anybody's head and telling them that they have to learn Lua, or use it.That assumes that anyone who is modding is sufficiently versant in Lua to identify the required part(s) of a lua gadget(s) and configure/modify it/them to produce the required behaviour.
Code: Select all
function gadget:GetInfo()
return {
name = "TeamDamage",
desc = "P.U.R.E. Team Damage Prevention",
author = "Argh",
date = "December 10th, 2008",
license = "Public Domain, or the least-restrictive rights in your country of residence",
layer = 0,
enabled = true,
}
end
local Health, maxHealth, paralyzeDamage = 0,0,0
local SetUnitHealth = Spring.SetUnitHealth
local GetUnitHealth = Spring.GetUnitHealth
local exceptionList = {}
if (gadgetHandler:IsSyncedCode()) then
function gadget:Initialize()
for i=1,#WeaponDefs do
if string.find(WeaponDefs[i].description,"(teamdamage)") then
table.insert(exceptionList,i,1)
end
end
end
function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
if unitTeam == attackerTeam then
Health, maxHealth, paralyzeDamage = GetUnitHealth(unitID)
if not exceptionList[weaponID] then
if paralyzer then
SetUnitHealth(unitID,{paralyze = damage + paralyzeDamage})
else
if Health + damage < maxHealth then
SetUnitHealth(unitID,{health = Health + damage})
else
SetUnitHealth(unitID,{health = maxHealth})
end
end
end
end
end
end
My awareness of it is the exact reason of my adding: "... or has it already happened?Argh wrote:It's already happened, you just aren't aware of it. Spring uses a TDF-->Lua parser now, it's all basically Lua.
Already exists, and is nicknamed CA.It would make sense to make a well-organized repository of gadgets so modders can filch this code easily.
I was led to believe a strength, and aim, of the Spring engine was its moddability. But it appears the direction has been steered, and the new goal is to ditch all the C++ code to replace the whole website with a link to a LUA interpreter and a "Lern 2 prgm ur own game, n00b!!" message.There's no way to prevent stupid kids from stuffing their games full of Gadget code that they don't understand, that they can't fix, and screwing up their games, zwzsg. All we can tell people is that if they don't know what they're doing, then they probably should lrn 2 Lua.
Sorry I wanted to type gadget, but mind was getting clouded from having to restrain myself to add question about what if there's also widgets relying on that call, as I knew people could retort that widget happens in a seperate stage.Widgets cannot do this stuff. That would be a cheat.If you have something like KP firewall and some nodamage widget, do units explode for shooting units they didn't hurt?
my point exactly.zwzsg wrote:I was led to believe a strength, and aim, of the Spring engine was its moddability. But it appears the direction has been steered, and the new goal is to ditch all the C++ code to replace the whole website with a link to a LUA interpreter and a "Lern 2 prgm ur own game, n00b!!" message.
In this thread alone, Pxtl and Argh are. And everybody else is too, in most feature request threads!Nobody's putting a gun to anybody's head and telling them that they have to learn Lua, or use it.
- A single one of such gadget, ok.That, and stuff like this is practically idiot-proof. Install it, and your team's weapons will never cause damage to your team's units. Period.
Code: Select all
function gadget:GetInfo()
return {
name = "TeamDamage",
desc = "A Generic Team Damage System Example",
author = "Argh",
date = "December 10th, 2008",
license = "Public Domain, or the least-restrictive rights in your country of residence",
layer = 0,
enabled = true,
}
end
local Health, maxHealth, paralyzeDamage = 0,0,0
local SetUnitHealth = Spring.SetUnitHealth
local GetUnitHealth = Spring.GetUnitHealth
local exceptionList = {}
local alwaysTakesDamage = {}
if (gadgetHandler:IsSyncedCode()) then
function gadget:Initialize()
for i=1,#WeaponDefs do --search all WeaponDef entries
if string.find(WeaponDefs[i].description,"(teamdamage)") then
table.insert(exceptionList,i,1)
end
end
for ud,_ in pairs(UnitDefs) do -- search all UnitDef entries
if UnitDefs[ud].customParams.always_takes_damage == 'yes' then
table.insert(alwaysTakesDamage,ud,1)
end
end
end
function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
if unitTeam == attackerTeam then
Health, maxHealth, paralyzeDamage = GetUnitHealth(unitID)
if not exceptionList[weaponID] and not alwaysTakesDamage[unitDefID] then
if paralyzer then
SetUnitHealth(unitID,{paralyze = damage + paralyzeDamage})
else
if Health + damage < maxHealth then
SetUnitHealth(unitID,{health = Health + damage})
else
SetUnitHealth(unitID,{health = maxHealth})
end
end
end
end
end
end
Code: Select all
customParams
{
always_takes_damage=yes;
}
Code: Select all
name=NameOfYourNiftyGunHere (teamdamage);
One if in C++ is still a million times faster then executing a single LUA call, so if only a single mod needs a tag and it takes a single if instead of a single LUA call, the total amount of CPU time spread out over all mods would probably be lower with engine-side tagsArgh wrote:I'm guessing that further philosophical debate's entirely pointless. If you want to live in a Lua-less world, be my guest, nobody's forcing you to use this, unlike engine-side tags, which are not optional, eat CPU even if you're not using them (that infamous if-->then stuff that KDR thinks I'm so stupid for mentioning, it's still not free, and every new tag adds another one to Spring somewhere, often in multiple somewheres).
Well, that really depends. If it's C++, then it's a hidden drag on the entire sim state, whether or not the game designer's making use of it. It's an opportunity cost, basically.One if in C++ is still a million times faster then executing a single LUA call
This wasn't the point I tried to make. My point was that this hidden drag on the entire sim state when the feature is not used, is still lower - when summed over all mods that do not use the feature - then the "drag" of a single mod implementing it in LUA. (I'm sure that applies up to a surprising high number of mods.)Argh wrote:Well, that really depends. If it's C++, then it's a hidden drag on the entire sim state, whether or not the game designer's making use of it. It's an opportunity cost, basically.One if in C++ is still a million times faster then executing a single LUA call
Yes, any C++ vs. Lua comparision will show you that, in isolation, Lua's a lot slower than C++. This is absolutely true.
However, when you look at something on the order of complexity of Spring, I think that it's very arguable and situational.
zwzsg wrote:Sorry I wanted to type gadget, but mind was getting clouded from having to restrain myself to add question about what if there's also widgets relying on that call, as I knew people could retort that widget happens in a seperate stage.
Right now CA has a gadget preventing self damage where noSelfDamage fails to run in the current spring. It causes the dps widget to give constant popups at the base of an orbital laser, because of the bouncing beam.zwzsg wrote:Since nowadays more and more gameplay mechanic have to rely on this meddling with damage received ugly LUA hack, the probability of having a mod aggregate two of such gadgets and then splode rise greatly.