AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Knife Kill Bonus (https://forums.alliedmods.net/showthread.php?t=276062)

Hamartia 12-13-2015 23:36

Knife Kill Bonus
 
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);
    }



tuty 12-14-2015 06:17

Re: Knife Kill Bonus
 
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 );
    }



Hamartia 12-16-2015 13:51

Re: Knife Kill Bonus
 
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 );
    }



prinoybullboy 12-28-2015 09:55

Re: Knife Kill Bonus
 
xD

asur 12-31-2015 03:52

Re: Knife Kill Bonus
 
Quote:

Originally Posted by Hamartia (Post 2372271)
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)

Hamartia 01-02-2016 05:51

Re: Knife Kill Bonus
 
Quote:

Originally Posted by asur (Post 2378357)
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.


All times are GMT -4. The time now is 14:03.

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