AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   [TTT] Give karma (https://forums.alliedmods.net/showthread.php?t=340947)

JuanitoAlimana 12-19-2022 17:42

[TTT] Give karma
 
Is there a way so players with the ADMIN_CFG flag get 100 extra karma points if they type /karma? Also, it would be awesome if they could only use it once every 10 minutes. Thanks!

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <cs_teams_api>
#include <timer_controller>
#include <ttt>

#define TASK_SURVIVAL            1111
#define TASK_ORPHEU                2222
#define m_bitsDamageType        76
#define m_flPainShock            108
#define OFFSET_LINUX_WEAPONS    4
#define OFFSET_LINUX_PLAYERS    5

enum
{
    
KARMA_KILL,
    
KARMA_DMG
}

new const 
g_szGameModes[GAME_MODE][] =
{
    
"unset",
    
"off",
    
"preparing",
    
"restarting",
    
"started",
    
"ended"
};

const 
DMG_SOMETHING DMG_GENERIC DMG_SLASH DMG_BURN 
    
DMG_FREEZE DMG_FALL DMG_BLAST DMG_SHOCK DMG_DROWN 
    
DMG_NERVEGAS DMG_POISON DMG_RADIATION DMG_ACID;
    
// RESETABLE
new g_iGlobalInfo[GLOBAL_INFO], g_iSpecialCount[PLAYER_CLASS], g_iRoundSpecial[PLAYER_CLASS];
new 
g_iPlayerData[33][PLAYER_DATA];
new 
g_iMultiCount 1g_iMultiSeconds 1;
new 
Trie:g_tCvarsToFileg_iTrieSize;
//
// NON RESETABLE
new cvar_traitorscvar_detectivescvar_karma_damage,
    
cvar_preparation_timecvar_karma_multicvar_karma_start,
    
cvar_credits_tra_startcvar_credits_tra_countcvar_credits_tra_detkillcvar_credits_tra_countkill,
    
cvar_credits_det_startcvar_credits_tra_repeatcvar_damage_modifier,
    
cvar_credits_det_bonussurvcvar_credits_det_survtimecvar_show_deathmessagecvar_detective_glow;
new 
g_pMsgTeamInfog_pMsgScreenFadeg_iGameModeForwardg_iPluginCfgForward;
new 
Float:g_fFreezeTimeFloat:g_fRoundTimeFloat:g_fRoundStart;
new 
g_iMaxDetectivesg_iMaxTraitorsg_iMaxPlayers;
new 
g_iExceptionItems[10] = {-2, -2, ...};
//

public plugin_init()
{
    
register_plugin("[TTT] Core"TTT_VERSIONTTT_AUTHOR);
    
register_cvar("ttt_server_version"TTT_VERSIONFCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);

    
cvar_traitors                mynew_register_cvar("ttt_traitors",                "4",    "One Traitor on X players. (Default: 4)");
    
cvar_detectives                mynew_register_cvar("ttt_detectives",                "6",    "One Detective on X players. (Default: 6)");
    
cvar_preparation_time        mynew_register_cvar("ttt_preparation_time",        "10",    "Preparation time before game start. (Default: 10)");
    
cvar_credits_tra_start        mynew_register_cvar("ttt_credits_tra_start",        "2",    "Number of credits Traitor has when starting game. (Default: 2)");
    
cvar_credits_tra_count        mynew_register_cvar("ttt_credits_tra_count",        "0.25",    "Percentage of players to kill to get extra credits. (Default: 0.25)");
    
cvar_credits_tra_repeat        mynew_register_cvar("ttt_credits_tra_repeat",        "1",    "Repeat percentage kills till all are killed. (Default: 1)");
    
cvar_credits_tra_detkill    mynew_register_cvar("ttt_credits_tra_detkill",    "1",    "Number of credits for killing a Detective. (Default: 1)");
    
cvar_credits_tra_countkill    mynew_register_cvar("ttt_credits_tra_countkill",    "1",    "Number of credits to give for percentage kills. (Default: 1)");
    
cvar_credits_det_start        mynew_register_cvar("ttt_credits_det_start",        "1",    "Number of credits Detective has when starting game. (Default: 1)");
    
cvar_credits_det_bonussurv    mynew_register_cvar("ttt_credits_det_bonussurv",    "1",    "Number of credits to give for surviving time. (Default: 1)");
    
cvar_credits_det_survtime    mynew_register_cvar("ttt_credits_det_survtime",    "45.0",    "Every X seconds give credits. (Default: 45.0)");
    
cvar_karma_damage            mynew_register_cvar("ttt_karma_damage",            "0.25",    "Karma modifier dealing damage. (Default: 0.25)");
    
cvar_karma_multi            mynew_register_cvar("ttt_karma_multi",            "50",    "Karma modifier for killing. (Default: 50)");
    
cvar_karma_start            mynew_register_cvar("ttt_karma_start",            "500",    "Starting karma. (Default: 500)");
    
cvar_show_deathmessage        mynew_register_cvar("ttt_show_deathmessage",        "abeg",    "Show deathmessages to: a=NONE, b=TRAITOR, c=DETECTIVE, d=INNOCENT, e=DEAD, f=SPECIAL, g=victim, h=killer. (Default: abeg)");
    
cvar_damage_modifier        mynew_register_cvar("ttt_damage_modifier",        "1.0",    "Modifies karma based damage. (Default: 1.0)");
    
cvar_detective_glow            mynew_register_cvar("ttt_detective_glow",            "1",    "Should detective also be glowing? (Default: 1)");

    
g_pMsgScreenFade    get_user_msgid("ScreenFade");
    
g_pMsgTeamInfo        get_user_msgid("TeamInfo");

    
register_event("TextMsg""Event_RoundRestart""a""2&#Game_C""2&#Game_w");
    
register_event("HLTV""Event_HLTV""a""1=0""2=0");
    
register_event("DeathMsg""Event_DeathMsg""a");
    
register_logevent("Event_EndPreptime"2"1=Round_Start");
    
register_logevent("Event_EndRound"2"1=Round_End");

    
register_forward(FM_AddToFullPack"Forward_AddToFullPack_post"1);

    
RegisterHamPlayer(Ham_Killed"Ham_Killed_pre"0);
    
RegisterHamPlayer(Ham_Killed"Ham_Killed_post"1);
    
RegisterHamPlayer(Ham_TakeDamage"Ham_TakeDamage_pre"0);
    
RegisterHamPlayer(Ham_TakeDamage"Ham_TakeDamage_post"1);
    
RegisterHamPlayer(Ham_TraceAttack"Ham_TraceAttack_pre"0);

    
g_iGameModeForward CreateMultiForward("ttt_gamemode"ET_IGNOREFP_CELL);
    
g_iPluginCfgForward CreateMultiForward("ttt_plugin_cfg"ET_IGNORE);

    
g_iMaxPlayers get_maxplayers();
    
#if AMXX_VERSION_NUM < 183
    
register_dictionary("ttt_c.txt");
    
register_dictionary("ttt_addons_c.txt");
    
#else
    
register_dictionary("ttt.txt");
    
register_dictionary("ttt_addons.txt");
    
#endif
}

public 
plugin_end()
    
set_game_state(GAME_PREPARING);

public 
plugin_natives()
{
    
register_library("ttt");
    
register_native("ttt_get_roundtime",    "_get_roundtime");
    
register_native("ttt_get_playerdata",    "_get_playerdata");
    
register_native("ttt_set_playerdata",    "_set_playerdata");
    
register_native("ttt_get_globalinfo",    "_get_globalinfo");
    
register_native("ttt_set_globalinfo",    "_set_globalinfo");
    
register_native("ttt_set_playerstate",    "_set_playerstate");
    
register_native("ttt_set_gamemode",        "_set_gamemode");
    
register_native("ttt_get_specialcount",    "_get_specialcount");
    
register_native("ttt_register_cvar",    "_register_cvar");
    
register_native("ttt_add_exception",    "_add_exception");
    
register_native("ttt_find_exception",    "_find_exception");
}

public 
plugin_cfg()
{
    
auto_exec_config(TTT_CONFIGFILE);
    
g_fRoundTime get_pcvar_float(get_cvar_pointer("mp_roundtime"));
    
TrieDestroy(g_tCvarsToFile);

    new 
ret;
    
ExecuteForward(g_iPluginCfgForwardret);
}

public 
client_disconnect(id)
{
    
set_task(0.5"reset_client"id);
    
set_special_state(idPC_NONE);
}

public 
client_putinserver(id)
{
    
// if(is_user_bot(id))
    //     server_cmd("kick #%i %s", get_user_userid(id), "Bot player!");

    
reset_client(id);
    
g_iPlayerData[id][PD_KILLEDBY] = -1;
    
set_task(11.0"startup_info"id);

    new 
karma get_pcvar_num(cvar_karma_start);
    
g_iPlayerData[id][PD_KARMATEMP] = karma;
    
g_iPlayerData[id][PD_KARMA] = karma;
}

public 
startup_info(id)
{
    if(
get_game_state() == GAME_STARTED && !is_user_alive(id))
    {
        
set_special_state(idPC_DEAD);
        
Show_All();
    }

    
// Please don't remove this :)
    
client_print_color(idprint_team_default"%s Mod created by ^3%s^1, ^4skype:guskis1^1, version: ^3%s^1!"TTT_TAGTTT_AUTHORTTT_VERSION);
}

public 
Event_RoundRestart()
{
    if(
get_game_state() != GAME_RESTARTING)
    {
        
reset_all();
        
set_game_state(GAME_RESTARTING);
    }
}

public 
Event_HLTV()
{
    if(
get_game_state() != GAME_PREPARING)
    {
        new 
cvar get_pcvar_num(cvar_preparation_time);
        if(!
cvar)
            
set_pcvar_num(cvar_preparation_timecvar 1);
        
g_fFreezeTime float(cvar);
        
set_task(0.1"set_timer");

        
g_fRoundTime get_pcvar_float(get_cvar_pointer("mp_roundtime"));
        
g_fRoundStart get_gametime();
        
reset_all();

        
set_game_state(GAME_PREPARING);
    }
}

public 
set_timer()
    
RoundTimerSet(0get_pcvar_num(cvar_preparation_time));

public 
Event_EndRound()
{
    if(
get_game_state() != GAME_ENDED)
    {
        
reset_all();
        
set_game_state(GAME_ENDED);
    }
}

public 
Event_EndPreptime()
{
    if(
task_exists(TASK_ORPHEU))
        
remove_task(TASK_ORPHEU);
    
set_task(float(get_pcvar_num(cvar_preparation_time)), "do_the_magic"TASK_ORPHEU);
}

public 
do_the_magic()
{
    
RoundTimerSet(floatround(g_fRoundTime));

    new 
num;
    static 
players[32];
    
get_players(playersnum);
    
ttt_log_to_file(LOG_DEFAULT"Current player count %d"num);

    if(
num 3)
    {
        
set_game_state(GAME_OFF);
        
client_print_color(0print_team_default"%s %L"TTT_TAGLANG_PLAYER"TTT_MODOFF1");
        return;
    }

    new 
trai get_pcvar_num(cvar_traitors), dete get_pcvar_num(cvar_detectives);
    
g_iMaxTraitors = (num/trai);
    if(!
g_iMaxTraitors)
        
g_iMaxTraitors 1;

    
g_iMaxDetectives = (num/dete);
    if(
g_iMaxTraitors+g_iMaxDetectives>num)
    {
        
set_pcvar_num(cvar_detectives8);
        
set_pcvar_num(cvar_traitors4);
        
g_iMaxTraitors = (num/trai);

        if(!
g_iMaxTraitors)
            
g_iMaxTraitors 1;
    
        
g_iMaxDetectives = (num/dete);
        
client_print_color(0print_team_default"%s %L"TTT_TAGLANG_PLAYER"TTT_MODOFF2");
    }
    while(
specials_needed() != 0)
        
pick_specials();

    new 
id;
    for(--
numnum >= 0num--)
    {
        
id players[num];
        if(!
is_user_alive(id)) continue;
        
g_iPlayerData[id][PD_KARMA] = g_iPlayerData[id][PD_KARMATEMP];

        if(
get_special_state(id) != PC_DETECTIVE && get_special_state(id) != PC_TRAITOR)
        {
            
screen_fade(idPC_INNOCENT);
            
set_special_state(idPC_INNOCENT);
            
cs_set_player_team(idCS_TEAM_CTfalse);
        }

        
entity_set_float(idEV_FL_fragsfloat(g_iPlayerData[id][PD_KARMA]));
        
cs_set_user_deaths(idg_iPlayerData[id][PD_KILLEDDEATHS]);
    }

    new 
i;
    for(
0PLAYER_CLASSi++)
        
g_iRoundSpecial[i] = get_special_count(i);

    
set_task(get_pcvar_float(cvar_credits_det_survtime), "give_survival_credits"TASK_SURVIVAL__"b");
    
    
get_players(playersnum);
    for(--
numnum >= 0num--)
    {
        
id players[num];
        
set_fake_team(idget_special_state(id));
    }

    
set_game_state(GAME_STARTED);
}

public 
Event_DeathMsg()
{
    new 
killer read_data(1); 
    new 
victim read_data(2);
    static 
weapon[16];
    
read_data(4weaponcharsmax(weapon));

    if(
is_user_connected(killer))
    {
        static 
newweap[32];
        
g_iPlayerData[victim][PD_KILLEDBY] = killer;
        
g_iPlayerData[killer][PD_KILLCOUNT]++;
        
formatex(newweapcharsmax(newweap), "weapon_%s"weapon);
        
g_iPlayerData[victim][PD_KILLEDWEAP] = get_weaponid(newweap);
    }

    static 
cvar[10];
    
get_pcvar_string(cvar_show_deathmessagecvarcharsmax(cvar));
    if(
cvar[0])
        
ttt_make_deathmsg(killervictimread_data(3), weaponread_flags(cvar));

    if(
equali(weapon"worldspawn"))
        
g_iPlayerData[victim][PD_KILLEDWEAP] = DEATHS_SUICIDE;
}

public 
Ham_Killed_pre(victimkillershouldgib)
{
    if(
my_return_check(victim))
        return 
HAM_IGNORED;

    if(
get_pdata_int(victimm_bitsDamageType) & DMG_SOMETHING)
        
add_death_info(victimkillerget_pdata_int(victimm_bitsDamageType5));

    
g_iPlayerData[victim][PD_KILLEDSTATE] = get_special_state(victim);
    
g_iPlayerData[victim][PD_KILLEDTIME] = floatround(floatmul(g_fRoundTime60.0) - get_round_time());
    
g_iPlayerData[victim][PD_KILLEDDEATHS]++;

    
set_special_state(victimPC_DEAD);
    return 
HAM_HANDLED;
}

public 
add_death_info(victimkillerdmg)
{
    new 
msg get_deathmessage(0dmg);
    if(
is_user_connected(killer))
    {
        
g_iPlayerData[victim][PD_KILLEDBY] = killer;
        
g_iPlayerData[killer][PD_KILLCOUNT]++;
    }
    else 
g_iPlayerData[victim][PD_KILLEDBY] = msg;

    
g_iPlayerData[victim][PD_KILLEDWEAP] = msg;
}

public 
get_deathmessage(iddmg)
{
    if(!
id)
    {
        if(
dmg DMG_GENERIC)
            
dmg DEATHS_GENERIC;
        else if(
dmg DMG_SLASH)
            
dmg DEATHS_SLASH;
        else if(
dmg DMG_BURN)
            
dmg DEATHS_BURN;
        else if(
dmg DMG_FREEZE)
            
dmg DEATHS_FREEZE;
        else if(
dmg DMG_FALL)
            
dmg DEATHS_FALL;
        else if(
dmg DMG_BLAST)
            
dmg DEATHS_BLAST;
        else if(
dmg DMG_SHOCK)
            
dmg DEATHS_SHOCK;
        else if(
dmg DMG_DROWN)
            
dmg DEATHS_DROWN;
        else if(
dmg DMG_NERVEGAS)
            
dmg DEATHS_NERVEGAS;
        else if(
dmg DMG_POISON)
            
dmg DEATHS_POISON;
        else if(
dmg DMG_RADIATION)
            
dmg DEATHS_RADIATION;
        else if(
dmg DMG_ACID)
            
dmg DEATHS_ACID;
        else 
dmg DEATHS_SUICIDE;
    }
    else 
dmg g_iPlayerData[id][PD_KILLEDWEAP];

    return 
dmg;
}

public 
Ham_Killed_post(victimkillershouldgib)
{
    if(
my_return_check(victim))
        return;

    if(!
is_user_connected(killer))
    {
        
killer find_valid_killer(victimkiller);
    }

    new 
bonus;
    static 
players[32], name[32];
    if(
float(get_special_count(PC_DEAD)+get_special_count(PC_TRAITOR)-g_iRoundSpecial[PC_TRAITOR])/float(g_iRoundSpecial[PC_INNOCENT]+g_iRoundSpecial[PC_DETECTIVE])
    > 
get_pcvar_float(cvar_credits_tra_count) * g_iMultiCount)
    {
        new 
numi;
        
bonus get_pcvar_num(cvar_credits_tra_countkill);
        
get_players(playersnum"a");
        for(--
numnum >= 0num--)
        {
            
players[num];

            if(
get_special_state(i) == PC_TRAITOR)
            {
                
g_iPlayerData[i][PD_CREDITS] += bonus;
                
client_print_color(iprint_team_default"%s %L"TTT_TAGi"TTT_AWARD1"bonusfloatround(get_pcvar_float(cvar_credits_tra_count)* g_iMultiCount*100), ispecial_names[PC_INNOCENT]);
            }
        }

        if(
get_pcvar_num(cvar_credits_tra_repeat))
            
g_iMultiCount++;
        else 
g_iMultiCount 100;
    }

    if(
is_user_connected(killer))
    {
        new 
killer_state get_special_alive(killer), victim_state get_special_alive(victim);
        if(
killer_state == PC_TRAITOR && victim_state == PC_DETECTIVE)
        {
            
bonus get_pcvar_num(cvar_credits_tra_detkill);
            
g_iPlayerData[killer][PD_CREDITS] += bonus;
            
get_user_name(victimnamecharsmax(name));
            
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_AWARD2"bonuskillerspecial_names[PC_DETECTIVE], name);
        }

        if(
killer != victim)
        {
            
get_user_name(victimnamecharsmax(name));
            if(
killer_state == PC_INNOCENT || killer_state == PC_DETECTIVE)
                
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_KILLED2"name);
            else if(
killer_state == PC_TRAITOR || victim_state == PC_TRAITOR)
                
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_KILLED3"namekillerspecial_names[victim_state]);

            
get_user_name(killernamecharsmax(name));
            
client_print_color(victimprint_team_default"%s %L"TTT_TAGvictim"TTT_KILLED1"namevictimspecial_names[killer_state]);
        }
    }

    new 
killed_item killed_with_item(victim);
    if(
killed_item)
    {
        if(
is_user_connected(killer))
        {
            if(
victim != killer && get_special_alive(killer) != get_special_alive(victim))
                
karma_modifier(killervictimKARMA_KILL);
        }
    }
    else 
karma_modifier(killervictimKARMA_KILL);

    if(!
killed_item && (!is_user_connected(killer) || killer == victim))
        
client_print_color(victimprint_team_default"%s %L"TTT_TAGvictim"TTT_SUICIDE");

    
set_task(0.1"Show_All");
}

public 
find_valid_killer(victimkiller)
{
    new 
new_killer get_player_data(victimPD_KILLEDBY);
    return 
new_killer new_killer killer;
}

public 
killed_with_item(victim)
{
    new 
item get_player_data(victimPD_KILLEDBYITEM);
    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == item)
            return 
1;
    }

    return 
