So I'm making a plugin that allows to buy a cannon gun, but the problem is that it doesn't matter what delay I make for next shot it fires slowly anyway.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <engine>
#define PLUGIN "Cannon GUN"
#define VERSION "1.0"
#define AUTHOR "-=3rn1s=-"
#define fm_create_entity(%1) engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, %1))
enum /* Weapon types */
{
Primary = 1
, Secondary
, Knife
, Grenades
, C4
}
new const VIEW_MODELCANNON[] = "models/v_cannon.mdl"
new const PLAYER_MODELCANNON[] = "models/p_cannon.mdl"
new const WORLD_MODELCANNON[] = "models/w_cannon.mdl"
new bool:hascannon[33]
new curweapon[33]
new drawed[33]
new Float:nextshot[33]
public plugin_precache()
{
precache_model(VIEW_MODELCANNON)
precache_model(PLAYER_MODELCANNON)
precache_model(WORLD_MODELCANNON)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /cannon", "BuyCannon")
register_event( "CurWeapon", "Event_CurWeapon", "be", "1=1" )
register_forward(FM_UpdateClientData, "UpdateClientData_Post", 1)
register_forward(FM_CmdStart,"fwd_CmdStart")
}
public client_connect(id)
{
hascannon[id] = false
drawed[id] = false
}
public client_disconnect(id)
{
hascannon[id] = false
drawed[id] = false
}
public fwd_CmdStart(id, uc_handle, seed)
{
if(!is_user_alive(id) || !hascannon[id] || curweapon[id] != CSW_P90) return FMRES_IGNORED
new buttons = get_uc(uc_handle,UC_Buttons)
if(buttons & IN_ATTACK)
{
buttons &= ~IN_ATTACK
set_uc(uc_handle,UC_Buttons,buttons)
if(drawed[id])
{
new wep = find_ent_by_owner(-1, "weapon_p90", id)
new Float:gtime = get_gametime()
if(cs_get_weapon_ammo(wep) > 0 && nextshot[id] <= gtime)
{
//MakeShot(id)
client_print(id, print_chat, "sove")
nextshot[id] = gtime + 0.2
cs_set_weapon_ammo(wep, cs_get_weapon_ammo(wep)-1)
message_begin(MSG_ONE, SVC_WEAPONANIM, _, id)
write_byte(3) //Animation id
write_byte(pev(id,pev_body))
message_end()
}
}
}
return FMRES_HANDLED
}
public UpdateClientData_Post( id, sendweapons, cd_handle )
{
//No sense in doing this for dead people?
//Add your additional checks and whatnot...
if (!is_user_alive(id) || !hascannon[id] || curweapon[id] != CSW_P90)
return FMRES_IGNORED;
//We want to use the cd_handle passed to us
//unless you want this for all the players
//in which you would specify 0 instead
//We get the current half-life time and set the next attack to a fraction of a sec later...
//This must be modified every time or else it won't block the attack
set_cd(cd_handle, CD_flNextAttack, halflife_time() + 0.001 );
//And finally return...
return FMRES_HANDLED;
}
public Event_CurWeapon( id )
{
drawed[id] = false
if(task_exists(id))
remove_task(id)
if(read_data(2) == CSW_P90 && hascannon[id])
{
set_pev( id, pev_viewmodel2, VIEW_MODELCANNON)
set_pev( id, pev_weaponmodel2, PLAYER_MODELCANNON)
set_task(0.8, "draw", id)
}
nextshot[id] = get_gametime()
curweapon[id] = read_data(2)
}
public draw(id)
{
drawed[id] = true
}
public BuyCannon(id)
{
if(!hascannon[id])
{
if(cs_get_user_money(id) >= 800)
{
if(cs_get_user_hasprim(id))
{
StripWeapons(id, Primary)
}
fm_give_item(id, "weapon_p90")
cs_set_user_bpammo(id, CSW_P90, 100)
cs_set_weapon_ammo(find_ent_by_owner(-1, "weapon_p90", id), 50);
cs_set_user_money(id, cs_get_user_money(id) - 800, 1)
hascannon[id] = true
}
else
{
client_printcolor(id, "/g[WP SHOP] /yTu neturi pakankamai pinigu, reikalinga suma /g800$/y.")
}
}
else
{
client_printcolor(id, "/g[WP SHOP] /yTu Jau turi ginkla /gCannon/y.")
}
}
/* //////////////////////////////////////////////////////////
//////////////////////// STOCK /////////////////////////////
//////////////////////////////////////////////////////// */
stock fm_give_item(index, const item[]) {
if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
return 0;
new ent = fm_create_entity(item);
if (!pev_valid(ent))
return 0;
new Float:origin[3];
pev(index, pev_origin, origin);
set_pev(ent, pev_origin, origin);
set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN);
dllfunc(DLLFunc_Spawn, ent);
new save = pev(ent, pev_solid);
dllfunc(DLLFunc_Touch, ent, index);
if (pev(ent, pev_solid) != save)
return ent;
engfunc(EngFunc_RemoveEntity, ent);
return -1;
}
stock StripWeapons(id, Type, bool: bSwitchIfActive = true)
{
new iReturn;
if(is_user_alive(id))
{
new iEntity, iWeapon;
while((iWeapon = GetWeaponFromSlot(id, Type, iEntity)) > 0)
iReturn = ham_strip_user_weapon(id, iWeapon, Type, bSwitchIfActive);
}
return iReturn;
}
stock GetWeaponFromSlot( id , iSlot , &iEntity )
{
if ( !( 1 <= iSlot <= 5 ) )
return 0;
iEntity = 0;
const m_rgpPlayerItems_Slot0 = 367;
const m_iId = 43;
const XO_WEAPONS = 4;
const XO_PLAYER = 5;
iEntity = get_pdata_cbase( id , m_rgpPlayerItems_Slot0 + iSlot , XO_PLAYER );
return ( iEntity > 0 ) ? get_pdata_int( iEntity , m_iId , XO_WEAPONS ) : 0;
}
stock ham_strip_user_weapon(id, iCswId, iSlot = 0, bool:bSwitchIfActive = true)
{
new iWeapon
if( !iSlot )
{
static const iWeaponsSlots[] = {
-1,
2, //CSW_P228
-1,
1, //CSW_SCOUT
4, //CSW_HEGRENADE
1, //CSW_XM1014
5, //CSW_C4
1, //CSW_MAC10
1, //CSW_AUG
4, //CSW_SMOKEGRENADE
2, //CSW_ELITE
2, //CSW_FIVESEVEN
1, //CSW_UMP45
1, //CSW_SG550
1, //CSW_GALIL
1, //CSW_FAMAS
2, //CSW_USP
2, //CSW_GLOCK18
1, //CSW_AWP
1, //CSW_MP5NAVY
1, //CSW_M249
1, //CSW_M3
1, //CSW_M4A1
1, //CSW_TMP
1, //CSW_G3SG1
4, //CSW_FLASHBANG
2, //CSW_DEAGLE
1, //CSW_SG552
1, //CSW_AK47
3, //CSW_KNIFE
1 //CSW_P90
}
iSlot = iWeaponsSlots[iCswId]
}
const XTRA_OFS_PLAYER = 5
const m_rgpPlayerItems_Slot0 = 367
iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_Slot0 + iSlot, XTRA_OFS_PLAYER)
const XTRA_OFS_WEAPON = 4
const m_pNext = 42
const m_iId = 43
while( iWeapon > 0 )
{
if( get_pdata_int(iWeapon, m_iId, XTRA_OFS_WEAPON) == iCswId )
{
break
}
iWeapon = get_pdata_cbase(iWeapon, m_pNext, XTRA_OFS_WEAPON)
}
if( iWeapon > 0 )
{
const m_pActiveItem = 373
if( bSwitchIfActive && get_pdata_cbase(id, m_pActiveItem, XTRA_OFS_PLAYER) == iWeapon )
{
ExecuteHamB(Ham_Weapon_RetireWeapon, iWeapon)
}
if( ExecuteHamB(Ham_RemovePlayerItem, id, iWeapon) )
{
user_has_weapon(id, iCswId, 0)
ExecuteHamB(Ham_Item_Kill, iWeapon)
return 1
}
}
return 0
}
stock client_printcolor(const id, const input[], any:...)
{
new count = 1, players[32];
static msg[191];
vformat(msg,190,input,3);
replace_all(msg,190,"/g","^4");// green txt
replace_all(msg,190,"/y","^1");// orange txt
replace_all(msg,190,"/ctr","^3");// team txt
replace_all(msg,190,"/w","^0");// team txt
if (id) players[0] = id; else get_players(players,count,"ch");
for (new i=0;i<count;i++)
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}