Target5150 / MoYu_Server_Stupid_Plugins

L4D2 Target Cat Project
GNU General Public License v3.0
80 stars 21 forks source link

[SUG] Some minor additions in l4d_tank_damage_announce #36

Closed nikita1824 closed 1 year ago

nikita1824 commented 1 year ago

Hello, recently I saw your changes for l4d_tank_damage_announce, as I can see you merged it with l4d2_tank_facts_announce Here are some minor additions if you don't mind: We could add this to avoid the case when tank didn't get any damage:

public void L4D_OnSpawnTank_Post(int client, const float vecPos[3], const float vecAng[3])
{
    ...
    g_aTankInfo.UserSet(userid, eTankLastHealth, float(GetEntProp(client, Prop_Send, "m_iMaxHealth"))); // <<< add this
}

and we could add natives for third party plugins (I used l4d2_tank_facts_announce to get tank statistics for spechud) (correct me if I misunderstood the code):

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
    CreateNative("TFA_Punches", Native_Punches);
    CreateNative("TFA_Rocks", Native_Rocks);
    CreateNative("TFA_Hittables", Native_Hittables);
    CreateNative("TFA_TotalDmg", Native_TotalDamage);
    CreateNative("TFA_UpTime", Native_UpTime);
    RegPluginLibrary("l4d_tank_damage_announce");
    ...
}

any Native_Punches(Handle hPlugin, int iNumParams) {
    int iClient = GetNativeCell(1);
    if (iClient <= 0) return 0;
    int iUserId = GetClientUserId(iClient);
    int iIdx = 0;
    int iTotalPunch;
    if (!g_aTankInfo.UserIndex(iUserId, iIdx, false))
        return 0;
    UserVector uSurvivorVector = g_aTankInfo.Get(iIdx, eSurvivorInfoVector);
    for (int i = 0; i < uSurvivorVector.Length; i++) {
        iTotalPunch += uSurvivorVector.Get(i, ePunch);
    }
    return iTotalPunch;
}

any Native_Rocks(Handle hPlugin, int iNumParams) {
    int iClient = GetNativeCell(1);
    if (iClient <= 0) return 0;
    int iUserId = GetClientUserId(iClient);
    int iIdx = 0;
    int iTotalRock;
    if (!g_aTankInfo.UserIndex(iUserId, iIdx, false))
        return 0;
    UserVector uSurvivorVector = g_aTankInfo.Get(iIdx, eSurvivorInfoVector);
    for (int i = 0; i < uSurvivorVector.Length; i++) {
        iTotalRock += uSurvivorVector.Get(i, eRock);
    }
    return iTotalRock;
}

any Native_Hittables(Handle hPlugin, int iNumParams) {
    int iClient = GetNativeCell(1);
    if (iClient <= 0) return 0;
    int iUserId = GetClientUserId(iClient);
    int iIdx = 0;
    int iTotalHittable;
    if (!g_aTankInfo.UserIndex(iUserId, iIdx, false))
        return 0;
    UserVector uSurvivorVector = g_aTankInfo.Get(iIdx, eSurvivorInfoVector);
    for (int i = 0; i < uSurvivorVector.Length; i++) {
        iTotalHittable += uSurvivorVector.Get(i, eHittable);
    }
    return iTotalHittable;
}

any Native_TotalDamage(Handle hPlugin, int iNumParams) {
    int iClient = GetNativeCell(1);
    if (iClient <= 0) return 0;
    int iUserId = GetClientUserId(iClient);
    int iIdx = 0;
    if (!g_aTankInfo.UserIndex(iUserId, iIdx, false))
        return 0;
    int iTotalDamage = g_aTankInfo.Get(iIdx, eTotalDamage);
    return iTotalDamage;
}

any Native_UpTime(Handle plugin, int numParams) {
    int iClient = GetNativeCell(1);
    if (iClient <= 0) return 0;
    int iUserId = GetClientUserId(iClient);
    int iIdx = 0;
    if (!g_aTankInfo.UserIndex(iUserId, iIdx, false))
        return 0;
    int iAliveDuration = RoundToFloor(GetGameTime() - view_as<float>(g_aTankInfo.Get(iIdx, eAliveSince)));
    return iAliveDuration;
}
jensewe commented 1 year ago

Thanks for the fix and writing the natives. Along with some other stuff, the commit above should help. Well a note that I'm not likely to make a full test on it at least now (or just lazy smh), any help is really appreciated.

nikita1824 commented 1 year ago

Hello again, thank you for your update. I'm sorry for the bad advice in the first addition (I didn't test it when posted)

jensewe commented 1 year ago

Yep I noticed and corrected during the update. Though I'd like to add that it isn't really good to store up the health on spawn, as I recenrly found some mutation manually changing the tank health in custom logics. I cannot clearly tell if L4D_OnSpawnTank_Post is called after game event tank_spawn, anyway I'd prefer to handle the max health at the very end (tank gets killed). Should be in the next update.