0;
}

public 
Show_All()
{
    if(
get_game_state() == GAME_STARTED)
    {
        new 
numispecstate;
        static 
players[32];
        
get_players(playersnum);
        for(--
numnum >= 0num--)
        {
            
players[num];

            
specstate get_special_state(i);
            if(
specstate == PC_DEAD || specstate == PC_NONE)
            {
                
set_attrib_special(i1PC_TRAITORPC_NONEPC_DEAD);
                if(!
g_iPlayerData[i][PD_SCOREBOARD])
                    
set_attrib_special(i0PC_INNOCENTPC_DETECTIVE);
            }
        }
    }
}

public 
Ham_TakeDamage_pre(victiminflictorattackerFloat:damagebits)
{
    if(!
my_return_check(attacker))
    {
        new 
Float:modifier g_iPlayerData[attacker][PD_KARMA]/1000.0;
        if(
modifier 0.05 && damage 0.1)
        {
            
damage *= (modifier*get_pcvar_float(cvar_damage_modifier));
            if(
cs_get_user_team(attacker) != cs_get_user_team(victim))
                
damage *= 0.35;

            if(
damage 1.0)
                
damage 1.0;
        }
        else 
damage 0.0;

        
SetHamParamFloat(4damage);
        return 
HAM_HANDLED;
    }

    return 
HAM_IGNORED;
}

