Update SetEntityHealth() to manage more entities#1770
Update SetEntityHealth() to manage more entities#1770einyux wants to merge 1 commit intoalliedmodders:masterfrom einyux:master
Conversation
|
I don't really see a point to these utility stocks with all the general conveniences SM has around props these days. |
|
I see, I will go with SetEntProp for my case. At least the stock allows more with this, even if it's not the most efficient way. |
|
Been wondering, since |
Incredibly highly not recommended. We had issues with nested datamaps for a while, to the point where we wouldn't even allow setting them because the offset was wrong and writing to the wrong location (which can still do pretty sigificant damage, like overwriting a handle). Please use Get/SetEntProp, and should there be a case where you need Data, file a bug. |
Would the same problem arise with netprop offset ? If duplicates are an issue, could go from the precept that the valid m_iHeath absolute offset is the one with lowest value (guessing from the term nested datamaps). Though, I realise you're right in pointing out that Set/GetEntprop is better suited for this, as Going back to my original message, I was suggesting a native with cached offset because a PR I submitted in the past that landed does this. But regardless, taking a few steps back on the problem this PR tries to solve, I see that my answer makes no sense anyways. Would the following revision to the SetEntityHealth stock be accepted ? (And if so I'll open another PR to close this one) stock void SetEntityHealth(int entity, int amount)
{
static bool gotconfig = false;
static char prop[32];
if (!gotconfig)
{
GameData gc = new GameData("core.games");
bool exists = gc.GetKeyValue("m_iHealth", prop, sizeof(prop));
delete gc;
if (!exists)
{
strcopy(prop, sizeof(prop), "m_iHealth");
}
gotconfig = true;
}
PropFieldType type;
int offset;
if ((offset = FindDataMapInfo(entity, prop, type)) == -1)
{
ThrowError("SetEntityHealth not supported by this mod");
return;
}
/* Dark Messiah uses a float for the health instead an integer */
if (type == PropField_Float)
{
SetEntDataFloat(entity, offset, float(amount));
}
else
{
SetEntData(entity, offset, amount);
}
if (IsValidEdict(entity))
{
ChangeEdictState(entity);
}
}We essentially trade off |
In CS:GO, the health of a grenade projectile ("CBaseCSGrenadeProjectile") is present only in datamaps (NOT in sendprops).
This PR allows to set the health of this kind of entities.