View Single Post
Author Message
Hamartia
Member
Join Date: Oct 2015
Old 12-13-2015 , 23:36   Knife Kill Bonus
Reply With Quote #1

Knife Kill Bonus is a plugin which gives bonus frags, hp and plays a sound on knife kill.

The speed bonus is not getting activated unless I swap the weapon. With the current weapon as knife on kill, the max speed is not given for user. Once I swap a weapon I am able to notice the speed.

To get speed information I use https://forums.alliedmods.net/showthread.php?t=51298

I am able to understand that on event "onCurWeaponEvent" it applied the speed but why not before the weapon swap ?

Also am getting "Warning: Tag mismatch" in lines related to the float cvar amx_kkb_speed. Can someone give me a tip like whats causing this mismatch ? I guess this is related to some data type mismatch ? Generally how do you compare float values ?

Code below. Thank you!

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fun>
#include <colorchat> 

#define PLUGIN "Knife Kill Bonuses"
#define VERSION "1.0"
#define AUTHOR "Flicker"

const TASK_ID 6969;
const 
Float:DEFAULT_SPEED 250.0;

new 
Knife_Sound[7][] =
{
"sound/lovecs/knifekillbonus/baap.mp3",
"sound/lovecs/knifekillbonus/baburao.mp3",
"sound/lovecs/knifekillbonus/heybitch.mp3",
"sound/lovecs/knifekillbonus/ohfuck.mp3",
"sound/lovecs/knifekillbonus/2nife2.mp3",
"sound/lovecs/knifekillbonus/whosurdaddy.mp3",
"sound/lovecs/knifekillbonus/hurra.mp3"
};

new 
bool:g_bHasSpeed[33];

new 
amx_kkb_enableamx_kkb_hpamx_kkb_frag;

new 
Float:amx_kkb_speedFloat:amx_kkb_speed_time;

public 
plugin_init() 
{    
    
register_plugin(PLUGINVERSIONAUTHOR)        ;
    
    
amx_kkb_enable register_cvar ("amx_kkb_enable","1");
    
amx_kkb_speed register_cvar ("amx_kkb_speed","330.0");
    
amx_kkb_speed_time register_cvar ("amx_kkb_speed_time","10.0");
    
amx_kkb_hp register_cvar ("amx_kkb_hp","15");
    
amx_kkb_frag register_cvar ("amx_kkb_frag","2");
    
    
register_event("DeathMsg""onDeathMsgEvent""a");
    
register_event("CurWeapon""onCurWeaponEvent""be""1=1");
}

public 
plugin_precache(){    
    for( new 
sizeof Knife_Sound i++ ){
        
precache_genericKnife_Sound] );
    }
}

public 
onDeathMsgEvent()
{
    if(
get_pcvar_num(amx_kkb_enable)){
        
    new 
id read_data(1);
        
    new 
szWeapon[32];
    
read_data(4szWeaponcharsmax(szWeapon));
    
    if(
get_pcvar_num(amx_kkb_enable) && equal(szWeapon"knife") && is_user_alive(id))
    {
        new 
szName[32], szName2[32], randomNumber;
        
get_user_name(idszNamecharsmax(szName));
        
get_user_name(read_data(2), szName2charsmax(szName2));

        if(
get_pcvar_float(amx_kkb_speed) > DEFAULT_SPEED){
            
client_print_color(0print_chat"^4[KnifeKill] ^3%s ^1knifed ^3%s ^1& gained ^3%d ^1HP, ^3%d ^1Frags and ^3Speed"szNameszName2get_pcvar_num(amx_kkb_hp),get_pcvar_num(amx_kkb_frag));
        }else{
            
client_print_color(0print_chat"^4[KnifeKill] ^3%s ^1knifed ^3%s ^1& gained ^3%d ^1HP and ^3%d ^1Frags"szNameszName2get_pcvar_num(amx_kkb_hp),get_pcvar_num(amx_kkb_frag));
        }
                
        
randomNumber random_num(0,sizeof Knife_Sound 1);
        
client_cmd(0"mp3 play %s"Knife_Sound[randomNumber]);
        
        
set_user_health(idget_user_health(id) + get_pcvar_num(amx_kkb_hp));
        
        
set_user_frags(idget_user_frags(id) + get_pcvar_num(amx_kkb_frag));
        
        if (
get_pcvar_float(amx_kkb_speed) > DEFAULT_SPEED){
            
g_bHasSpeed[id] = true;
            
remove_task(id TASK_ID);
            
set_task(get_pcvar_float(amx_kkb_speed_time), "taskRemoveSpeed"id TASK_ID);
            
set_user_maxspeed(idget_pcvar_float(amx_kkb_speed));
        }
    }
    }

}

public 
onCurWeaponEvent(id){
    if(
get_pcvar_num(amx_kkb_enable) && (get_pcvar_float(amx_kkb_speed) > DEFAULT_SPEED) && g_bHasSpeed[id]){
        
set_user_maxspeed(idget_pcvar_float(amx_kkb_speed));
    }
}

public 
taskRemoveSpeed(id)
{
    new 
szName[32];
    
    
id -= TASK_ID;
    
g_bHasSpeed[id] = false;
    
set_user_maxspeed(idDEFAULT_SPEED);
    
    
get_user_name(idszNamecharsmax(szName));
    
client_print_color(0print_chat"^4[KnifeKill] ^1Bonus speed removed for ^3%s"szName);

    
}

public 
client_disconnect(id)
{
    if(
get_pcvar_num(amx_kkb_enable)){
        
remove_task(id TASK_ID);
    }

__________________
Hamartia is offline