public 
Ham_TakeDamage_post(victiminflictorattackerFloat:damagebits)
{
    if(!
my_return_check(attacker))
    {
        if(
damage 0.1)
        {
            if(
victim != attacker)
                
karma_modifier(attackervictimKARMA_DMG);
        }
        else 
set_pdata_float(victimm_flPainShock1.0OFFSET_LINUX_PLAYERS);
    }
}

public 
Ham_TraceAttack_pre()
{
    if(
get_game_state() != GAME_STARTED && get_game_state() != GAME_OFF)
        return 
HAM_SUPERCEDE;

    return 
HAM_IGNORED;
}

public 
Forward_AddToFullPack_post(es_handleeenthosthostflagsidpSet)
{
    if(
id && host != ent && is_user_connected(host) && is_user_connected(ent) && get_orig_retval())
    {
        static 
cvar;
        if(!
cvar)
            
cvar get_pcvar_num(cvar_detective_glow);

        new 
entTeam get_special_alive(ent);
        if(
entTeam != PC_INNOCENT)
        {
            new 
hostTeam get_special_alive(host);
            new 
fakeTeam get_player_data(entPD_FAKESTATE);
            if(
fakeTeam && hostTeam != entTeam)
                
entTeam fakeTeam;
            if(
hostTeam == PC_TRAITOR || ((hostTeam == PC_DETECTIVE || hostTeam == PC_INNOCENT) && entTeam != PC_TRAITOR && cvar))
            {
                
set_es(es_handleES_RenderFxkRenderFxGlowShell);
                
set_es(es_handleES_RenderColorg_iTeamColors[entTeam]);
                
set_es(es_handleES_RenderAmt35);
            }
        }
    }
}

public 
pick_specials()
{
    new 
idnum;
    static 
players[32];
    static 
name[32];

    
get_players(playersnum);

    while(
id == 0)
    {
        
id players[random(num)];
        if(
get_special_state(id) == PC_TRAITOR || get_special_state(id) == PC_DETECTIVE)
            
id 0;
    }

    new 
randomNum specials_needed();
    
get_user_name(idnamecharsmax(name));
    switch(
randomNum)
    {
        case 
PC_TRAITOR:
        {
            
g_iPlayerData[id][PD_CREDITS] = get_pcvar_num(cvar_credits_tra_start);
            
set_special_state(idrandomNum);

            
screen_fade(idrandomNum);
            
ttt_log_to_file(LOG_DEFAULT"[%L] %s choosen (ID:%d)"idspecial_names[randomNum], nameid);
            
cs_set_player_team(idCS_TEAM_Tfalse);
        }
        case 
PC_DETECTIVE:
        {
            if(
num >= get_pcvar_num(cvar_detectives))
            {
                
g_iPlayerData[id][PD_CREDITS] = get_pcvar_num(cvar_credits_det_start);
                
set_special_state(idrandomNum);

                
screen_fade(idrandomNum);
                
ttt_log_to_file(LOG_DEFAULT"[%L] %s choosen (ID:%d)"idspecial_names[randomNum], nameid);
                
cs_set_player_team(idCS_TEAM_CTfalse);
            }
        }
        case 
PC_NONE: return;
    }
}

stock screen_fade(idplayer_state)
{
    
message_begin(MSG_ONE_UNRELIABLEg_pMsgScreenFade_id);
    
write_short(FixedUnsigned16(1.01<<12));
    
write_short(0);
    
write_short((SF_FADE_MODULATE)); //flags (SF_FADE_IN + SF_FADE_ONLYONE) (SF_FADEOUT)
    
write_byte(g_iTeamColors[player_state][0]);
    
write_byte(g_iTeamColors[player_state][1]);
    
write_byte(g_iTeamColors[player_state][2]);
    
write_byte(180);
    
message_end();
}

stock my_return_check(id)
{
    new 
game get_game_state();
    if(!
is_user_connected(id) || game == GAME_OFF || game == GAME_ENDED)
        return 
1;

    return 
0;
}

public 
specials_needed()
{
    if(
g_iMaxTraitors get_special_count(PC_TRAITOR))
        return 
PC_TRAITOR;
    else if(
g_iMaxDetectives get_special_count(PC_DETECTIVE))
        return 
PC_DETECTIVE;

    return 
PC_NONE;
}

public 
give_survival_credits()
{
    static 
players[32];
    new 
numidbonus get_pcvar_num(cvar_credits_det_bonussurv);
    
get_players(playersnum"a");
    for(--
numnum >= 0num--)
    {
        
id players[num];
        if(
get_special_state(id) == PC_DETECTIVE)
        {
            
g_iPlayerData[id][PD_CREDITS] += bonus;
            
client_print_color(idprint_team_default"%s %L"TTT_TAGid"TTT_AWARD4"bonusfloatround(get_pcvar_float(cvar_credits_det_survtime))*g_iMultiSeconds);
            
g_iMultiSeconds++;
        }
    }
}

public 
reset_all()
{
    static 
players[32];
    new 
numidi;
    
get_players(playersnum);
    for(--
numnum >= 0num--)
    {
        
id players[num];

        
set_special_state(idPC_NONE);
        for(
0PLAYER_DATAi++)
        {
            if(
== PD_KARMA || == PD_KARMATEMP || == PD_KILLEDDEATHS) continue;
            if(
== PD_KILLEDBY || == PD_KILLEDBYITEM)
                
g_iPlayerData[id][i] = -1;
            else 
g_iPlayerData[id][i] = 0;
        }
        if(
task_exists(id))
            
remove_task(id);
        
set_attrib_all(id0);
    }

    for(
0PLAYER_CLASSi++)
        
g_iSpecialCount[i] = 0;
    
//if(get_game_state() == GAME_ENDED || get_game_state() == GAME_RESTARTING)
    //    set_game_state(GAME_OFF);

    
g_iMultiSeconds 1;
    
g_iMultiCount 1;

    if(
task_exists(TASK_SURVIVAL))
        
remove_task(TASK_SURVIVAL);
}

public 
reset_client(id)
{
    for(new 
0PLAYER_DATAi++)
    {
        if(
== PD_KILLEDBY || == PD_KILLEDBYITEM)
            
g_iPlayerData[id][i] = -1;
        else 
g_iPlayerData[id][i] = 0;
    }

    
set_special_state(idPC_NONE);
    
set_attrib_all(id0);
}

public 
karma_modifier(attackervictimtype)
{
    if(
attacker == 0)
        
attacker victim;

    if(!
is_user_connected(attacker) || !is_user_connected(victim) || get_game_state() == GAME_OFF)
        return;

    static 
players[32];
    new 
numkarmamultimodifier;
    
get_players(playersnum);
    if(
type == KARMA_KILL)
    {
        
karmamulti floatround(get_pcvar_num(cvar_karma_multi)*(g_iPlayerData[victim][PD_KARMATEMP]/1000.0));
        
modifier = (3*(g_iMaxPlayers-1)-(num-1))/(g_iMaxPlayers-1);
    }
    else if(
type == KARMA_DMG)
    {
        new 
Float:temp entity_get_float(victimEV_FL_dmg_take);
        
karmamulti floatround(temp*0.25) < floatround(temp*get_pcvar_float(cvar_karma_damage));
        
modifier 1;
    }

    new 
ivictim get_special_alive(victim);
    new 
iattacker get_special_alive(attacker);

    switch(
iattacker)
    {
        case 
PC_TRAITOR//attacker is traitor
        
{
            switch(
ivictim)
            {
                case 
PC_TRAITOR:                    g_iPlayerData[attacker][PD_KARMATEMP] -= karmamulti*modifier;
                case 
PC_DETECTIVEPC_INNOCENT:        g_iPlayerData[attacker][PD_KARMATEMP] += karmamulti/modifier;
            }
        }
        case 
PC_DETECTIVEPC_INNOCENT//attacker is detective or innocent
        
{
            switch(
ivictim)
            {
                case 
PC_TRAITOR:                    g_iPlayerData[attacker][PD_KARMATEMP] += karmamulti/modifier;
                case 
PC_DETECTIVEPC_INNOCENT:        g_iPlayerData[attacker][PD_KARMATEMP] -= karmamulti*modifier;
            }
        }
    }

    
karma_reset(attacker);
}

stock karma_reset(id)
{
    if(
g_iPlayerData[id][PD_KARMATEMP] > 1000)
        
g_iPlayerData[id][PD_KARMATEMP] = 1000;
    else if(
g_iPlayerData[id][PD_KARMATEMP] < 1)
        
g_iPlayerData[id][PD_KARMATEMP] = 0;
}

stock set_game_state(new_state)
{
    
ttt_log_to_file(LOG_GAMETYPE"[PRE ] Gamemode: %s"g_szGameModes[g_iGlobalInfo[GI_GAMEMODE]]);
    if(
get_game_state() && get_game_state() < GAME_ENDED && new_state == GAME_RESTARTING)
        
log_amx("[TTT] Game has restarted :( (game: %d)"get_game_state());

    
g_iGlobalInfo[GI_GAMEMODE] = new_state;

    new 
ret;
    
ExecuteForward(g_iGameModeForwardretnew_state);
    
ttt_log_to_file(LOG_GAMETYPE"[POST] Gamemode: %s"g_szGameModes[g_iGlobalInfo[GI_GAMEMODE]]);
}

