Raised This Month: $ Target: $400
 0% 

weapon fire speed [Solved]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 04-25-2012 , 17:00   weapon fire speed [Solved]
Reply With Quote #1

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(PLUGINVERSIONAUTHOR)
    
    
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(iduc_handleseed)
{
    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) > && nextshot[id] <= gtime)
        {
            
//MakeShot(id)
            
client_print(idprint_chat"sove")
            
nextshot[id] = gtime 0.2
            cs_set_weapon_ammo
(wepcs_get_weapon_ammo(wep)-1)
            
            
message_begin(MSG_ONESVC_WEAPONANIM_id)
            
write_byte(3//Animation id
            
write_byte(pev(id,pev_body))
            
message_end()
            
        }
    }
    
    }
  
    return 
FMRES_HANDLED
}


public 
UpdateClientData_Postidsendweaponscd_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_handleCD_flNextAttackhalflife_time() + 0.001 );      
    
    
//And finally return...
    
    
return FMRES_HANDLED;
}

public 
Event_CurWeaponid )  
{
    
drawed[id] = false
    
    
if(task_exists(id))
    
remove_task(id)
    
    if(
read_data(2) == CSW_P90 && hascannon[id])
    {
        
set_pevidpev_viewmodel2VIEW_MODELCANNON)  
        
set_pevidpev_weaponmodel2PLAYER_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(idPrimary)
            }
            
            
fm_give_item(id"weapon_p90")
            
cs_set_user_bpammo(idCSW_P90100)
            
cs_set_weapon_ammo(find_ent_by_owner(-1"weapon_p90"id), 50);
        
            
cs_set_user_money(idcs_get_user_money(id) - 8001)
        
            
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(indexpev_originorigin);
    
set_pev(entpev_originorigin);
    
set_pev(entpev_spawnflagspev(entpev_spawnflags) | SF_NORESPAWN);
    
dllfunc(DLLFunc_Spawnent);

    new 
save pev(entpev_solid);
    
dllfunc(DLLFunc_Touchentindex);
    if (
pev(entpev_solid) != save)
        return 
ent;

    
engfunc(EngFunc_RemoveEntityent);

    return -
1;
}

stock StripWeapons(idTypeboolbSwitchIfActive true)
{
    new 
iReturn;
    
    if(
is_user_alive(id))
    {
        new 
iEntityiWeapon;
        while((
iWeapon GetWeaponFromSlot(idTypeiEntity)) > 0)
            
iReturn ham_strip_user_weapon(idiWeaponTypebSwitchIfActive);
    }
    
    return 
iReturn;
}
    
        
stock GetWeaponFromSlotid iSlot , &iEntity )
{
    if ( !( 
<= iSlot <= ) )
        return 
0;
    
    
iEntity 0;
    const 
m_rgpPlayerItems_Slot0 367;
    const 
m_iId 43;
    const 
XO_WEAPONS 4;
    const 
XO_PLAYER 5;
        
    
iEntity get_pdata_cbaseid m_rgpPlayerItems_Slot0 iSlot XO_PLAYER );
    
    return ( 
iEntity ) ? get_pdata_intiEntity m_iId XO_WEAPONS ) : 0;
}  


stock ham_strip_user_weapon(idiCswIdiSlot 0bool: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
            
//CSW_P90
        
}
        
iSlot iWeaponsSlots[iCswId]
    }

    const 
XTRA_OFS_PLAYER 5
    
const m_rgpPlayerItems_Slot0 367

    iWeapon 
get_pdata_cbase(idm_rgpPlayerItems_Slot0 iSlotXTRA_OFS_PLAYER)

    const 
XTRA_OFS_WEAPON 4
    
const m_pNext 42
    
const m_iId 43

    
while( iWeapon )
    {
        if( 
get_pdata_int(iWeaponm_iIdXTRA_OFS_WEAPON) == iCswId )
        {
            break
        }
        
iWeapon get_pdata_cbase(iWeaponm_pNextXTRA_OFS_WEAPON)
    }

    if( 
iWeapon )
    {
        const 
m_pActiveItem 373
        
if( bSwitchIfActive && get_pdata_cbase(idm_pActiveItemXTRA_OFS_PLAYER) == iWeapon )
        {
            
ExecuteHamB(Ham_Weapon_RetireWeaponiWeapon)
        }

        if( 
ExecuteHamB(Ham_RemovePlayerItemidiWeapon) )
        {
            
user_has_weapon(idiCswId0)
            
ExecuteHamB(Ham_Item_KilliWeapon)
            return 
1
        
}
    }

    return 
0


stock client_printcolor(const id, const input[], any:...)
{
    new 
count 1players[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 (idplayers[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_UNRELIABLEget_user_msgid("SayText"), _players[i]);
            
write_byte(players[i]);
            
write_string(msg);
            
message_end();
        }


Last edited by usaexelent; 04-27-2012 at 07:04.
usaexelent is offline
Send a message via Skype™ to usaexelent
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 04-25-2012 , 17:10   Re: weapon fire speed
Reply With Quote #2

use Ham_Weapon_PrimaryAttack in post

example


PHP Code:
//plugin_init
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_awp""fw_Awp_PrimaryAttack_Post"1)


/*******************/

public fw_Awp_PrimaryAttack_Post(ent)
{
    static 
id 

    id 
get_pdata_cbase(ent414)

    if(!
is_user_alive(id))
        return 
HAM_IGNORED
    
    
static Float:fRate
    fRate 
1.4
    
    set_pdata_float
(ent46fRate4)
    
set_pdata_float(ent47fRate4)
    
set_pdata_float(ent48fRate4)
    
    return 
HAM_IGNORED

__________________

www.amxmodx-es.com

Steam: Luchokoldo

Last edited by rak; 04-25-2012 at 17:14.
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 04-26-2012 , 07:10   Re: weapon fire speed
Reply With Quote #3

This weapon firing is blocked... I am making my own custom gun, and the rate is the time in wich some one can shoot again of my custom fire.
usaexelent is offline
Send a message via Skype™ to usaexelent
usaexelent
Senior Member
Join Date: Nov 2009
Location: Lithuania
Old 04-27-2012 , 07:05   Re: weapon fire speed [Solved]
Reply With Quote #4

Problem solved, the problem was that every time I shoot cur weapon event is called. That's strange but fixed everything.
usaexelent is offline
Send a message via Skype™ to usaexelent
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-27-2012 , 11:27   Re: weapon fire speed [Solved]
Reply With Quote #5

Quote:
Originally Posted by usaexelent View Post
Problem solved, the problem was that every time I shoot cur weapon event is called. That's strange but fixed everything.
Strange, or obvious?

http://wiki.amxmodx.org/Half-Life_1_...ents#CurWeapon
Quote:
Updates the clip ammo number and weapon's corresponding ammo type icon on the HUD.
In order for that to happen, it would have to be called every shot.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode