AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
|
07-29-2015
, 12:20
Re: [REQ] Loot AFK C4 ?
|
#11
|
Ok, check this:
PHP Code:
/* Copyleft 2015
SteaC4 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with StealC4; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <amxmodx> #include <amxmisc> #include <engine> #include <fakemeta> #include <hamsandwich> #include <cstrike>
#define PluginName "Steal C4" #define PluginVersion "0.3" #define PluginAuthor "HamletEagle"
new const NeededSound[] = "common/wpn_denyselect.wav"
new bool:CarrierIsCamping
new BombOwner new CvarDistance new CvarLootTime new CvarLootAfk new CvarAutoDropC4 new CvarAutoDropTime new MaxPlayers new gmsgBarTime
public plugin_init() { register_plugin ( .plugin_name = PluginName, .version = PluginVersion, .author = PluginAuthor ) register_forward(FM_EmitSound, "PfnEmitSound") RegisterHam(Ham_AddPlayerItem, "player", "CBasePlayer_AddPlayerItem", true) CvarLootTime = register_cvar("loot_time", "3") CvarLootAfk = register_cvar("loot_afk", "10") CvarDistance = register_cvar("loot_distance", "20.0") CvarAutoDropC4 = register_cvar("loot_autodropc4", "0") CvarAutoDropTime = register_cvar("loot_autodroptime", "20") MaxPlayers = get_maxplayers() gmsgBarTime = get_user_msgid("BarTime") set_task(1.0, "CheckCarrierAfk", .flags = "b") }
public CheckCarrierAfk() { if(BombOwner == 0) { return } static bool:SameOrigin, i static CampSeconds, DropSeconds static Float:PlayerOrigin[3]; pev(BombOwner, pev_origin, PlayerOrigin) static Float:PlayerOldOrigin[3] for(i = 0; i < 3; i++) { if(PlayerOrigin[i] == PlayerOldOrigin[i]) { SameOrigin = true break } else { SameOrigin = false break } } if(SameOrigin) { CampSeconds = CampSeconds + 1 if(CampSeconds >= get_pcvar_num(CvarLootAfk)) { CarrierIsCamping = true if(get_pcvar_num(CvarAutoDropC4) != 0) { DropSeconds = DropSeconds + 1 if(DropSeconds >= get_pcvar_num(CvarAutoDropTime)) { #if AMXX_VERSION_NUM < 183 engclient_cmd(BombOwner, "drop", "weapon_c4") #else amxclient_cmd(BombOwner, "drop", "weapon_c4") #endif BombOwner = 0 CarrierIsCamping = false } } else if(DropSeconds) { DropSeconds = 0 } } else { DropSeconds = 0 } } else { CampSeconds = 0 CarrierIsCamping = false } PlayerOldOrigin = PlayerOrigin }
public CBasePlayer_AddPlayerItem(id, WeaponEntity) { if(pev_valid(WeaponEntity) && cs_get_weapon_id(WeaponEntity) == CSW_C4) { if(1 <= id <= MaxPlayers) { BombOwner = id } } }
public PfnEmitSound(id, Channel, const Sound[], Float:Volume, Float:Attenuation, Flags, Pitch) { if(equal(Sound, NeededSound) && (pev(id, pev_button) & IN_USE)) //just to make sure, the sound may be reused for another action { if(1 <= id <= MaxPlayers) { if(!user_has_weapon(id, CSW_C4) && get_user_team(id) == 1) { if(CarrierIsCamping) { new Target, Body get_user_aiming(id, Target, Body) if(1 <= Target <= MaxPlayers && Target == BombOwner) { new Float:TargetOrigin[3]; pev(Target, pev_origin, TargetOrigin) new Float:PlayerOrigin[3]; pev(id, pev_origin, PlayerOrigin) if(get_distance_f(PlayerOrigin, TargetOrigin) <= get_pcvar_float(CvarDistance)) { new Time = get_pcvar_num(CvarLootTime) message_begin(MSG_ONE, gmsgBarTime, _, id) { write_short(Time) message_end() } set_task(float(Time), "TransferC4", id) } } } } } } }
public TransferC4(id) { fm_transfer_user_gun(BombOwner, id, CSW_C4) user_has_weapon(BombOwner, CSW_C4, 0) user_has_weapon(id, CSW_C4, 1) BombOwner = id }
stock bool:fm_transfer_user_gun(index1, index2, wid = 0, const wname[] = "") { new ent_class[32] if(!wid && wname[0]) { copy(ent_class, charsmax(ent_class), wname) } else { new weapon = wid, clip, ammo if(!weapon && !(weapon = get_user_weapon(index1, clip, ammo))) { return false } get_weaponname(weapon, ent_class, charsmax(ent_class)) }
new ent_weap = find_ent_by_owner(-1, ent_class, index1) if(!ent_weap) { return false }
engclient_cmd(index1, "drop", ent_class)
new ent_box = pev(ent_weap, pev_owner) if(!ent_box || ent_box == index1) { return false }
set_pev(ent_box, pev_flags, pev(ent_box, pev_flags) | FL_ONGROUND) dllfunc(DLLFunc_Touch, ent_box, index2) if(pev(ent_weap, pev_owner) != index2) { return false }
return true }
__________________
Last edited by HamletEagle; 07-29-2015 at 12:22.
|
|