stock get_game_state()
    return 
g_iGlobalInfo[GI_GAMEMODE];

stock get_special_state(id)
    return 
g_iPlayerData[id][PD_PLAYERSTATE];

stock get_special_alive(id)
{
    if(!
is_user_alive(id))
        return 
g_iPlayerData[id][PD_KILLEDSTATE];

    return 
get_special_state(id);
}

stock set_special_state(idnew_state)
{
    if(!
is_user_connected(id))
        return;

    new 
player_state get_special_state(id);
    if(
player_state == new_state)
        return;

    
set_special_count(player_stateget_special_count(player_state)-1);

    
set_player_data(idPD_PLAYERSTATEnew_state);
    
set_special_count(new_stateget_special_count(new_state)+1);
}

stock set_player_data(idpdvalue)
    
g_iPlayerData[id][pd] = value;

stock get_player_data(idpd)
    return 
g_iPlayerData[id][pd];

stock set_special_count(special_statecount)
    
g_iSpecialCount[special_state] = count;

stock get_special_count(special_state)
    return 
g_iSpecialCount[special_state];

stock set_fake_team(idgetstate)
{
    new 
numispecstate;
    static 
players[32];
    
get_players(playersnum);

    for(--
numnum >= 0num--)
    {
        
players[num];
        
specstate get_special_state(i);
        switch(
getstate)
        {
            case 
PC_INNOCENTPC_DETECTIVE:
            {
                if(
specstate == PC_DETECTIVE)
                    
set_fake_message(idi"CT");
                else 
set_fake_message(idi"TERRORIST");
            }
            case 
PC_TRAITOR:
            {
                if(
specstate == PC_TRAITOR || specstate == PC_DETECTIVE)
                {
                    
set_fake_message(idi"CT");
                    if(
specstate == PC_DETECTIVE)
                        
set_attrib_special(i4PC_TRAITORPC_NONEPC_DEAD);
                }
                else 
set_fake_message(idi"TERRORIST");
            }
        }
    }
}

stock set_fake_message(idimsg[])
{
    
message_begin(MSG_ONE_UNRELIABLEg_pMsgTeamInfo_id);
    
write_byte(i);
    
write_string(msg);
    
message_end();
}

stock Float:get_round_time()
    return 
get_gametime() - g_fRoundStart g_fFreezeTime;

stock mynew_register_cvar(name[], string[], description[], flags 0Float:fvalue 0.0)
{
    
new_register_cvar(namestringdescription);
    return 
register_cvar(namestringflagsfvalue);
}

stock new_register_cvar(name[], string[], description[], plug[] = "ttt_core.amxx")
{
    static 
path[96];
    if(!
path[0])
    {
        
get_localinfo("amxx_configsdir"pathcharsmax(path));
        
format(pathcharsmax(path), "%s/%s"pathTTT_CONFIGFILE);
    }

    new 
file;
    if(!
g_tCvarsToFile)
        
g_tCvarsToFile TrieCreate();

    if(!
file_exists(path))
    {
        
file fopen(path"wt");
        if(!
file)
            return 
0;

        
fprintf(file"// Server specific.^n");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_tkpunish""0",                plug"Disables TeamKill punishments");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_friendlyfire""1",            plug"Enables friendly fire to attack teamnates");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_limitteams""0",                plug"Disables team limits");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_autoteambalance""0",            plug"Disables team limits");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_freezetime""0",                plug"Disables freeze time on round start");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_playerid""2",                plug"Disables team info when aiming on player");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""sv_allktalk""1",                plug"Enables alltalk");
        
fprintf(file"%-26s %-14s // %-32s // %s^n""amx_statscfg""off PlayerName",    plug"Disables player name when aiming on player");
        
fprintf(file"^n");
        
fprintf(file"// Mod specific.^n");
    }
    else
    {
        
file fopen(path"rt");
        if(!
file)
            return 
0;

        
//if(!TrieGetSize(g_tCvarsToFile))
        
if(!g_iTrieSize)
        {
            new 
newline[48];
            static 
line[128];
            while(!
feof(file))
            {
                
fgets(filelinecharsmax(line));
                if(
line[0] == ';' || !line[0])
                    continue;

                
parse(linenewlinecharsmax(newline));
                
remove_quotes(newline);
                
#if AMXX_VERSION_NUM >= 183
                    
TrieSetCell(g_tCvarsToFilenewline1false);
                
#else
                    
TrieSetCell(g_tCvarsToFilenewline1);
                
#endif
                
g_iTrieSize++;
            }
        }
        
fclose(file);
        
file fopen(path"at");
    }

    if(!
TrieKeyExists(g_tCvarsToFilename))
    {
        
fprintf(file"%-32s %-8s // %-32s // %s^n"namestringplugdescription);
        
#if AMXX_VERSION_NUM >= 183
            
TrieSetCell(g_tCvarsToFilename1false);
        
#else
            
TrieSetCell(g_tCvarsToFilename1);
        
#endif
        
g_iTrieSize++;
    }

    
fclose(file);
    return 
1;
}

// API
public _set_playerstate(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_set_playerstate needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    
set_special_state(get_param(1), get_param(2));
    return 
1;
}

public 
_set_gamemode(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_set_gamemode needs 1 param(p1: %d)"pluginparamsget_param(1));

    
set_game_state(get_param(1));
    return 
1;
}

public 
_get_specialcount(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_get_specialcount needs 1 param(p1: %d)"pluginparamsget_param(1));

    return 
get_special_count(get_param(1));
}

public 
Float:_get_roundtime()
    return 
get_round_time();

public 
_get_playerdata(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_get_playerdata needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    return 
get_player_data(get_param(1), get_param(2));
}

public 
_set_playerdata(pluginparams)
{
    if(
params != 3)
        return 
ttt_log_api_error("ttt_set_playerdata needs 3 params(p1: %d, p2: %d, p3: %d)"pluginparamsget_param(1), get_param(2), get_param(3));

    new 
id get_param(1);
    new 
datatype get_param(2);
    
set_player_data(iddatatypeget_param(3));
    if(
datatype == PD_KARMATEMP)
        
karma_reset(id);

    return 
1;
}

public 
_get_globalinfo(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_get_globalinfo needs 1 param(p1: %d)"pluginparamsget_param(1));

    return 
g_iGlobalInfo[get_param(1)];
}

public 
_set_globalinfo(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_set_globalinfo needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    
g_iGlobalInfo[get_param(1)] = get_param(2);
    return 
1;
}

public 
_register_cvar(pluginparams)
{
    if(
params != 3)
        return 
ttt_log_api_error("ttt_register_cvar needs 3 params"pluginparams);

    static 
name[48], string[16], pluginname[48], description[128];
    
get_string(1namecharsmax(name));
    
get_string(2stringcharsmax(string));
    
get_string(3descriptioncharsmax(description));
    
get_plugin(pluginpluginnamecharsmax(pluginname));

    return 
new_register_cvar(namestringdescriptionpluginname);
}

public 
_add_exception(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_add_exception needs 1 param(p1: %d)"pluginparamsget_param(1));

    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == -2)
        {
            
g_iExceptionItems[i] = get_param(1);
            return 
1;
        }
    }

    return 
0;
}

public 
_find_exception(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_find_exception needs 1 param(p1: %d)"pluginparamsget_param(1));

    new 
item get_param(1);
    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == item)
            return 
1;
    }

    return 
0;



JuanitoAlimana 01-16-2023 17:31

Re: [TTT] Give karma
 
Up

JuanitoAlimana 03-25-2023 20:32

Re: [TTT] Give karma
 
This would be so cool...

dhruv21995 03-26-2023 03:42

Re: [TTT] Give karma
 
1 Attachment(s)
Quote:

Originally Posted by JuanitoAlimana (Post 2795574)
Is there a way so players with the ADMIN_CFG flag get 100 extra karma points if they type /karma? Also, it would be awesome if they could only use it once every 10 minutes. Thanks!

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <cs_teams_api>
#include <timer_controller>
#include <ttt>

...
...
...
    return 
0;



The entire code has been converted to .sma file and attached for better viewing. No editing has been done. I liked to concept and hope to provide a solution to this soon enough!

lexzor 03-26-2023 09:16

Re: [TTT] Give karma
 
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <cs_teams_api>
#include <timer_controller>
#include <ttt>
#include <amxmisc>
#include <nvault>

#define TASK_SURVIVAL            1111
#define TASK_ORPHEU                2222
#define m_bitsDamageType        76
#define m_flPainShock            108
#define OFFSET_LINUX_WEAPONS    4
#define OFFSET_LINUX_PLAYERS    5

enum
{
    
KARMA_KILL,
    
KARMA_DMG
}

new const 
g_szGameModes[GAME_MODE][] =
{
    
"unset",
    
"off",
    
"preparing",
    
"restarting",
    
"started",
    
"ended"
};

const 
DMG_SOMETHING DMG_GENERIC DMG_SLASH DMG_BURN 
    
DMG_FREEZE DMG_FALL DMG_BLAST DMG_SHOCK DMG_DROWN 
    
DMG_NERVEGAS DMG_POISON DMG_RADIATION DMG_ACID;
    
// RESETABLE
new g_iGlobalInfo[GLOBAL_INFO], g_iSpecialCount[PLAYER_CLASS], g_iRoundSpecial[PLAYER_CLASS];
new 
g_iPlayerData[33][PLAYER_DATA];
new 
g_iMultiCount 1g_iMultiSeconds 1;
new 
Trie:g_tCvarsToFileg_iTrieSize;
//
// NON RESETABLE
new cvar_traitorscvar_detectivescvar_karma_damage,
    
cvar_preparation_timecvar_karma_multicvar_karma_start,
    
cvar_credits_tra_startcvar_credits_tra_countcvar_credits_tra_detkillcvar_credits_tra_countkill,
    
cvar_credits_det_startcvar_credits_tra_repeatcvar_damage_modifier,
    
