I'm having an issue with CTakeDamageInfo
's functions not being registered after being restored from a save file. (CTakeDamageInfo
is a class exposed by my own changes)
First, I spawned a citizen running a script file named test_takedamage_1
:
function TakeDamage()
{
local ent = Entities.FindByName(null,"devzombies")
local info = CreateDamageInfo(ent, ent, Vector(0, 0, 100000), Vector(0,0,0), 1000, 0)
if (ent)
{
printl("Found zombie, applying damage " + info.GetDamage())
ent.TakeDamage(info)
}
else
{
printl("Can't find zombie")
}
DestroyDamageInfo(info)
}
Then, after saving the game and loading the save, I spawned a zombie named devzombies
and ran the following command on the citizen:
ent_fire !picker runscriptcode "TakeDamage()"
This code fails to run, with the console containing the following error:
(16.35) input : devcitizen.runscriptcode(TakeDamage())
CALLSTACK
*FUNCTION [TakeDamage()] test_takedamage_1.nut line [9]
AN ERROR HAS OCCURRED [the index 'GetDamage' does not exist]
*FUNCTION [main()] InputRunScript line [1]
[this] TABLE
LOCALS
[vargv] ARRAY
[info] NULL
[this] TABLE
[ent] INSTANCE
Entity devcitizen encountered an error in RunScript()
This is the case with any entity running any code involving CTakeDamageInfo
from that point forward, but it curiously does not happen if there is no script in the level involving CTakeDamageInfo
when the game is saved and its first involvement is after the save is loaded.
This has not been tested with other classes.
Steps to reproduce
- Load
mapbase_demo02
- Spawn a citizen by typing the following command into the console:
npc_create npc_citizen devcitizen vscripts "test_takedamage_1"
(NOTE: Assumes the script above was saved as test_takedamage_1
in scripts/vscripts
)
- Save the game
- Load the save
- Spawn a zombie by typing the following command into the console:
npc_create npc_zombie devzombies
- Run the following command in the console:
ent_fire devcitizen runscriptcode "TakeDamage()"
CTakeDamageInfo
script desc
BEGIN_SCRIPTDESC_ROOT( CTakeDamageInfo, "Damage information handler." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetInflictor, "GetInflictor", "Gets the inflictor." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetInflictor, "SetInflictor", "Sets the inflictor." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetWeapon, "GetWeapon", "Gets the weapon." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetWeapon, "SetWeapon", "Sets the weapon." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAttacker, "GetAttacker", "Gets the attacker." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAttacker, "SetAttacker", "Sets the attacker." )
DEFINE_SCRIPTFUNC( GetDamage, "Gets the damage." )
DEFINE_SCRIPTFUNC( SetDamage, "Sets the damage." )
DEFINE_SCRIPTFUNC( GetMaxDamage, "Gets the max damage." )
DEFINE_SCRIPTFUNC( SetMaxDamage, "Sets the max damage." )
DEFINE_SCRIPTFUNC( ScaleDamage, "Scales the damage." )
DEFINE_SCRIPTFUNC( AddDamage, "Adds to the damage." )
DEFINE_SCRIPTFUNC( SubtractDamage, "Removes from the damage." )
DEFINE_SCRIPTFUNC( GetDamageBonus, "Gets the damage bonus." )
DEFINE_SCRIPTFUNC( SetDamageBonus, "Sets the damage bonus." )
DEFINE_SCRIPTFUNC( GetBaseDamage, "Gets the base damage." )
DEFINE_SCRIPTFUNC( BaseDamageIsValid, "Checks if the base damage is valid." )
DEFINE_SCRIPTFUNC( GetDamageForce, "Gets the damage force." )
DEFINE_SCRIPTFUNC( SetDamageForce, "Sets the damage force." )
DEFINE_SCRIPTFUNC( ScaleDamageForce, "Scales the damage force." )
DEFINE_SCRIPTFUNC( GetDamagePosition, "Gets the damage position." )
DEFINE_SCRIPTFUNC( SetDamagePosition, "Sets the damage position." )
DEFINE_SCRIPTFUNC( GetReportedPosition, "Gets the reported damage position." )
DEFINE_SCRIPTFUNC( SetReportedPosition, "Sets the reported damage position." )
DEFINE_SCRIPTFUNC( GetDamageType, "Gets the damage type." )
DEFINE_SCRIPTFUNC( SetDamageType, "Sets the damage type." )
DEFINE_SCRIPTFUNC( AddDamageType, "Adds to the damage type." )
DEFINE_SCRIPTFUNC( GetDamageCustom, "Gets the damage custom." )
DEFINE_SCRIPTFUNC( SetDamageCustom, "Sets the damage custom." )
DEFINE_SCRIPTFUNC( GetDamageStats, "Gets the damage stats." )
DEFINE_SCRIPTFUNC( SetDamageStats, "Sets the damage stats." )
DEFINE_SCRIPTFUNC( IsForceFriendlyFire, "Gets force friendly fire." )
DEFINE_SCRIPTFUNC( SetForceFriendlyFire, "Sets force friendly fire." )
DEFINE_SCRIPTFUNC( GetAmmoType, "Gets the ammo type." )
DEFINE_SCRIPTFUNC( SetAmmoType, "Sets the ammo type." )
DEFINE_SCRIPTFUNC( GetAmmoName, "Gets the ammo type name." )
DEFINE_SCRIPTFUNC( GetPlayerPenetrationCount, "Gets the player penetration count." )
DEFINE_SCRIPTFUNC( SetPlayerPenetrationCount, "Sets the player penetration count." )
DEFINE_SCRIPTFUNC( GetDamagedOtherPlayers, "Gets whether other players have been damaged." )
DEFINE_SCRIPTFUNC( SetDamagedOtherPlayers, "Sets whether other players have been damaged." )
END_SCRIPTDESC();