Raised This Month: $32 Target: $400
 8% 

Knife Kill Bonus


Post New Thread Reply   
 
Thread Tools Display Modes
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
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 12-14-2015 , 06:17   Re: Knife Kill Bonus
Reply With Quote #2

im at uni now. but a good way to update a client speed is using ham.
Check if user has a knife as current weapon then do your stuff

PHP Code:
new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame;

RegisterHamHam_Player_ResetMaxSpeed"player""bacon_ResetMaxSpeed");

public 
bacon_ResetMaxSpeedid )
{
    if( 
is_user_aliveid ) )
    {
        
        new 
Float:flMaxSpeed your speed;
        
        
engfuncEngFunc_SetClientMaxspeedidflMaxSpeed );
        
set_pevidpev_maxspeedflMaxSpeed );
    }

__________________

Last edited by tuty; 12-14-2015 at 06:18.
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Old 12-16-2015, 13:09
Hamartia
This message has been deleted by Hamartia.
Hamartia
Member
Join Date: Oct 2015
Old 12-16-2015 , 13:51   Re: Knife Kill Bonus
Reply With Quote #3

Will this affect the performance since this is going to be called on prethink or am i exaggerating it ?

Am planning to use it the same way as you have mentioned, just added an array check to see if user has speed. (this array will have the user id only if he has killed some one with knife)

PHP Code:
new Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame;

RegisterHamHam_Player_ResetMaxSpeed"player""bacon_ResetMaxSpeed");

public 
bacon_ResetMaxSpeedid )
{
    if( 
is_user_aliveid ) && g_bHasSpeed[id])
    {
        
        new 
Float:flMaxSpeed your speed;
        
        
engfuncEngFunc_SetClientMaxspeedidflMaxSpeed );
        
set_pevidpev_maxspeedflMaxSpeed );
    }

__________________
Hamartia is offline
prinoybullboy
Member
Join Date: Aug 2014
Old 12-28-2015 , 09:55   Re: Knife Kill Bonus
Reply With Quote #4

xD
prinoybullboy is offline
asur
Member
Join Date: Dec 2014
Old 12-31-2015 , 03:52   Re: Knife Kill Bonus
Reply With Quote #5

Quote:
Originally Posted by Hamartia View Post
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);
    }


Just change :
PHP Code:
new Float:amx_kkb_speedFloat:amx_kkb_speed_time
to
PHP Code:
new amx_kkb_speedamx_kkb_speed_time
No errors nd whole plugin will work as usual (no weapon switch prblm)
asur is offline
Hamartia
Member
Join Date: Oct 2015
Old 01-02-2016 , 05:51   Re: Knife Kill Bonus
Reply With Quote #6

Quote:
Originally Posted by asur View Post
Just change :
PHP Code:
new Float:amx_kkb_speedFloat:amx_kkb_speed_time
to
PHP Code:
new amx_kkb_speedamx_kkb_speed_time
No errors nd whole plugin will work as usual (no weapon switch prblm)
Hey, thank you ! All seems to be working fine. Thank you for taking time to read my full question and for the solution. I added float so that it will be treated as a float but now i realize that they are just the variables for storing the pointer values and hence the mismatch.
__________________
Hamartia 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 12:42.


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