cvar_credits_det_bonussurvcvar_credits_det_survtimecvar_show_deathmessagecvar_detective_glow;
new 
g_pMsgTeamInfog_pMsgScreenFadeg_iGameModeForwardg_iPluginCfgForward;
new 
Float:g_fFreezeTimeFloat:g_fRoundTimeFloat:g_fRoundStart;
new 
g_iMaxDetectivesg_iMaxTraitorsg_iMaxPlayers;
new 
g_iExceptionItems[10] = {-2, -2, ...};
//

new g_iVaultg_iKarmaTime[33],
new const 
g_szVaultName[] = "karma"
new g_iCvar[2]

public 
plugin_init()
{
    
register_plugin("[TTT] Core"TTT_VERSIONTTT_AUTHOR);
    
register_cvar("ttt_server_version"TTT_VERSIONFCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);

    
cvar_traitors                mynew_register_cvar("ttt_traitors",                "4",    "One Traitor on X players. (Default: 4)");
    
cvar_detectives                mynew_register_cvar("ttt_detectives",                "6",    "One Detective on X players. (Default: 6)");
    
cvar_preparation_time        mynew_register_cvar("ttt_preparation_time",        "10",    "Preparation time before game start. (Default: 10)");
    
cvar_credits_tra_start        mynew_register_cvar("ttt_credits_tra_start",        "2",    "Number of credits Traitor has when starting game. (Default: 2)");
    
cvar_credits_tra_count        mynew_register_cvar("ttt_credits_tra_count",        "0.25",    "Percentage of players to kill to get extra credits. (Default: 0.25)");
    
cvar_credits_tra_repeat        mynew_register_cvar("ttt_credits_tra_repeat",        "1",    "Repeat percentage kills till all are killed. (Default: 1)");
    
cvar_credits_tra_detkill    mynew_register_cvar("ttt_credits_tra_detkill",    "1",    "Number of credits for killing a Detective. (Default: 1)");
    
cvar_credits_tra_countkill    mynew_register_cvar("ttt_credits_tra_countkill",    "1",    "Number of credits to give for percentage kills. (Default: 1)");
    
cvar_credits_det_start        mynew_register_cvar("ttt_credits_det_start",        "1",    "Number of credits Detective has when starting game. (Default: 1)");
    
cvar_credits_det_bonussurv    mynew_register_cvar("ttt_credits_det_bonussurv",    "1",    "Number of credits to give for surviving time. (Default: 1)");
    
cvar_credits_det_survtime    mynew_register_cvar("ttt_credits_det_survtime",    "45.0",    "Every X seconds give credits. (Default: 45.0)");
    
cvar_karma_damage            mynew_register_cvar("ttt_karma_damage",            "0.25",    "Karma modifier dealing damage. (Default: 0.25)");
    
cvar_karma_multi            mynew_register_cvar("ttt_karma_multi",            "50",    "Karma modifier for killing. (Default: 50)");
    
cvar_karma_start            mynew_register_cvar("ttt_karma_start",            "500",    "Starting karma. (Default: 500)");
    
cvar_show_deathmessage        mynew_register_cvar("ttt_show_deathmessage",        "abeg",    "Show deathmessages to: a=NONE, b=TRAITOR, c=DETECTIVE, d=INNOCENT, e=DEAD, f=SPECIAL, g=victim, h=killer. (Default: abeg)");
    
cvar_damage_modifier        mynew_register_cvar("ttt_damage_modifier",        "1.0",    "Modifies karma based damage. (Default: 1.0)");
    
cvar_detective_glow            mynew_register_cvar("ttt_detective_glow",            "1",    "Should detective also be glowing? (Default: 1)");

    
g_pMsgScreenFade    get_user_msgid("ScreenFade");
    
g_pMsgTeamInfo        get_user_msgid("TeamInfo");

    
register_event("TextMsg""Event_RoundRestart""a""2&#Game_C""2&#Game_w");
    
register_event("HLTV""Event_HLTV""a""1=0""2=0");
    
register_event("DeathMsg""Event_DeathMsg""a");
    
register_logevent("Event_EndPreptime"2"1=Round_Start");
    
register_logevent("Event_EndRound"2"1=Round_End");

    
register_forward(FM_AddToFullPack"Forward_AddToFullPack_post"1);

    
RegisterHamPlayer(Ham_Killed"Ham_Killed_pre"0);
    
RegisterHamPlayer(Ham_Killed"Ham_Killed_post"1);
    
RegisterHamPlayer(Ham_TakeDamage"Ham_TakeDamage_pre"0);
    
RegisterHamPlayer(Ham_TakeDamage"Ham_TakeDamage_post"1);
    
RegisterHamPlayer(Ham_TraceAttack"Ham_TraceAttack_pre"0);

    
g_iGameModeForward CreateMultiForward("ttt_gamemode"ET_IGNOREFP_CELL);
    
g_iPluginCfgForward CreateMultiForward("ttt_plugin_cfg"ET_IGNORE);

    
g_iMaxPlayers get_maxplayers();
    
#if AMXX_VERSION_NUM < 183
    
register_dictionary("ttt_c.txt");
    
register_dictionary("ttt_addons_c.txt");
    
#else
    
register_dictionary("ttt.txt");
    
register_dictionary("ttt_addons.txt");
    
#endif

    
register_clcmd("say /karma""karmaCmd"ADMIN_CFG)
    
register_clcmd("say_team /karma""karmaCmd"ADMIN_CFG)

    if((
g_iVault nvault_open(g_szVaultName)) == INVALID_HANDLE)
    {
        
set_fail_state("File ^"%s^" couldn't be opened"g_szVaultName)
    }

    
g_iCvar[0] = register_cvar("karma_cmd_points""100")
    
g_iCvar[1] = register_cvar("karma_cmd_time""10")
}

public 
karmaCmd(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
    {
        return 
PLUGIN_HANDLED
    
}

    if(
g_iKarmaTime[id] < get_systime())
    {
        
client_print_color(idprint_team_default"%s You have to wait^4 %i minutes^1 to get free karma points again."TTT_TAG, (get_systime() - g_iKarmaTime[id]) * 60);
        return 
PLUGIN_CONTINUE
    
}

    new 
karmaPoints get_pcvar_num(g_iCvar[0])
    new 
iTime get_pcvar_num(g_iCvar[1]), szAuthID[MAX_AUTHID_LENGTH]
    
get_user_authid(idszAuthIDcharsmax(szAuthID))

    
g_iKarmaTime[id] = get_systime(iTime 60)
    
nvault_set(g_iVaultszAuthIDfmt("%i"g_iKarmaTime[id]))

    
client_print_color(idprint_team_default"%s You got^4 %i^1 karma points! You can get another^4 %i^1 after^3 %i minutes^1."TTT_TAGkarmaPointskarmaPointsiTime);

    return 
PLUGIN_CONTINUE
}

public 
plugin_end()
{
    
nvault_close(g_iVault)
    
set_game_state(GAME_PREPARING);
}

public 
plugin_natives()
{
    
register_library("ttt");
    
register_native("ttt_get_roundtime",    "_get_roundtime");
    
register_native("ttt_get_playerdata",    "_get_playerdata");
    
register_native("ttt_set_playerdata",    "_set_playerdata");
    
register_native("ttt_get_globalinfo",    "_get_globalinfo");
    
register_native("ttt_set_globalinfo",    "_set_globalinfo");
    
register_native("ttt_set_playerstate",    "_set_playerstate");
    
register_native("ttt_set_gamemode",        "_set_gamemode");
    
register_native("ttt_get_specialcount",    "_get_specialcount");
    
register_native("ttt_register_cvar",    "_register_cvar");
    
register_native("ttt_add_exception",    "_add_exception");
    
register_native("ttt_find_exception",    "_find_exception");
}

public 
plugin_cfg()
{
    
auto_exec_config(TTT_CONFIGFILE);
    
g_fRoundTime get_pcvar_float(get_cvar_pointer("mp_roundtime"));
    
TrieDestroy(g_tCvarsToFile);

    new 
ret;
    
ExecuteForward(g_iPluginCfgForwardret);
}

public 
client_disconnect(id)
{
    
set_task(0.5"reset_client"id);
    
set_special_state(idPC_NONE);
}

public 
client_putinserver(id)
{
    
// if(is_user_bot(id))
    //     server_cmd("kick #%i %s", get_user_userid(id), "Bot player!");

    
reset_client(id);
    
g_iPlayerData[id][PD_KILLEDBY] = -1;
    
set_task(11.0"startup_info"id);

    new 
karma get_pcvar_num(cvar_karma_start);
    
g_iPlayerData[id][PD_KARMATEMP] = karma;
    
g_iPlayerData[id][PD_KARMA] = karma;

    static 
szAuthID[MAX_AUTHID_LENGTH], iTsszData[12]
    
get_user_authid(idszAuthIDcharsmax(szAuthID))

    
g_iKarmaTime[id] = -1

    
if(nvault_lookup(g_iVaultszAuthIDszDatacharsmax(szData), iTs))
    {
        
g_iKarmaTime[id] = str_to_num(szData);
    }

}

public 
startup_info(id)
{
    if(
get_game_state() == GAME_STARTED && !is_user_alive(id))
    {
        
set_special_state(idPC_DEAD);
        
Show_All();
    }

    
// Please don't remove this :)
    
client_print_color(idprint_team_default"%s Mod created by ^3%s^1, ^4skype:guskis1^1, version: ^3%s^1!"TTT_TAGTTT_AUTHORTTT_VERSION);
}

public 
Event_RoundRestart()
{
    if(
get_game_state() != GAME_RESTARTING)
    {
        
reset_all();
        
set_game_state(GAME_RESTARTING);
    }
}

public 
Event_HLTV()
{
    if(
get_game_state() != GAME_PREPARING)
    {
        new 
cvar get_pcvar_num(cvar_preparation_time);
        if(!
cvar)
            
set_pcvar_num(cvar_preparation_timecvar 1);
        
g_fFreezeTime float(cvar);
        
set_task(0.1"set_timer");

        
g_fRoundTime get_pcvar_float(get_cvar_pointer("mp_roundtime"));
        
g_fRoundStart get_gametime();
        
reset_all();

        
set_game_state(GAME_PREPARING);
    }
}

