AoiKagase / Amxx-CrosshairMenu

2 stars 0 forks source link

As i see you like to fork and update plugins #3

Closed arkprocession closed 1 year ago

arkprocession commented 1 year ago

(Close this after reading, as is just a question) This question would not exist if i did not see you make forks and fix plugins, so here i go: publicly, it doesnt exist a plugin working fine that:

Example code that interferes with this functionality:

new const PLUGINNAME[] = "Drop all weapons when you die" // and also on disconnect
new const VERSION[] = "0.2.1"
new const AUTHOR[] = "JGHG & VEN & 80T"
/*
Copyleft by Johnny got his gun
http://www.amxmodx.org/forums/viewtopic.php?p=22368
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

// Defines
#define MODE_DEATH  (1<<0)
#define MODE_DISCONNECT (1<<1)

#define CVAR_NAME "daw_mode"
#define CVAR_DEF "3"

#define NROFITEMS 34

// Globals
new const WEAPONSTRINGS[NROFITEMS][] = {
    "",                     // 0 First should be empty
    "weapon_p228",
    "weapon_shield",
    "weapon_scout",
    "weapon_hegrenade",             // 4 weapon_hegrenade
    "weapon_xm1014",
    "",                     // 6 C4 CSW_C4
    "weapon_mac10",
    "weapon_aug",
    "weapon_smokegrenade",              // 9 weapon_smokegrenade
    "weapon_elite",
    "weapon_fiveseven",
    "weapon_ump45",
    "weapon_sg550",
    "weapon_galil",
    "weapon_famas",
    "weapon_usp",
    "weapon_glock18",
    "weapon_awp",
    "weapon_mp5navy",
    "weapon_m249",
    "weapon_m3",
    "weapon_m4a1",
    "weapon_tmp",
    "weapon_g3sg1",
    "weapon_flashbang",             // 25 weapon_flashbang
    "weapon_deagle",
    "weapon_sg552",
    "weapon_ak47",
    "",                     // 27 knife CSW_KNIFE
    "weapon_p90",
    "item_kevlar",
    "item_assaultsuit",
    "item_thighpack"
}

new g_pcvar
new g_drop[] = "drop"

new alive[33];

public plugin_init() {
    RegisterHam(Ham_Spawn, "weaponbox", "Ham_FOSpawn_weaponbox", 1);
    RegisterHam(Ham_Spawn, "player", "Ham_FOSpawn_player", 1);
    RegisterHam(Ham_Killed, "player", "Ham_FEKilled_player", 0);

    RegisterHam(Ham_CS_Item_CanDrop, "weapon_hegrenade", "Enable_Drop")
    RegisterHam(Ham_CS_Item_CanDrop, "weapon_flashbang", "Enable_Drop")
    RegisterHam(Ham_CS_Item_CanDrop, "weapon_smokegrenade", "Enable_Drop")
    // RegisterHam(Ham_CS_Item_CanDrop, "weapon_c4", "Disable_Drop")

    register_plugin(PLUGINNAME, VERSION, AUTHOR)

    register_event("DeathMsg", "death_event", "a", "2!0")
    register_event("CurWeapon", "Event_CurWeapon", "be");

    g_pcvar = register_cvar(CVAR_NAME, CVAR_DEF)
}

public Ham_FOSpawn_player(id)
    alive[id] = 1;

public Ham_FEKilled_player(victim, idattacker, shouldgib) {
    client_dies(victim);
    return HAM_IGNORED;
}

public Event_CurWeapon(id) {
    if(alive[id])
        alive[id] = 1;
}

public client_dies(id) {
    if(!alive[id])
        return;
    alive[id] = 0;
}

public Enable_Drop(iEnt) {
    SetHamReturnInteger(1)
    return HAM_SUPERCEDE
}

public Disable_Drop(iEnt) {
    SetHamReturnInteger(0)
    return HAM_SUPERCEDE
}

public death_event() {
    if (get_pcvar_num(g_pcvar) & MODE_DEATH)
        drop_all_weapons(read_data(2))
}

public client_disconnect(id) {
    client_dies(id);
    if (get_pcvar_num(g_pcvar) & MODE_DISCONNECT)
        drop_all_weapons(id)
}

drop_all_weapons(id) {
    new weapons[32], weaponsInList, wid
    get_user_weapons(id, weapons, weaponsInList)
    for (new i = 0; i < weaponsInList; i++) {
        wid = weapons[i]
        if (wid != CSW_KNIFE && wid != CSW_C4) {
            engclient_cmd(id, g_drop, WEAPONSTRINGS[wid])
        }
    }
}

public Ham_FOSpawn_weaponbox(weaponbox_ent) {
    set_pev(weaponbox_ent, pev_velocity, Float:{0.0, 0.0, 0.0});
    set_task(0.1, "spread_weapons", weaponbox_ent);
}

public spread_weapons(weaponbox_ent) {
    static classname[32], owner
    if(!pev_valid(weaponbox_ent))
        return

    pev(weaponbox_ent, pev_classname, classname, 31);
    if(!equal(classname, "weaponbox") && !equal(classname, "armoury_entity"))
        return

    owner = pev(weaponbox_ent, pev_owner)
    if(!pev_valid(owner))
        return

    pev(owner, pev_classname, classname, 31)
    if(!equal(classname, "player"))
        return

    if(alive[owner])
        return

    new Float:flAngles[3], Float:flVelocity[3]
    pev(owner, pev_angles, flAngles)
    pev(owner, pev_velocity, flVelocity)
    flAngles[1] = random_float(0.0, 360.0)
    flVelocity[0] = random_float(-150.0, 150.0)
    flVelocity[1] = random_float(-150.0, 150.0)
    set_pev(weaponbox_ent, pev_angles, flAngles);
    set_pev(weaponbox_ent, pev_velocity, flVelocity);
}

Here an example of how to keep bpammo on weapon transfer or drop, flawlessly:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <hamsandwich>

new const Version[] = "0.1";

enum WeaponSlots
{
    Slot1 = 1,
    Slot2
}

public plugin_init() 
{
    register_plugin( "Drop BP Ammo with Weapon" , Version , "bugsy" );

    register_forward( FM_SetModel , "SetModel" );
    RegisterHam( Ham_AddPlayerItem , "player" , "AddPlayerItem" );
}

public SetModel( iEntity , const szModel[] )
{
    new szClassname[ 32 ] , iWeaponEntID , iWeaponSlot , iBPAmmo;

    pev( iEntity , pev_classname , szClassname , charsmax( szClassname ) );

    if ( equal ( szClassname , "weaponbox" ) )
    {
        if ( pev_valid( ( iWeaponEntID = GetWeaponEntityFromWeaponbox( iEntity , iWeaponSlot ) ) ) )
        {
            if ( ( iBPAmmo = cs_get_user_bpammo( pev( iEntity , pev_owner ) , cs_get_weapon_id( iWeaponEntID ) ) ) )
                set_pev( iWeaponEntID , pev_iuser2 , iBPAmmo );
        }
    }
} 

public AddPlayerItem( iPlayer , iEntity )
{
    new iBPAmmo = pev( iEntity , pev_iuser2 );

    if ( iBPAmmo )
        cs_set_user_bpammo( iPlayer , cs_get_weapon_id( iEntity ) , iBPAmmo );
}

GetWeaponEntityFromWeaponbox( iWeaponBox , &iWeaponSlot )
{
    new const m_rgpPlayerItems_Weaponbox[ 6 ] = { 34 , 35 , ... };
    new iWeaponEntID;

    for ( new WeaponSlots:iSlot = Slot1 ; iSlot <= Slot2 ; iSlot++ )
    {
        if ( ( iWeaponEntID = get_pdata_cbase( iWeaponBox , m_rgpPlayerItems_Weaponbox[ 0 ] + _:iSlot ) ) > 0 )
        {
            iWeaponSlot = _:iSlot;
            break;
        }
    }    

    return ( iWeaponEntID > 0 ) ? iWeaponEntID : 0;
}  

2 - A plugin that modifies damage and doesn't mess with other plugins, or scoreboard, Known issues: plugins that register events based on deaths, print messages, etc tends to get the info wrong. For example a plugin that reports with print chat the death of an enemy, says the enemy killed himself by the "added damage" to a vanilla weapon.

for example i have this code:


#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <engine>

#define PLUGIN  "Extra Damage Mod"
#define VERSION "0.2"
#define AUTHOR  "v3x"

#define ACCESS_LEVEL    ADMIN_CFG
#define MAXWEAPS    31

new cstrike;

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
    register_concmd("sv_weapondamage", "ConCmd_WeapDmg", ACCESS_LEVEL, ": <weaponid> <damage>");
    register_concmd("amx_weaponlist", "ConCmd_WeapList", 0, ": Lists weapon ids");
    register_event("Damage", "Event_Damage", "b", "2>0");

    cstrike = cstrike_running();
}

new g_nWeapDmg[MAXWEAPS] = { 0, ... };

public Event_Damage( id )
{
    new iWeapID, iHitzone, iAttacker = get_user_attacker(id, iWeapID, iHitzone);

    if(!is_user_connected(id) || !is_user_connected(iAttacker))
        return PLUGIN_CONTINUE;

    new dmgType = read_data(3);

    if(dmgType & DMG_BLAST)
        iWeapID = 4;

    extra_damage(iAttacker, id, g_nWeapDmg[iWeapID], iWeapID);

    return PLUGIN_CONTINUE;
}

public ConCmd_WeapDmg( id, lvl, cid )
{
    if(!cmd_access(id, lvl, cid, 3))
        return PLUGIN_HANDLED;

    new arg1[16], arg2[8];
    read_argv(1, arg1, 15); // Weapon ID
    read_argv(2, arg2, 7);  // Damage amt

    new weapid = str_to_num(arg1);
    new damage = str_to_num(arg2);

    if(weapid > 0 && weapid < MAXWEAPS)
    {
        if(weapid == 2 || weapid == 6 || weapid == 9 || weapid == 25)
        {
            console_print(id, "[XtraDamageMod] Invalid weapon id: %i", weapid);
            server_print("[XtraDamageMod] Invalid weapon id: %i", weapid);
            return PLUGIN_HANDLED;
        }

        g_nWeapDmg[weapid] = damage;

        new weapname[33];
        get_weaponname(weapid, weapname, 32);

        replace(weapname, 32, "weap_", "");

        if(damage > 0)
        {
            console_print(id, "[XtraDamageMod] Added %i extra damage for %s", damage, weapname);
        }
        else if(damage <= 0)
        {
            console_print(id, "[XtraDamageMod] Removed extra damage for %s", damage, weapname);
        }
    }

    if(weapid == 0)
    {
        for(new i = 1; i < MAXWEAPS; i++)
            g_nWeapDmg[i] = damage;

        if(damage > 0)
        {
            console_print(id, "[XtraDamageMod] Added %i extra damage for all weapons", damage);
        }
        if(damage <= 0)
        {
            console_print(id, "[XtraDamageMod] Removed extra damage for all weapons");
        }
    }

    return PLUGIN_HANDLED;
}

// Doesn't work well for clients..
public ConCmd_WeapList( id )
{
    new arg[8];
    read_argv(1, arg, 7);

    new szWeapMsg[256], nLen, iPage = str_to_num(arg);

    nLen = format(szWeapMsg, 255, "[ExtraDamageMod] Weapon ID list %s", (iPage==2) ? "(con.):" : ":");

    if(iPage == 0 || iPage == 1)
    {
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- P228: %i", CSW_P228);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Scout: %i", CSW_SCOUT);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- HE Grenade: %i", CSW_HEGRENADE);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- XM1014 (autoshotgun): %i", CSW_XM1014);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Mac10: %i", CSW_MAC10);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Aug: %i", CSW_AUG);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Elites: %i", CSW_ELITE);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Fiveseven: %i", CSW_FIVESEVEN);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- UMP45: %i", CSW_UMP45);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- SG550: %i", CSW_SG550);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Galil: %i", CSW_GALIL);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Famas: %i", CSW_FAMAS);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- USP: %i", CSW_USP);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n^nType 'amx_weaponlist 2' for more");
    }
    else if(iPage == 2)
    {
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Glock18: %i", CSW_GLOCK18);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- AWP: %i", CSW_AWP);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- MP5NAVY: %i", CSW_MP5NAVY);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- M249 (Para): %i", CSW_M249);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- M3 (Pump): %i", CSW_M3);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- M4A1: %i", CSW_M4A1);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- TMP: %i", CSW_TMP);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- G3SG1: %i", CSW_G3SG1);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Deagle: %i", CSW_DEAGLE);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- SG552: %i", CSW_SG552);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- AK47: %i", CSW_AK47);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- Knife: %i", CSW_KNIFE);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n- P90: %i", CSW_P90);
        nLen += format(szWeapMsg[nLen], (255-nLen), "^n^nType 'amx_weaponlist 1' to go back");
    }

    if(is_user_connected(id))
        console_print(id, szWeapMsg);
    else
        server_print(szWeapMsg);

    return PLUGIN_HANDLED;
}

public extra_damage(attacker, victim, damage, weap)
{
    if(!cstrike || !is_user_connected(attacker) || !is_user_connected(victim))
        return;
    if(damage <= 0 || get_user_health(victim) <= 0 || get_user_godmode(victim))
        return;

    new FFon = get_cvar_num("mp_friendlyfire");

    new index, body, distance = 99999;
    get_user_aiming(attacker, index, body, distance);

    new weaponname[33];
    get_weaponname(weap, weaponname, 32);

    replace(weaponname, 32, "weapon_", "");

    new team[2];
    team[0] = get_user_team(attacker);
    team[1] = get_user_team(victim);

    if(FFon && team[0] == team[1])
    {
        new name[32];
        get_user_name(attacker, name, 31);
        client_print(0, print_chat, "%s attacked a teammate", name);
    }

    if(get_user_health(victim) > damage)
    {
        fakedamage(victim, weaponname, float(damage), (weap == 4) ? DMG_BLAST : DMG_BULLET); 

        new origin[3];
        get_user_origin(victim, origin);

        message_begin(MSG_ONE, get_user_msgid("Damage"), {0,0,0}, victim);
        write_byte(0);      // dmg_save
        write_byte(damage); // dmg_take
        write_long(0);      // visibleDamageBits
        write_coord(origin[0]); // damageOrigin.x
        write_coord(origin[1]); // damageOrigin.y
        write_coord(origin[2]); // damageOrigin.z
        message_end();
    }
    else
    {
        log_kill(attacker, victim, weaponname, (body == HIT_HEAD) ? 1 : 0);
    }
}

stock log_kill(killer, victim, weapon[],headshot) 
{
    new weapname[64];

    if(containi(weapon, "nade") != -1)
        format(weapname, 63, "grenade");
    else
    {
        format(weapname, 63, "%s", weapon);
        replace(weapname, 63, "weapon_", "");
    }

    user_silentkill(victim)
    set_msg_block(get_user_msgid("DeathMsg"), BLOCK_NOT)
    static msgid = 0
if (!msgid)
{
    msgid = get_user_msgid("DeathMsg")
}
emessage_begin(MSG_ALL, msgid, {0,0,0}, 0)
ewrite_byte(killer)
ewrite_byte(victim)

static mod_name[32]

if (!mod_name[0])
{
    get_modname(mod_name, 31)
}
if (equal(mod_name, "cstrike") || equal(mod_name, "czero") || equal(mod_name, "csv15") || equal(mod_name, "cs13"))
    ewrite_byte(headshot)
ewrite_string(weapname)
emessage_end()

    if(get_user_team(killer) != get_user_team(victim))
    {
        set_user_frags(killer, get_user_frags(killer) + 1);

        new money = cs_get_user_money(killer) + 300;

        if(money >= 2147483583)
        {
            cs_set_user_money(killer, 2147483583);
        }
        else
        {
            cs_set_user_money(killer, cs_get_user_money(killer) + 300, 1);
        }
    }
    if(get_user_team(killer)==get_user_team(victim))
        set_user_frags(killer, get_user_frags(killer) - 1);

    message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"));
    write_byte(killer);
    write_short(get_user_frags(killer));
    write_short(cs_get_user_deaths(killer));
    write_short(0);
    write_short(1);
    message_end(); 

    new kname[32], vname[32], kauthid[32], vauthid[32], kteam[10], vteam[10];

    get_user_name(killer, kname, 31);
    get_user_team(killer, kteam, 9);
    get_user_authid(killer, kauthid, 31);

    get_user_name(victim, vname, 31);
    get_user_team(victim, vteam, 9);
    get_user_authid(victim, vauthid, 31);

    log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"%s^"", 
    kname, get_user_userid(killer), kauthid, kteam, 
    vname, get_user_userid(victim), vauthid, vteam, weapname);

    return PLUGIN_CONTINUE;
}

For example, this plugin register deaths with altered damage on weapons as suicides if i use the above plugin:


#include <amxmodx>
#include <reapi>

#define PLUGIN  "[Reapi] Mensaje de Muerte en el Chat"
#define VERSION "1.5"
#define AUTHOR  "[N]drs"

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    register_message(get_user_msgid("DeathMsg"), "OnServer_SendMessage_DeathMsg")
    RegisterHookChain(RG_CBasePlayer_Killed, "OnPlayer_Killed_Post", true)
}

public OnServer_SendMessage_DeathMsg()
    return PLUGIN_HANDLED

public OnPlayer_Killed_Post(iVictim, iAttacker, iGib)
{
    static szWeaponName[25]

    if(!iAttacker || iAttacker == iVictim)
    {
        client_print_color(0, print_team_grey, "^4[Server] ^3^4%n ^3 killed himself", iVictim)
        return
    }

    get_weaponname(get_user_weapon(iAttacker), szWeaponName, charsmax(szWeaponName))
    replace_string(szWeaponName, charsmax(szWeaponName), "weapon_", "")

    client_print_color(0, print_team_grey, "[Server]^4%n ^3killed ^4%n ^3with ^4%s", iAttacker, iVictim, szWeaponName)
} 
AoiKagase commented 1 year ago

1.Drop all weapons when you die

2.Extra Damage Mod

3.[Reapi] Mensaje de Muerte en el Chat

arkprocession commented 1 year ago

1.Drop all weapons when you die

  • I think ReviveKit had an automatic weapon box retrieval feature, but is that doing something bad?

2.Extra Damage Mod

  • I think Hamsandwich or ReAPI could be used to handle the damage more reliably.
  • There is a way to modify this.

3.[Reapi] Mensaje de Muerte en el Chat

  • There seems to be no particular problem, but Hamsandwich seems sufficient without the need to use ReAPI.

I don't think i ever experienced a weaponbox retrieval feature in your revival kit. its not doing anything bad at all,

But by default in vanilla condition zero, if player A picks up an AK47 and then drops it to the floor, the weapon box/ ammo box stays with the player, and the dropped weapon will have only 30 bullets and no bpammo.

With that little portion of code from bugsy, the weapon remember its bpammo and everything works.

I gave you that code just as an example of a fix of a big lack of functionality in my opinion.

The real problem: Not being able to drop secondary weapons when carrying a primary, without losing the functionality of " dropped pinless grenades on death makes them explode" its from condition zero vanilla. So i cannot use the code for dropping secondary weapons as i presented you because it cancels that functionality. How? it cancels it by dropping the grenade intact, as if you were just carrying it but not intending to use it. Even if the grenade its not declared as a droppeable weapon in that code.

If you are interested in it, i know you will fork it, and if you do, then the objective will be:

Make secondary weapons drops and not interfere with grenades without pin exploding if player is killed before throwing them