Member
Join Date: Oct 2014
Location: wouldn't you like to kno
|
09-04-2017
, 15:56
Hooking primary attack to do stuff
|
#1
|
My shit plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <fun>
#define PLUGIN "Healing Bullets"
#define AUTHOR "Dracula Mafioso"
#define VERSION "1.0"
// map de_dust;bot_stop 1;mp_startmoney 16000;mp_freezetime 1
new purchased
new attackerid
new damage
new health
new weapon
new weaponid
new clip
new ammocount
public plugin_init()
{
register_plugin(PLUGIN,VERSION,AUTHOR);
register_event("Damage", "takedamage","b", "2>1");
register_event("DeathMsg", "RIP", "bf", _);
register_forward(FM_PlayerPreThink, "reducebullets");
register_clcmd("+attack", "reducebullets", 0); // Doesn't work
register_clcmd("healingbullets", "CmdBuy", 0, "Buys healing bullets");
}
public RIP(id)
{
if(purchased == 1)
{
purchased = 0;
set_hudmessage(133, 140, 72, 0.78, 0.85, 0, 6.0, 1.0)
show_hudmessage(id, "")
}
}
public CmdBuy(id)
{
weapon = get_user_weapon(id, clip, _);
switch(weapon)
{
case CSW_USP:
{
if(purchased == 1)
{
client_print(id, print_center, "You have already purchased it!");
return PLUGIN_HANDLED
}
if(cs_get_user_buyzone(id) == 0)
{
client_print(id, print_center, "You are not in a buyzone!");
return PLUGIN_HANDLED
}
if(cs_get_user_money(id) < (12*50))
{
switch(random_num(0,1))
{
case 0:client_print(id, print_chat, "You're jokin' right? You're skint!");
case 1:client_print(id, print_chat, "Insufficient funds!");
}
return PLUGIN_HANDLED
}
weaponid = find_ent_by_owner(-1, "weapon_usp45", id)
cs_set_weapon_ammo(weaponid, 12);
client_print(id, print_center, "You have purchased 1 clip of healing bullets");
purchased = 1;
ammocount = 12;
cs_set_user_money(id, cs_get_user_money(id)-(12*500));
set_hudmessage(133, 140, 72, 0.78, 0.85, 0, 6.0, 512.0)
show_hudmessage(id, "Healing bullets:%d",ammocount)
}
case CSW_P228:
{
if(purchased == 1)
{
client_print(id, print_center, "You have already purchased it!");
return PLUGIN_HANDLED
}
if(cs_get_user_buyzone(id) == 0)
{
client_print(id, print_chat, "You are not in a buyzone!");
return PLUGIN_HANDLED
}
if(cs_get_user_money(id) < (13*50))
{
switch(random_num(0,1))
{
case 0:client_print(id, print_chat, "You're jokin' right? You're skint!");
case 1:client_print(id, print_chat, "Insufficient funds!");
}
return PLUGIN_HANDLED
}
weaponid = find_ent_by_owner(-1, "weapon_p228", id)
cs_set_weapon_ammo(weaponid, 13);
client_print(id, print_center, "You have purchased 1 clip of healing bullets");
purchased = 1;
ammocount = 13;
cs_set_user_money(id, cs_get_user_money(id)-(13*500));
set_hudmessage(133, 140, 72, 0.78, 0.85, 0, 6.0, 512.0)
show_hudmessage(id, "Healing bullets:%d",ammocount)
}
}
}
public reducebullets(id)
{
if(get_user_button(id) &IN_ATTACK)
{
if(purchased == 1 && ammocount > 0)
{
client_print(0, print_chat, "DEBUG: user has purchased and >1 ammo");
ammocount--
set_hudmessage(133, 140, 72, 0.78, 0.85, 0, 6.0, 512.0)
show_hudmessage(id, "Healing bullets:%d",ammocount)
}
if(ammocount <= 0)
{
client_print(0, print_chat, "DEBUG: user has 0 ammo");
purchased = 0
ammocount = 0
set_hudmessage(133, 140, 72, 0.78, 0.85, 0, 6.0, 1.0)
show_hudmessage(id, "")
}
}
}
public takedamage(id)
{
attackerid = get_user_attacker(id)
if(get_user_weapon(attackerid,_,_) == CSW_KNIFE)
{
client_print(0, print_chat, "USING A KNIFE PLEB");
return PLUGIN_HANDLED
}
if(purchased ==1 && ammocount >0)
{
damage = read_data(2)
health = get_user_health(attackerid);
if(health == 100)
{
client_print(attackerid, print_chat, "DEBUG USER FULL HP");
return PLUGIN_HANDLED
}
if((health + (damage*0.6)) >=100)
{
set_user_health(attackerid, 100);
return PLUGIN_HANDLED
}
set_user_health(attackerid, floatround(((damage*0.6)+health)));
}
}
The forward hooked it, but what happens is as long as the +attack key is held down it keeps executing the hooked function as fast as my pc can process the requests. Can I somehow slow it down? For when you would hold down the attack button with a automatic gun the execution of the function reducebullets() would be synchronized with the fire rate of the weapon?
And make it fire once despite the button being held down for PISTOLS?
I'm interested if it can be slowed down to ways described. I could easily filter out how fast for each gun.
If not, what else can I do? Is there a better way to do this?
Edit: Fixed it by using
Code:
if(get_user_button(id) & IN_ATTACK) { //do stuff }
Last edited by Reel mafioso; 09-06-2017 at 04:25.
Reason: Fixed it :P
|
|