public 
set_timer()
    
RoundTimerSet(0get_pcvar_num(cvar_preparation_time));

public 
Event_EndRound()
{
    if(
get_game_state() != GAME_ENDED)
    {
        
reset_all();
        
set_game_state(GAME_ENDED);
    }
}

public 
Event_EndPreptime()
{
    if(
task_exists(TASK_ORPHEU))
        
remove_task(TASK_ORPHEU);
    
set_task(float(get_pcvar_num(cvar_preparation_time)), "do_the_magic"TASK_ORPHEU);
}

public 
do_the_magic()
{
    
RoundTimerSet(floatround(g_fRoundTime));

    new 
num;
    static 
players[32];
    
get_players(playersnum);
    
ttt_log_to_file(LOG_DEFAULT"Current player count %d"num);

    if(
num 3)
    {
        
set_game_state(GAME_OFF);
        
client_print_color(0print_team_default"%s %L"TTT_TAGLANG_PLAYER"TTT_MODOFF1");
        return;
    }

    new 
trai get_pcvar_num(cvar_traitors), dete get_pcvar_num(cvar_detectives);
    
g_iMaxTraitors = (num/trai);
    if(!
g_iMaxTraitors)
        
g_iMaxTraitors 1;

    
g_iMaxDetectives = (num/dete);
    if(
g_iMaxTraitors+g_iMaxDetectives>num)
    {
        
set_pcvar_num(cvar_detectives8);
        
set_pcvar_num(cvar_traitors4);
        
g_iMaxTraitors = (num/trai);

        if(!
g_iMaxTraitors)
            
g_iMaxTraitors 1;
    
        
g_iMaxDetectives = (num/dete);
        
client_print_color(0print_team_default"%s %L"TTT_TAGLANG_PLAYER"TTT_MODOFF2");
    }
    while(
specials_needed() != 0)
        
pick_specials();

    new 
id;
    for(--
numnum >= 0num--)
    {
        
id players[num];
        if(!
is_user_alive(id)) continue;
        
g_iPlayerData[id][PD_KARMA] = g_iPlayerData[id][PD_KARMATEMP];

        if(
get_special_state(id) != PC_DETECTIVE && get_special_state(id) != PC_TRAITOR)
        {
            
screen_fade(idPC_INNOCENT);
            
set_special_state(idPC_INNOCENT);
            
cs_set_player_team(idCS_TEAM_CTfalse);
        }

        
entity_set_float(idEV_FL_fragsfloat(g_iPlayerData[id][PD_KARMA]));
        
cs_set_user_deaths(idg_iPlayerData[id][PD_KILLEDDEATHS]);
    }

    new 
i;
    for(
0PLAYER_CLASSi++)
        
g_iRoundSpecial[i] = get_special_count(i);

    
set_task(get_pcvar_float(cvar_credits_det_survtime), "give_survival_credits"TASK_SURVIVAL__"b");
    
    
get_players(playersnum);
    for(--
numnum >= 0num--)
    {
        
id players[num];
        
set_fake_team(idget_special_state(id));
    }

    
set_game_state(GAME_STARTED);
}

public 
Event_DeathMsg()
{
    new 
killer read_data(1); 
    new 
victim read_data(2);
    static 
weapon[16];
    
read_data(4weaponcharsmax(weapon));

    if(
is_user_connected(killer))
    {
        static 
newweap[32];
        
g_iPlayerData[victim][PD_KILLEDBY] = killer;
        
g_iPlayerData[killer][PD_KILLCOUNT]++;
        
formatex(newweapcharsmax(newweap), "weapon_%s"weapon);
        
g_iPlayerData[victim][PD_KILLEDWEAP] = get_weaponid(newweap);
    }

    static 
cvar[10];
    
get_pcvar_string(cvar_show_deathmessagecvarcharsmax(cvar));
    if(
cvar[0])
        
ttt_make_deathmsg(killervictimread_data(3), weaponread_flags(cvar));

    if(
equali(weapon"worldspawn"))
        
g_iPlayerData[victim][PD_KILLEDWEAP] = DEATHS_SUICIDE;
}

public 
Ham_Killed_pre(victimkillershouldgib)
{
    if(
my_return_check(victim))
        return 
HAM_IGNORED;

    if(
get_pdata_int(victimm_bitsDamageType) & DMG_SOMETHING)
        
add_death_info(victimkillerget_pdata_int(victimm_bitsDamageType5));

    
g_iPlayerData[victim][PD_KILLEDSTATE] = get_special_state(victim);
    
g_iPlayerData[victim][PD_KILLEDTIME] = floatround(floatmul(g_fRoundTime60.0) - get_round_time());
    
g_iPlayerData[victim][PD_KILLEDDEATHS]++;

    
set_special_state(victimPC_DEAD);
    return 
HAM_HANDLED;
}

public 
add_death_info(victimkillerdmg)
{
    new 
msg get_deathmessage(0dmg);
    if(
is_user_connected(killer))
    {
        
g_iPlayerData[victim][PD_KILLEDBY] = killer;
        
g_iPlayerData[killer][PD_KILLCOUNT]++;
    }
    else 
g_iPlayerData[victim][PD_KILLEDBY] = msg;

    
g_iPlayerData[victim][PD_KILLEDWEAP] = msg;
}

public 
get_deathmessage(iddmg)
{
    if(!
id)
    {
        if(
dmg DMG_GENERIC)
            
dmg DEATHS_GENERIC;
        else if(
dmg DMG_SLASH)
            
dmg DEATHS_SLASH;
        else if(
dmg DMG_BURN)
            
dmg DEATHS_BURN;
        else if(
dmg DMG_FREEZE)
            
dmg DEATHS_FREEZE;
        else if(
dmg DMG_FALL)
            
dmg DEATHS_FALL;
        else if(
dmg DMG_BLAST)
            
dmg DEATHS_BLAST;
        else if(
dmg DMG_SHOCK)
            
dmg DEATHS_SHOCK;
        else if(
dmg DMG_DROWN)
            
dmg DEATHS_DROWN;
        else if(
dmg DMG_NERVEGAS)
            
dmg DEATHS_NERVEGAS;
        else if(
dmg DMG_POISON)
            
dmg DEATHS_POISON;
        else if(
dmg DMG_RADIATION)
            
dmg DEATHS_RADIATION;
        else if(
dmg DMG_ACID)
            
dmg DEATHS_ACID;
        else 
dmg DEATHS_SUICIDE;
    }
    else 
dmg g_iPlayerData[id][PD_KILLEDWEAP];

    return 
dmg;
}

public 
Ham_Killed_post(victimkillershouldgib)
{
    if(
my_return_check(victim))
        return;

    if(!
is_user_connected(killer))
    {
        
killer find_valid_killer(victimkiller);
    }

    new 
bonus;
    static 
players[32], name[32];
    if(
float(get_special_count(PC_DEAD)+get_special_count(PC_TRAITOR)-g_iRoundSpecial[PC_TRAITOR])/float(g_iRoundSpecial[PC_INNOCENT]+g_iRoundSpecial[PC_DETECTIVE])
    > 
get_pcvar_float(cvar_credits_tra_count) * g_iMultiCount)
    {
        new 
numi;
        
bonus get_pcvar_num(cvar_credits_tra_countkill);
        
get_players(playersnum"a");
        for(--
numnum >= 0num--)
        {
            
players[num];

            if(
get_special_state(i) == PC_TRAITOR)
            {
                
g_iPlayerData[i][PD_CREDITS] += bonus;
                
client_print_color(iprint_team_default"%s %L"TTT_TAGi"TTT_AWARD1"bonusfloatround(get_pcvar_float(cvar_credits_tra_count)* g_iMultiCount*100), ispecial_names[PC_INNOCENT]);
            }
        }

        if(
get_pcvar_num(cvar_credits_tra_repeat))
            
g_iMultiCount++;
        else 
g_iMultiCount 100;
    }

    if(
is_user_connected(killer))
    {
        new 
killer_state get_special_alive(killer), victim_state get_special_alive(victim);
        if(
killer_state == PC_TRAITOR && victim_state == PC_DETECTIVE)
        {
            
bonus get_pcvar_num(cvar_credits_tra_detkill);
            
g_iPlayerData[killer][PD_CREDITS] += bonus;
            
get_user_name(victimnamecharsmax(name));
            
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_AWARD2"bonuskillerspecial_names[PC_DETECTIVE], name);
        }

        if(
killer != victim)
        {
            
get_user_name(victimnamecharsmax(name));
            if(
killer_state == PC_INNOCENT || killer_state == PC_DETECTIVE)
                
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_KILLED2"name);
            else if(
killer_state == PC_TRAITOR || victim_state == PC_TRAITOR)
                
client_print_color(killerprint_team_default"%s %L"TTT_TAGkiller"TTT_KILLED3"namekillerspecial_names[victim_state]);

            
get_user_name(killernamecharsmax(name));
            
client_print_color(victimprint_team_default"%s %L"TTT_TAGvictim"TTT_KILLED1"namevictimspecial_names[killer_state]);
        }
    }

    new 
killed_item killed_with_item(victim);
    if(
killed_item)
    {
        if(
is_user_connected(killer))
        {
            if(
victim != killer && get_special_alive(killer) != get_special_alive(victim))
                
karma_modifier(killervictimKARMA_KILL);
        }
    }
    else 
karma_modifier(killervictimKARMA_KILL);

    if(!
killed_item && (!is_user_connected(killer) || killer == victim))
        
client_print_color(victimprint_team_default"%s %L"TTT_TAGvictim"TTT_SUICIDE");

    
set_task(0.1"Show_All");
}

public 
find_valid_killer(victimkiller)
{
    new 
new_killer get_player_data(victimPD_KILLEDBY);
    return 
new_killer new_killer killer;
}

public 
killed_with_item(victim)
{
    new 
item get_player_data(victimPD_KILLEDBYITEM);
    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == item)
            return 
1;
    }

    return 
