Skip to content
View in the app

A better way to browse. Learn more.

Learn more

player-push-command/addons/amxmodx/scripting/olds_push.sma

olds_push.sma
190 lines · 5.5 KB · Pawn (AMX Mod X)
Raw
/*
 * Player Push Command (olds.ro)
 * Copyright (C) 2026 daemon (olds.ro)
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version. It is distributed WITHOUT ANY WARRANTY; see
 * <https://www.gnu.org/licenses/>.
 *
 * bind <key> +push (or say /push): shoves the player or loose object right in
 * front of you, then a cooldown.
 */
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN  "Player Push Command"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define PUSH_RANGE 80.0
#define PUSH_LIFT  0.3

new const PUSH_SOUND[] = "player/pl_pain2.wav"

new g_cvForce, g_cvCd, g_cvTeam, g_cvSpawnProt
new Float:g_next[MAX_PLAYERS + 1]
new Float:g_spawned[MAX_PLAYERS + 1]

public plugin_precache()
{
    precache_sound(PUSH_SOUND)
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_push.txt")

    g_cvForce = create_cvar("olds_push_force", "450", FCVAR_NONE, "Push speed (units per second)", true, 50.0, true, 2000.0)
    g_cvCd = create_cvar("olds_push_cd", "3.0", FCVAR_NONE, "Seconds between two pushes", true, 0.0, true, 60.0)
    g_cvTeam = create_cvar("olds_push_team", "1", FCVAR_NONE, "1 = teammates can be pushed too", true, 0.0, true, 1.0)
    g_cvSpawnProt = create_cvar("olds_push_spawnprot", "3.0", FCVAR_NONE, "Seconds after spawning in which a player cannot be pushed", true, 0.0, true, 60.0)
    AutoExecConfig(true, "olds_push")

    register_clcmd("+push", "cmd_push")
    register_clcmd("-push", "cmd_release")
    register_clcmd("say /push", "cmd_push")
    register_clcmd("say_team /push", "cmd_push")
    RegisterHam(Ham_Spawn, "player", "on_spawn_post", 1)
}

public client_putinserver(id)
{
    g_next[id] = 0.0
    g_spawned[id] = 0.0
}

public on_spawn_post(id)
{
    if (is_user_alive(id))
        g_spawned[id] = get_gametime()
    return HAM_IGNORED
}

public cmd_release(id)
{
    return PLUGIN_HANDLED
}

public cmd_push(id)
{
    if (!is_user_alive(id))
        return PLUGIN_HANDLED
    new Float:now = get_gametime()
    if (now < g_next[id])
    {
        client_print(id, print_center, "%L", id, "PUSH_COOLDOWN", g_next[id] - now)
        return PLUGIN_HANDLED
    }

    new Float:eye[3], Float:ofs[3], Float:angles[3], Float:dir[3], Float:end[3]
    pev(id, pev_origin, eye)
    pev(id, pev_view_ofs, ofs)
    pev(id, pev_v_angle, angles)
    angle_vector(angles, ANGLEVECTOR_FORWARD, dir)
    for (new i = 0; i < 3; i++)
    {
        eye[i] += ofs[i]
        end[i] = eye[i] + dir[i] * PUSH_RANGE
    }

    new tr = create_tr2()
    engfunc(EngFunc_TraceLine, eye, end, DONT_IGNORE_MONSTERS, id, tr)
    new target = get_tr2(tr, TR_pHit)
    free_tr2(tr)

    if (target > 0 && target <= MaxClients)
    {
        if (!can_push_player(id, target))
            target = 0
    }
    else if (target > MaxClients && !is_movable(target))
        target = 0

    // Loose objects that a line does not hit (trigger-solid balls and the like).
    if (target <= 0)
        target = find_object(id, eye, dir)
    if (target <= 0)
        return PLUGIN_HANDLED

    shove(target, angles[1], target <= MaxClients)
    emit_sound(target, CHAN_BODY, PUSH_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    g_next[id] = now + get_pcvar_float(g_cvCd)
    return PLUGIN_HANDLED
}

can_push_player(id, target)
{
    if (target == id || !is_user_alive(target))
        return 0
    if (get_pcvar_num(g_cvTeam) != 1 && get_user_team(target) == get_user_team(id))
        return 0
    if (get_gametime() - g_spawned[target] < get_pcvar_float(g_cvSpawnProt))
        return 0
    return 1
}

is_movable(ent)
{
    if (!pev_valid(ent))
        return 0
    switch (pev(ent, pev_movetype))
    {
        case MOVETYPE_TOSS, MOVETYPE_BOUNCE, MOVETYPE_STEP, MOVETYPE_PUSHSTEP:
            return 1
    }
    return 0
}

find_object(id, const Float:eye[3], const Float:dir[3])
{
    new Float:mid[3]
    for (new i = 0; i < 3; i++)
        mid[i] = eye[i] + dir[i] * (PUSH_RANGE * 0.5)

    new best, Float:bestDist = PUSH_RANGE + 1.0
    new ent = MaxClients
    while ((ent = engfunc(EngFunc_FindEntityInSphere, ent, mid, PUSH_RANGE * 0.6)) > 0)
    {
        if (ent <= MaxClients || ent == id || !is_movable(ent) || pev(ent, pev_owner) == id)
            continue
        if (pev(ent, pev_effects) & EF_NODRAW)
            continue
        new Float:o[3], Float:to[3]
        pev(ent, pev_origin, o)
        for (new i = 0; i < 3; i++)
            to[i] = o[i] - eye[i]
        new Float:dist = vector_length(to)
        if (dist > PUSH_RANGE || dist < 1.0)
            continue
        // In front: within about 35 degrees of the view.
        if ((to[0] * dir[0] + to[1] * dir[1] + to[2] * dir[2]) / dist < 0.82)
            continue
        if (dist < bestDist)
        {
            best = ent
            bestDist = dist
        }
    }
    return best
}

shove(target, Float:yaw, bool:player)
{
    new Float:speed = get_pcvar_float(g_cvForce)
    new Float:velocity[3]
    pev(target, pev_velocity, velocity)
    velocity[0] = floatcos(yaw, degrees) * speed
    velocity[1] = floatsin(yaw, degrees) * speed
    // A little lift so ground friction does not eat the push at once.
    if (player)
        velocity[2] = floatmax(velocity[2], speed * PUSH_LIFT)
    else
        velocity[2] = floatmax(velocity[2], 60.0)
    set_pev(target, pev_velocity, velocity)
    if (player)
        set_pev(target, pev_flags, pev(target, pev_flags) & ~FL_ONGROUND)
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.