Page 1 of 1

Lua Weapon Variable Damage [uh, Solved already?]

Posted: Sun Jul 10, 2011 12:34 am
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]

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

Posted: Sun Jul 10, 2011 1:10 am
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]

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

Posted: Sun Jul 10, 2011 1:20 am
by kinetosimpetus
Probably no noticeable difference.