0;
}

public 
Show_All()
{
    if(
get_game_state() == GAME_STARTED)
    {
        new 
numispecstate;
        static 
players[32];
        
get_players(playersnum);
        for(--
numnum >= 0num--)
        {
            
players[num];

            
specstate get_special_state(i);
            if(
specstate == PC_DEAD || specstate == PC_NONE)
            {
                
set_attrib_special(i1PC_TRAITORPC_NONEPC_DEAD);
                if(!
g_iPlayerData[i][PD_SCOREBOARD])
                    
set_attrib_special(i0PC_INNOCENTPC_DETECTIVE);
            }
        }
    }
}

public 
Ham_TakeDamage_pre(victiminflictorattackerFloat:damagebits)
{
    if(!
my_return_check(attacker))
    {
        new 
Float:modifier g_iPlayerData[attacker][PD_KARMA]/1000.0;
        if(
modifier 0.05 && damage 0.1)
        {
            
damage *= (modifier*get_pcvar_float(cvar_damage_modifier));
            if(
cs_get_user_team(attacker) != cs_get_user_team(victim))
                
damage *= 0.35;

            if(
damage 1.0)
                
damage 1.0;
        }
        else 
damage 0.0;

        
SetHamParamFloat(4damage);
        return 
HAM_HANDLED;
    }

    return 
HAM_IGNORED;
}

public 
Ham_TakeDamage_post(victiminflictorattackerFloat:damagebits)
{
    if(!
my_return_check(attacker))
    {
        if(
damage 0.1)
        {
            if(
victim != attacker)
                
karma_modifier(attackervictimKARMA_DMG);
        }
        else 
set_pdata_float(victimm_flPainShock1.0OFFSET_LINUX_PLAYERS);
    }
}

public 
Ham_TraceAttack_pre()
{
    if(
get_game_state() != GAME_STARTED && get_game_state() != GAME_OFF)
        return 
HAM_SUPERCEDE;

    return 
HAM_IGNORED;
}

public 
Forward_AddToFullPack_post(es_handleeenthosthostflagsidpSet)
{
    if(
id && host != ent && is_user_connected(host) && is_user_connected(ent) && get_orig_retval())
    {
        static 
cvar;
        if(!
cvar)
            
cvar get_pcvar_num(cvar_detective_glow);

        new 
entTeam get_special_alive(ent);
        if(
entTeam != PC_INNOCENT)
        {
            new 
hostTeam get_special_alive(host);
            new 
fakeTeam get_player_data(entPD_FAKESTATE);
            if(
fakeTeam && hostTeam != entTeam)
                
entTeam fakeTeam;
            if(
hostTeam == PC_TRAITOR || ((hostTeam == PC_DETECTIVE || hostTeam == PC_INNOCENT) && entTeam != PC_TRAITOR && cvar))
            {
                
set_es(es_handleES_RenderFxkRenderFxGlowShell);
                
set_es(es_handleES_RenderColorg_iTeamColors[entTeam]);
                
set_es(es_handleES_RenderAmt35);
            }
        }
    }
}

public 
pick_specials()
{
    new 
idnum;
    static 
players[32];
    static 
name[32];

    
get_players(playersnum);

    while(
id == 0)
    {
        
id players[random(num)];
        if(
get_special_state(id) == PC_TRAITOR || get_special_state(id) == PC_DETECTIVE)
            
id 0;
    }

    new 
randomNum specials_needed();
    
get_user_name(idnamecharsmax(name));
    switch(
randomNum)
    {
        case 
PC_TRAITOR:
        {
            
g_iPlayerData[id][PD_CREDITS] = get_pcvar_num(cvar_credits_tra_start);
            
set_special_state(idrandomNum);

            
screen_fade(idrandomNum);
            
ttt_log_to_file(LOG_DEFAULT"[%L] %s choosen (ID:%d)"idspecial_names[randomNum], nameid);
            
cs_set_player_team(idCS_TEAM_Tfalse);
        }
        case 
PC_DETECTIVE:
        {
            if(
num >= get_pcvar_num(cvar_detectives))
            {
                
g_iPlayerData[id][PD_CREDITS] = get_pcvar_num(cvar_credits_det_start);
                
set_special_state(idrandomNum);

                
screen_fade(idrandomNum);
                
ttt_log_to_file(LOG_DEFAULT"[%L] %s choosen (ID:%d)"idspecial_names[randomNum], nameid);
                
cs_set_player_team(idCS_TEAM_CTfalse);
            }
        }
        case 
PC_NONE: return;
    }
}

stock screen_fade(idplayer_state)
{
    
message_begin(MSG_ONE_UNRELIABLEg_pMsgScreenFade_id);
    
write_short(FixedUnsigned16(1.01<<12));
    
write_short(0);
    
write_short((SF_FADE_MODULATE)); //flags (SF_FADE_IN + SF_FADE_ONLYONE) (SF_FADEOUT)
    
write_byte(g_iTeamColors[player_state][0]);
    
write_byte(g_iTeamColors[player_state][1]);
    
write_byte(g_iTeamColors[player_state][2]);
    
write_byte(180);
    
message_end();
}

stock my_return_check(id)
{
    new 
game get_game_state();
    if(!
is_user_connected(id) || game == GAME_OFF || game == GAME_ENDED)
        return 
1;

    return 
0;
}

public 
specials_needed()
{
    if(
g_iMaxTraitors get_special_count(PC_TRAITOR))
        return 
PC_TRAITOR;
    else if(
g_iMaxDetectives get_special_count(PC_DETECTIVE))
        return 
PC_DETECTIVE;

    return 
PC_NONE;
}

public 
give_survival_credits()
{
    static 
players[32];
    new 
numidbonus get_pcvar_num(cvar_credits_det_bonussurv);
    
get_players(playersnum"a");
    for(--
numnum >= 0num--)
    {
        
id players[num];
        if(
get_special_state(id) == PC_DETECTIVE)
        {
            
g_iPlayerData[id][PD_CREDITS] += bonus;
            
client_print_color(idprint_team_default"%s %L"TTT_TAGid"TTT_AWARD4"bonusfloatround(get_pcvar_float(cvar_credits_det_survtime))*g_iMultiSeconds);
            
g_iMultiSeconds++;
        }
    }
}

public 
reset_all()
{
    static 
players[32];
    new 
numidi;
    
get_players(playersnum);
    for(--
numnum >= 0num--)
    {
        
id players[num];

        
set_special_state(idPC_NONE);
        for(
0PLAYER_DATAi++)
        {
            if(
== PD_KARMA || == PD_KARMATEMP || == PD_KILLEDDEATHS) continue;
            if(
== PD_KILLEDBY || == PD_KILLEDBYITEM)
                
g_iPlayerData[id][i] = -1;
            else 
g_iPlayerData[id][i] = 0;
        }
        if(
task_exists(id))
            
remove_task(id);
        
set_attrib_all(id0);
    }

    for(
0PLAYER_CLASSi++)
        
g_iSpecialCount[i] = 0;
    
//if(get_game_state() == GAME_ENDED || get_game_state() == GAME_RESTARTING)
    //    set_game_state(GAME_OFF);

    
g_iMultiSeconds 1;
    
g_iMultiCount 1;

    if(
task_exists(TASK_SURVIVAL))
        
remove_task(TASK_SURVIVAL);
}

public 
reset_client(id)
{
    for(new 
0PLAYER_DATAi++)
    {
        if(
== PD_KILLEDBY || == PD_KILLEDBYITEM)
            
g_iPlayerData[id][i] = -1;
        else 
g_iPlayerData[id][i] = 0;
    }

    
set_special_state(idPC_NONE);
    
set_attrib_all(id0);
}

public 
karma_modifier(attackervictimtype)
{
    if(
attacker == 0)
        
attacker victim;

    if(!
is_user_connected(attacker) || !is_user_connected(victim) || get_game_state() == GAME_OFF)
        return;

    static 
players[32];
    new 
numkarmamultimodifier;
    
get_players(playersnum);
    if(
type == KARMA_KILL)
    {
        
karmamulti floatround(get_pcvar_num(cvar_karma_multi)*(g_iPlayerData[victim][PD_KARMATEMP]/1000.0));
        
modifier = (3*(g_iMaxPlayers-1)-(num-1))/(g_iMaxPlayers-1);
    }
    else if(
type == KARMA_DMG)
    {
        new 
Float:temp entity_get_float(victimEV_FL_dmg_take);
        
karmamulti floatround(temp*0.25) < floatround(temp*get_pcvar_float(cvar_karma_damage));
        
modifier 1;
    }

    new 
ivictim get_special_alive(victim);
    new 
iattacker get_special_alive(attacker);

    switch(
iattacker)
    {
        case 
PC_TRAITOR//attacker is traitor
        
{
            switch(
ivictim)
            {
                case 
PC_TRAITOR:                    g_iPlayerData[attacker][PD_KARMATEMP] -= karmamulti*modifier;
                case 
PC_DETECTIVEPC_INNOCENT:        g_iPlayerData[attacker][PD_KARMATEMP] += karmamulti/modifier;
            }
        }
        case 
PC_DETECTIVEPC_INNOCENT//attacker is detective or innocent
        
{
            switch(
ivictim)
            {
                case 
PC_TRAITOR:                    g_iPlayerData[attacker][PD_KARMATEMP] += karmamulti/modifier;
                case 
PC_DETECTIVEPC_INNOCENT:        g_iPlayerData[attacker][PD_KARMATEMP] -= karmamulti*modifier;
            }
        }
    }

    
karma_reset(attacker);
}

stock karma_reset(id)
{
    if(
g_iPlayerData[id][PD_KARMATEMP] > 1000)
        
g_iPlayerData[id][PD_KARMATEMP] = 1000;
    else if(
g_iPlayerData[id][PD_KARMATEMP] < 1)
        
g_iPlayerData[id][PD_KARMATEMP] = 0;
}

