Lua Weapon Variable Damage [uh, Solved already?]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Lua Weapon Variable Damage [uh, Solved already?]

Post by kinetosimpetus »

I'm trying to make a cannon to be fired by a vehicle or turret against other vehicles, turrets, whatever really, that does a different amount of damage each shot, specifically so as you keep shooting it, it becomes less effective to a target if you keep hitting it.

I started with a chunk of LUA that detects a weapon hit, and heals the attacker, and I've changed it, to damage the attacker in the way I mentioned, but I'm not sure how to make it damage the target instead. I'm not sure the GetCharacterUnit line will work, because the target might not be a "Character"? :?
Hidden/Spoiler:
[code]

OnObjectDamage(function(object, damager)

if damager == nil then
return
end

if GetObjectLastHitWeaponClass(object) == "com_weap_veh_ion_cannon" then
local unit = GetCharacterUnit(damager)
if unit == nil then
return
end

local damage = GetObjectHealth(unit) * 0.20

if damage > 1000 then
damage = 1000
end

SetProperty(unit, "CurHealth", GetObjectHealth(unit) - damage)

end

end
)[/code]
EDIT: Well, that was easy...

New code that works if anyone likes it.
Hidden/Spoiler:
[code]

OnObjectDamage(function(object, damager)

if damager == nil then
return
end

if GetObjectLastHitWeaponClass(object) == "com_weap_veh_ion_cannon" then
local unit = GetCharacterUnit(damager)
if unit == nil then
return
end

local damage = GetObjectHealth(object) * 0.20

if damage > 1000 then
damage = 1000
end

SetProperty(object, "CurHealth", GetObjectHealth(object) - damage)

end

end
)[/code]
Jaspo
Command Sergeant Major
Command Sergeant Major
Posts: 282
Joined: Sun Mar 01, 2009 4:34 am
Projects :: AotC DoW+++Boonta Eve Classic
Games I'm Playing :: WoT MBWBVC Robocraft
xbox live or psn: No gamertag set
Contact:

Re: Lua Weapon Variable Damage [uh, Solved already?]

Post by Jaspo »

Does this work better? At all? The same?
Hidden/Spoiler:
[code]OnObjectDamage(function(object, damager)

if damager == nil then
return
end

if GetObjectLastHitWeaponClass(object) == "com_weap_veh_ion_cannon" then
local object_instance = GetCharacterUnit(object)
if object_instance == nil then
return
end

damage = GetObjectHealth(object_instance) * 0.20

if damage > 1000 then
damage = 1000
end

SetProperty(object_instance, "CurHealth", GetObjectHealth(object_instance) - damage)

end

end
)[/code]
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Re: Lua Weapon Variable Damage [uh, Solved already?]

Post by kinetosimpetus »

Probably no noticeable difference.
Post Reply