stock set_game_state(new_state)
{
    
ttt_log_to_file(LOG_GAMETYPE"[PRE ] Gamemode: %s"g_szGameModes[g_iGlobalInfo[GI_GAMEMODE]]);
    if(
get_game_state() && get_game_state() < GAME_ENDED && new_state == GAME_RESTARTING)
        
log_amx("[TTT] Game has restarted :( (game: %d)"get_game_state());

    
g_iGlobalInfo[GI_GAMEMODE] = new_state;

    new 
ret;
    
ExecuteForward(g_iGameModeForwardretnew_state);
    
ttt_log_to_file(LOG_GAMETYPE"[POST] Gamemode: %s"g_szGameModes[g_iGlobalInfo[GI_GAMEMODE]]);
}

stock get_game_state()
    return 
g_iGlobalInfo[GI_GAMEMODE];

stock get_special_state(id)
    return 
g_iPlayerData[id][PD_PLAYERSTATE];

stock get_special_alive(id)
{
    if(!
is_user_alive(id))
        return 
g_iPlayerData[id][PD_KILLEDSTATE];

    return 
get_special_state(id);
}

stock set_special_state(idnew_state)
{
    if(!
is_user_connected(id))
        return;

    new 
player_state get_special_state(id);
    if(
player_state == new_state)
        return;

    
set_special_count(player_stateget_special_count(player_state)-1);

    
set_player_data(idPD_PLAYERSTATEnew_state);
    
set_special_count(new_stateget_special_count(new_state)+1);
}

stock set_player_data(idpdvalue)
    
g_iPlayerData[id][pd] = value;

stock get_player_data(idpd)
    return 
g_iPlayerData[id][pd];

stock set_special_count(special_statecount)
    
g_iSpecialCount[special_state] = count;

stock get_special_count(special_state)
    return 
g_iSpecialCount[special_state];

stock set_fake_team(idgetstate)
{
    new 
numispecstate;
    static 
players[32];
    
get_players(playersnum);

    for(--
numnum >= 0num--)
    {
        
players[num];
        
specstate get_special_state(i);
        switch(
getstate)
        {
            case 
PC_INNOCENTPC_DETECTIVE:
            {
                if(
specstate == PC_DETECTIVE)
                    
set_fake_message(idi"CT");
                else 
set_fake_message(idi"TERRORIST");
            }
            case 
PC_TRAITOR:
            {
                if(
specstate == PC_TRAITOR || specstate == PC_DETECTIVE)
                {
                    
set_fake_message(idi"CT");
                    if(
specstate == PC_DETECTIVE)
                        
set_attrib_special(i4PC_TRAITORPC_NONEPC_DEAD);
                }
                else 
set_fake_message(idi"TERRORIST");
            }
        }
    }
}

stock set_fake_message(idimsg[])
{
    
message_begin(MSG_ONE_UNRELIABLEg_pMsgTeamInfo_id);
    
write_byte(i);
    
write_string(msg);
    
message_end();
}

stock Float:get_round_time()
    return 
get_gametime() - g_fRoundStart g_fFreezeTime;

stock mynew_register_cvar(name[], string[], description[], flags 0Float:fvalue 0.0)
{
    
new_register_cvar(namestringdescription);
    return 
register_cvar(namestringflagsfvalue);
}

stock new_register_cvar(name[], string[], description[], plug[] = "ttt_core.amxx")
{
    static 
path[96];
    if(!
path[0])
    {
        
get_localinfo("amxx_configsdir"pathcharsmax(path));
        
format(pathcharsmax(path), "%s/%s"pathTTT_CONFIGFILE);
    }

    new 
file;
    if(!
g_tCvarsToFile)
        
g_tCvarsToFile TrieCreate();

    if(!
file_exists(path))
    {
        
file fopen(path"wt");
        if(!
file)
            return 
0;

        
fprintf(file"// Server specific.^n");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_tkpunish""0",                plug"Disables TeamKill punishments");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_friendlyfire""1",            plug"Enables friendly fire to attack teamnates");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_limitteams""0",                plug"Disables team limits");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_autoteambalance""0",            plug"Disables team limits");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_freezetime""0",                plug"Disables freeze time on round start");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""mp_playerid""2",                plug"Disables team info when aiming on player");
        
fprintf(file"%-32s %-8s // %-32s // %s^n""sv_allktalk""1",                plug"Enables alltalk");
        
fprintf(file"%-26s %-14s // %-32s // %s^n""amx_statscfg""off PlayerName",    plug"Disables player name when aiming on player");
        
fprintf(file"^n");
        
fprintf(file"// Mod specific.^n");
    }
    else
    {
        
file fopen(path"rt");
        if(!
file)
            return 
0;

        
//if(!TrieGetSize(g_tCvarsToFile))
        
if(!g_iTrieSize)
        {
            new 
newline[48];
            static 
line[128];
            while(!
feof(file))
            {
                
fgets(filelinecharsmax(line));
                if(
line[0] == ';' || !line[0])
                    continue;

                
parse(linenewlinecharsmax(newline));
                
remove_quotes(newline);
                
#if AMXX_VERSION_NUM >= 183
                    
TrieSetCell(g_tCvarsToFilenewline1false);
                
#else
                    
TrieSetCell(g_tCvarsToFilenewline1);
                
#endif
                
g_iTrieSize++;
            }
        }
        
fclose(file);
        
file fopen(path"at");
    }

    if(!
TrieKeyExists(g_tCvarsToFilename))
    {
        
fprintf(file"%-32s %-8s // %-32s // %s^n"namestringplugdescription);
        
#if AMXX_VERSION_NUM >= 183
            
TrieSetCell(g_tCvarsToFilename1false);
        
#else
            
TrieSetCell(g_tCvarsToFilename1);
        
#endif
        
g_iTrieSize++;
    }

    
fclose(file);
    return 
1;
}

// API
public _set_playerstate(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_set_playerstate needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    
set_special_state(get_param(1), get_param(2));
    return 
1;
}

public 
_set_gamemode(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_set_gamemode needs 1 param(p1: %d)"pluginparamsget_param(1));

    
set_game_state(get_param(1));
    return 
1;
}

public 
_get_specialcount(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_get_specialcount needs 1 param(p1: %d)"pluginparamsget_param(1));

    return 
get_special_count(get_param(1));
}

public 
Float:_get_roundtime()
    return 
get_round_time();

public 
_get_playerdata(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_get_playerdata needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    return 
get_player_data(get_param(1), get_param(2));
}

public 
_set_playerdata(pluginparams)
{
    if(
params != 3)
        return 
ttt_log_api_error("ttt_set_playerdata needs 3 params(p1: %d, p2: %d, p3: %d)"pluginparamsget_param(1), get_param(2), get_param(3));

    new 
id get_param(1);
    new 
datatype get_param(2);
    
set_player_data(iddatatypeget_param(3));
    if(
datatype == PD_KARMATEMP)
        
karma_reset(id);

    return 
1;
}

public 
_get_globalinfo(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_get_globalinfo needs 1 param(p1: %d)"pluginparamsget_param(1));

    return 
g_iGlobalInfo[get_param(1)];
}

public 
_set_globalinfo(pluginparams)
{
    if(
params != 2)
        return 
ttt_log_api_error("ttt_set_globalinfo needs 2 params(p1: %d, p2: %d)"pluginparamsget_param(1), get_param(2));

    
g_iGlobalInfo[get_param(1)] = get_param(2);
    return 
1;
}

public 
_register_cvar(pluginparams)
{
    if(
params != 3)
        return 
ttt_log_api_error("ttt_register_cvar needs 3 params"pluginparams);

    static 
name[48], string[16], pluginname[48], description[128];
    
get_string(1namecharsmax(name));
    
get_string(2stringcharsmax(string));
    
get_string(3descriptioncharsmax(description));
    
get_plugin(pluginpluginnamecharsmax(pluginname));

    return 
new_register_cvar(namestringdescriptionpluginname);
}

public 
_add_exception(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_add_exception needs 1 param(p1: %d)"pluginparamsget_param(1));

    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == -2)
        {
            
g_iExceptionItems[i] = get_param(1);
            return 
1;
        }
    }

    return 
0;
}

public 
_find_exception(pluginparams)
{
    if(
params != 1)
        return 
ttt_log_api_error("ttt_find_exception needs 1 param(p1: %d)"pluginparamsget_param(1));

    new 
item get_param(1);
    static const 
size sizeof(g_iExceptionItems);
    for(new 
0sizei++)
    {
        if(
g_iExceptionItems[i] == item)
            return 
1;
    }

    return 
0;


cvars:

PHP Code:

"karma_cmd_points" "100" //how many points
"karma_cmd_time" "10" //minutes to wait to get again 

command:
say and say team: /karma


don't know if it s working due to no compiling posibility
PHP Code:

#include <timer_controller>
#include <ttt> 

you don't provide these includes. if it's not working post again here the problem and the above include files

JuanitoAlimana 03-28-2023 17:20

Re: [TTT] Give karma
 
//// give_karma.sma
//
// \give_karma.sma(57) : error 020: invalid symbol name ""
// \give_karma.sma(57) : error 001: expected token: ";", but found "const"
// \give_karma.sma(60) : error 001: expected token: ";", but found "public"
// \give_karma.sma(113) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(115) : error 001: expected token: ";", but found "if"
// \give_karma.sma(115) : error 035: argument type mismatch (argument 1)
// \give_karma.sma(118) : error 001: expected token: ";", but found "}"
// \give_karma.sma(121) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(122) : error 001: expected token: ";", but found "}"
// \give_karma.sma(129) : error 001: expected token: ";", but found "}"
// \give_karma.sma(135) : error 001: expected token: ";", but found "}"
// \give_karma.sma(138) : error 001: expected token: ";", but found "new"
// \give_karma.sma(139) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(141) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(142) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(144) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(147) : error 001: expected token: ";", but found "}"
// \give_karma.sma(152) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(182) : warning 233: symbol "client_disconnect" is marked as deprecated: Use client_disconnected() instead.
//
// \give_karma.sma(201) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(203) : error 001: expected token: ";", but found "-identifier-"
// \give_karma.sma(205) : error 001: expected token: ";", but found "if"
// \give_karma.sma(57) : warning 203: symbol is never used: ""
//
// 21 Errors.


All times are GMT -4. The time now is 08:47.

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