[ZP 5.0.8] Класс человека с способностью

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
418
Реакции
-7
Предупреждения
8
Привет всем, сделал класс человека с способностью неуязвимости на 10 секунд, но некорректно работает кулдаун и хотел бы поставить на кнопки ALT + E. вместо G (cmd drop). Кто поможет, буду благодарен)

C++:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <zp50_class_human>
#include <zp50_class_nemesis>
#include <zmvip>
#include <zp50_items>
#include <zombieplague>
#include <zp_level_system>

#define LVL_COUNT 20

// Invulnurable Attributes
new const humanclass1_name[] = "Invulnurable Human"
new const humanclass1_info[] = "[Invulnurability on ALT]"
new const humanclass1_models[][] = { "leet" }
const humanclass1_health = 150
const Float:humanclass1_speed = 1.0
const Float:humanclass1_gravity = 1.0

new g_human_invul

new godmode[33] = 0
new godmode_used[33] = 0
new godmode_cooldown[33]

new Float:alt_cooldown = 30.0
new Float:godmode_time = 10.0

new MsgSayText

public plugin_precache()
{
    register_plugin("[ZP] Class: Human: Invulnurable", ZP_VERSION_STRING, "_RedGamer_")
    register_clcmd("drop", "use_ability")

    register_forward( FM_PlayerPreThink, "client_prethink")
    register_logevent("roundStart", 2, "1=Round_Start")
    
    g_human_invul = zp_class_human_register(humanclass1_name, humanclass1_info, humanclass1_health, humanclass1_speed, humanclass1_gravity)
    new index
    for (index = 0; index < sizeof humanclass1_models; index++)
        zp_class_human_register_model(g_human_invul, humanclass1_models[index])

    MsgSayText = get_user_msgid("SayText")
}

public client_prethink(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        if (is_user_alive(id) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id) && (zp_class_human_get_current(id) == g_human_invul))
        Action(id)
    }
}

public Action(id)
{
    if (godmode[id] == 1)
    {
        set_user_godmode(id, 1)
    }
    else
    {
        set_user_godmode(id, 0)
    }
    return PLUGIN_HANDLED
}

public roundStart()
{
    for (new i = 1; i <= get_maxplayers(); i++)
    {
        godmode_cooldown[i] = floatround(alt_cooldown)
        godmode_used[i] = 0
        godmode[i] = 0
        remove_task(i)
    }
}

public ShowHUD(id)
{
    if (is_user_alive(id))
    {
        godmode_cooldown[id] = godmode_cooldown[id] - 1
        set_hudmessage(200, 100, 0, 0.80, 0.87, 0, 1.0, 1.1, 0.0, 0.0, -1)
        show_hudmessage(id, "[Неуязвимость: %d]", godmode_cooldown[id])
    }
    else
    {
        remove_task(id)
    }
}

public use_ability(id)
{
    if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        if (godmode_used[id] == 0)
        {
            set_user_rendering(id, kRenderFxGlowShell, 255, 165, 0, kRenderNormal, 0)

            godmode[id] = 1
            godmode_used[id] = 1
            set_task(godmode_time, "godmode_disable", id)

            godmode_cooldown[id] = floatround(alt_cooldown)
            set_task(1.0, "ShowHUD", id, _, _, "a", godmode_cooldown[id])
            set_user_godmode(id, 1)
            client_print(id, print_chat, "[TEST] - Ability used")
        }
    }
}

public godmode_disable(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        set_user_rendering(id)
        godmode[id] = 0
        set_task(alt_cooldown, "set_ability_godmode_cooldown", id)
        set_user_godmode(id, 0)
    }
}

public set_ability_godmode_cooldown(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_used[id] = 0
    }
}

public zp_fw_core_cure_pre(id)
{
    if (zp_class_human_get_next(id) == g_human_invul)
    {
        if (zp_level(id) < LVL_COUNT)
        {
            zp_colored_print(id, "^x01[^x04ZP^x01] Вы не достигли ^x04%d ^x01уровня!", LVL_COUNT)
            zp_class_human_set_next(id, 0)
        }
        else
        {
            zp_class_human_set_next(id, g_human_invul)
        }
    }
}

public zp_fw_core_cure_post(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_cooldown[id] = floatround(alt_cooldown)
        remove_task(id)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

public zp_fw_core_infect_post(id)
{
    remove_task(id)
}

zp_colored_print(target, const message[], any:...)
{
    static buffer[512], i, argscount
    argscount = numargs()
    
    if (!target)
    {
        static player
        for (player = 1; player <= get_maxplayers(); player++)
        {
            if (!is_user_connected(player))
                continue;
            
            static changed[5], changedcount
            changedcount = 0
            
            for (i = 2; i < argscount; i++)
            {
                if (getarg(i) == LANG_PLAYER)
                {
                    setarg(i, 0, player)
                    changed[changedcount] = i
                    changedcount++
                }
            }
            
            vformat(buffer, charsmax(buffer), message, 3)
            
            message_begin(MSG_ONE_UNRELIABLE, MsgSayText, _, player)
            write_byte(player)
            write_string(buffer)
            message_end()
            
            for (i = 0; i < changedcount; i++)
                setarg(changed[i], 0, LANG_PLAYER)
        }
    }
    else
    {
        vformat(buffer, charsmax(buffer), message, 3)
        
        message_begin(MSG_ONE, MsgSayText, _, target)
        write_byte(target)
        write_string(buffer)
        message_end()
    }
}
 
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
Потомучто таски, нужно создавать и удалять правильно, делать им айди разное! Использовать prethink для таких целей, это серьезно
 
Последнее редактирование:
Сообщения
104
Реакции
8
Не знаю как будет на ALT , но на Е это In_use через buttons использовать!
 
Сообщения
418
Реакции
-7
Предупреждения
8
Сделал так, всё работает, но cooldown стоит на 30с, худ пропадает через 30с, способность запускается повторно через 40с (игрового времени) как быть?
+ когда становлюсь зомби, неуязвимость (годмод) не обнуляется.

C++:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <zp50_class_human>
#include <zp50_class_nemesis>
#include <zmvip>
#include <zp50_items>
#include <zombieplague>
#include <zp_level_system>

#define LVL_COUNT 20

// Invulnurable Attributes
new const humanclass1_name[] = "Invulnurable Human"
new const humanclass1_info[] = "[Invulnurability on ALT]"
new const humanclass1_models[][] = { "leet" }
const humanclass1_health = 150
const Float:humanclass1_speed = 1.0
const Float:humanclass1_gravity = 1.0

new g_human_invul

new godmode[33] = 0
new godmode_used[33] = 0
new godmode_cooldown[33]

new Float:alt_cooldown = 30.0
new Float:godmode_time = 10.0

new MsgSayText
new g_maxplayers

public plugin_precache()
{
    register_plugin("[ZP] Class: Human: Invulnurable", ZP_VERSION_STRING, "_RedGamer_")

    register_forward( FM_PlayerPreThink, "client_prethink")
    register_logevent("roundStart", 2, "1=Round_Start")
    
    g_human_invul = zp_class_human_register(humanclass1_name, humanclass1_info, humanclass1_health, humanclass1_speed, humanclass1_gravity)
    new index
    for (index = 0; index < sizeof humanclass1_models; index++)
        zp_class_human_register_model(g_human_invul, humanclass1_models[index])

    MsgSayText = get_user_msgid("SayText")
    g_maxplayers = get_maxplayers()
}

public client_prethink(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id)){
            {
                use_ability(id)
                Action(id)
            }
        }
    }
}

public Action(id)
{
    if (godmode[id] == 1)
    {
        set_user_godmode(id, 1)
    }
    else
    {
        set_user_godmode(id, 0)
    }
    return PLUGIN_HANDLED
}

public roundStart()
{
    for (new i = 1; i <= g_maxplayers; i++)
    {
        godmode_cooldown[i] = floatround(alt_cooldown)
        godmode_used[i] = 0
        godmode[i] = 0
        remove_task(i)
    }
}

public ShowHUD(id)
{
    if (is_user_alive(id))
    {
        godmode_cooldown[id] -= 1
        set_hudmessage(200, 100, 0, 0.80, 0.87, 0, 1.0, 1.1, 0.0, 0.0, -1)
        show_hudmessage(id, "[Неуязвимость: %d]", godmode_cooldown[id])
    }
    else
    {
        remove_task(id)
    }
}

public use_ability(id)
{
    if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        if (pev(id, pev_button) & IN_USE && !(pev(id, pev_oldbuttons) & IN_USE))
        {
            if (godmode_used[id] == 0)
            {
                set_user_rendering(id, kRenderFxGlowShell, 255, 165, 0, kRenderNormal, 0)
                godmode[id] = 1
                godmode_used[id] = 1

                set_task(godmode_time, "godmode_disable", id)   
                godmode_cooldown[id] = floatround(alt_cooldown)

                set_task(1.0, "ShowHUD", id, _, _, "a", godmode_cooldown[id])
                set_user_godmode(id, 1)
                client_print(id, print_chat, "[TEST] - Ability used")       
            }
        }
    }
}

public godmode_disable(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        set_user_rendering(id)
        godmode[id] = 0
        set_task(alt_cooldown, "set_ability_godmode_cooldown", id)
        set_user_godmode(id, 0)
    }
}

public set_ability_godmode_cooldown(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_used[id] = 0
    }
}

public zp_fw_core_cure_pre(id)
{
    if (zp_class_human_get_next(id) == g_human_invul)
    {
        if (zp_level(id) < LVL_COUNT)
        {
            zp_colored_print(id, "^x01[^x04ZP^x01] Вы не достигли ^x04%d ^x01уровня!", LVL_COUNT)
            zp_class_human_set_next(id, 0)
        }
        else
        {
            zp_class_human_set_next(id, g_human_invul)
        }
    }
}

public zp_fw_core_cure_post(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_cooldown[id] = floatround(alt_cooldown)
        remove_task(id)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

public zp_fw_core_infect_pre(id)
{
    set_user_rendering(id)
    remove_task(id)
    godmode[id] = 0
    godmode_used[id] = 0
}

zp_colored_print(target, const message[], any:...)
{
    static buffer[512], i, argscount
    argscount = numargs()
    
    if (!target)
    {
        static player
        for (player = 1; player <= g_maxplayers; player++)
        {
            if (!is_user_connected(player))
                continue;
            
            static changed[5], changedcount
            changedcount = 0
            
            for (i = 2; i < argscount; i++)
            {
                if (getarg(i) == LANG_PLAYER)
                {
                    setarg(i, 0, player)
                    changed[changedcount] = i
                    changedcount++
                }
            }
            
            vformat(buffer, charsmax(buffer), message, 3)
            
            message_begin(MSG_ONE_UNRELIABLE, MsgSayText, _, player)
            write_byte(player)
            write_string(buffer)
            message_end()
            
            for (i = 0; i < changedcount; i++)
                setarg(changed[i], 0, LANG_PLAYER)
        }
    }
    else
    {
        vformat(buffer, charsmax(buffer), message, 3)
        
        message_begin(MSG_ONE, MsgSayText, _, target)
        write_byte(target)
        write_string(buffer)
        message_end()
    }
}
 
Сообщения
1,013
Реакции
198
Помог
6 раз(а)
А зачем вообще в prethink гонять условие?
 
Сообщения
1,013
Реакции
198
Помог
6 раз(а)
RedGamer, поставил бы на Е, чтобы при парашюте не использовалось, проверить игрок на земле или нет

При IN_USE (E) проверять сбросился ли кулдаун, счётчик не работает, потому что таск нужно делать каждую секунду и вычитать из переменной
 
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
RedGamer, ты понимашь что такое индекс таска?
Код:
set_task(godmode_time, "godmode_disable", id)
set_task(1.0, "ShowHUD", id, _, _, "a", godmode_cooldown[id])
set_task(alt_cooldown, "set_ability_godmode_cooldown", id)
При срабатывании remove_task(id), какая задача не сработает?
 
Сообщения
418
Реакции
-7
Предупреждения
8
RedGamer, ты понимашь что такое индекс таска?
Код:
set_task(godmode_time, "godmode_disable", id)
set_task(1.0, "ShowHUD", id, _, _, "a", godmode_cooldown[id])
set_task(alt_cooldown, "set_ability_godmode_cooldown", id)
При срабатывании remove_task(id), какая задача не сработает?
1 и 3?
Не особо понимаю, как индексы называть правильно..
 
Сообщения
104
Реакции
8
RedGamer, тебе же вроде по сути надо зациклить таск
Код:
set_task(1.0, "...", pPlayer + TASKID_WAIT_HUD, _, _, .flags = "b");
remove_task(pPlayer);
 
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
Kulogram,
Код:
set_task(1.0, "...", pPlayer + TASKID_WAIT_HUD, _, _, .flags = "b");
remove_task(pPlayer + TASKID_WAIT_HUD);
 
Сообщения
1,082
Реакции
58
Помог
11 раз(а)
Так его надо для начала объявить, что бы код твой понимал к чему обращаться)) к примеру: #define TASKID_WAIT_HUD 0x7G0H
14 Июн 2024
Если ты хочешь работать с каждым таском отдельно, то index таска, должен быть разным
 
Сообщения
104
Реакции
8
Code_0xABC, а можно просто без дефайна , вместо TASKID_WAIT_HUD просто ---> 11223311
Код:
set_task(1.0, "...", pPlayer + 112321, _, _, .flags = "b");
 
Сообщения
418
Реакции
-7
Предупреждения
8
Kulogram, да чёт напихал я тасков со своими индексами и всё пошло не по плану

C++:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <zp50_class_human>
#include <zp50_class_nemesis>
#include <zp50_items>
#include <zombieplague>
#include <zp_level_system>

#define LVL_COUNT 20

//ID Tasks
#define TIME_COOLDOWN 111
#define TIME_GODMODE 222

// Screen Fade
#define FADE_TIME 2048 // 1 sec. = 4096
#define HOLD_TIME 40960 // 2 sec. = 4096*2
#define FADE_IN 0x0000
#define R 255
#define G 160
#define B 0
#define FADE_ALPHA 100

// Invulnurable Attributes
new const humanclass1_name[] = "Invulnurable Human"
new const humanclass1_info[] = "[Invulnurability on ALT]"
new const humanclass1_models[][] = { "leet" }
const humanclass1_health = 150
const Float:humanclass1_speed = 1.0
const Float:humanclass1_gravity = 1.0

new g_human_invul

new godmode[33] = 0
new godmode_used[33] = 0
new godmode_cooldown[33]

new Float:alt_cooldown = 30.0
new Float:godmode_time = 10.0

new MsgSayText
new g_MsgScreenFade
new g_maxplayers

public plugin_precache()
{
    register_plugin("[ZP] Class: Human: Invulnurable", ZP_VERSION_STRING, "_RedGamer_")

    register_forward(FM_PlayerPreThink, "client_prethink")
    register_logevent("roundStart", 2, "1=Round_Start")
    
    g_human_invul = zp_class_human_register(humanclass1_name, humanclass1_info, humanclass1_health, humanclass1_speed, humanclass1_gravity)
    new index
    for (index = 0; index < sizeof humanclass1_models; index++)
        zp_class_human_register_model(g_human_invul, humanclass1_models[index])

    MsgSayText = get_user_msgid("SayText")
    g_MsgScreenFade = get_user_msgid("ScreenFade")
    g_maxplayers = get_maxplayers()
}

public client_prethink(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id)){
            {
                use_ability(id)
                Action(id)
            }
        }
    }
}

public Action(id)
{
    if (godmode[id] == 1)
    {
        set_user_godmode(id, 1)
    }
    else
    {
        set_user_godmode(id, 0)
    }
    return PLUGIN_HANDLED
}

public roundStart()
{
    for (new i = 1; i <= g_maxplayers; i++)
    {
        godmode_cooldown[i] = floatround(alt_cooldown)
        godmode_used[i] = 0
        godmode[i] = 0
        reset_values(i)
    }
}

public ShowHUD(id)
{
    if (is_user_alive(id))
    {
        godmode_cooldown[id] -= 1
        set_hudmessage(200, 100, 0, 0.80, 0.87, 0, 1.0, 1.1, 0.0, 0.0, -1)
        show_hudmessage(id, "[Неуязвимость: %d]", godmode_cooldown[id])
    }
    else
    {
        remove_task(id + 111)
    }
}

public use_ability(id)
{
    if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        if (pev(id, pev_button) & IN_USE && !(pev(id, pev_oldbuttons) & IN_USE))
        {
            if (godmode_used[id] == 0)
            {
                orange_screen(id)
                set_user_rendering(id, kRenderFxGlowShell, 255, 165, 0, kRenderNormal, 0)
                godmode[id] = 1
                godmode_used[id] = 1

                set_task(godmode_time, "godmode_disable", id + 222)   
                godmode_cooldown[id] = floatround(alt_cooldown)

                set_task(1.0, "ShowHUD", id + 111, _, _, "a", godmode_cooldown[id])
                set_user_godmode(id, 1)
                client_print(id, print_chat, "[TEST] - Ability used")       
            }
        }
    }
}

public godmode_disable(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        set_user_rendering(id)
        godmode[id] = 0
        set_task(alt_cooldown, "set_ability_godmode_cooldown", id + 111)
        set_user_godmode(id, 0)
    }
}

public orange_screen(id)
{
    message_begin(MSG_ONE, g_MsgScreenFade, _, id)
    write_short(FADE_TIME)
    write_short(HOLD_TIME)
    write_short(FADE_IN)
    write_byte(R)
    write_byte(G)
    write_byte(B)
    write_byte(FADE_ALPHA)
    message_end()
}

public set_ability_godmode_cooldown(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_used[id] = 0
    }
}

public reset_values(id)
{
    remove_task(id + 111)
    remove_task(id + 222)
}

public zp_fw_core_cure_pre(id)
{
    if (zp_class_human_get_next(id) == g_human_invul)
    {
        if (zp_level(id) < LVL_COUNT)
        {
            zp_colored_print(id, "^x01[^x04ZP^x01] Вы не достигли ^x04%d ^x01уровня!", LVL_COUNT)
            zp_class_human_set_next(id, 0)
        }
        else
        {
            zp_class_human_set_next(id, g_human_invul)
        }
    }
}

public zp_fw_core_cure_post(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_cooldown[id] = floatround(alt_cooldown)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

public zp_fw_core_infect_post(id)
{
    if (zp_get_user_zombie(id) || zp_get_user_nemesis(id))
    {
        set_user_rendering(id)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

zp_colored_print(target, const message[], any:...)
{
    static buffer[512], i, argscount
    argscount = numargs()
    
    if (!target)
    {
        static player
        for (player = 1; player <= g_maxplayers; player++)
        {
            if (!is_user_connected(player))
                continue;
            
            static changed[5], changedcount
            changedcount = 0
            
            for (i = 2; i < argscount; i++)
            {
                if (getarg(i) == LANG_PLAYER)
                {
                    setarg(i, 0, player)
                    changed[changedcount] = i
                    changedcount++
                }
            }
            
            vformat(buffer, charsmax(buffer), message, 3)
            
            message_begin(MSG_ONE_UNRELIABLE, MsgSayText, _, player)
            write_byte(player)
            write_string(buffer)
            message_end()
            
            for (i = 0; i < changedcount; i++)
                setarg(changed[i], 0, LANG_PLAYER)
        }
    }
    else
    {
        vformat(buffer, charsmax(buffer), message, 3)
        
        message_begin(MSG_ONE, MsgSayText, _, target)
        write_byte(target)
        write_string(buffer)
        message_end()
    }
}
 
Сообщения
418
Реакции
-7
Предупреждения
8
Помогите с тасками разобраться и с невиданным бессмертием зомбака от этой способности..
 
Сообщения
104
Реакции
8
RedGamer, я бы помог тебе, но у меня нет инклудов таких для компиляции и проверить нет где(
Попробуй этот вариант, но не уверен что будет работать )
Код:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <zp50_class_human>
#include <zp50_class_nemesis>
#include <zp50_items>
#include <zombieplague>
#include <zp_level_system>

#define LVL_COUNT 20

//ID Tasks
#define TIME_COOLDOWN 111
#define TIME_GODMODE 222
#define TASKID_WAIT_HUD 7721

// Screen Fade
#define FADE_TIME 2048 // 1 sec. = 4096
#define HOLD_TIME 40960 // 2 sec. = 4096*2
#define FADE_IN 0x0000
#define R 255
#define G 160
#define B 0
#define FADE_ALPHA 100

// Invulnurable Attributes
new const humanclass1_name[] = "Invulnurable Human"
new const humanclass1_info[] = "[Invulnurability on ALT]"
new const humanclass1_models[][] = { "leet" }
const humanclass1_health = 150
const Float:humanclass1_speed = 1.0
const Float:humanclass1_gravity = 1.0

new g_human_invul

new godmode[33] = 0
new godmode_used[33] = 0
new godmode_cooldown[33]

new Float:alt_cooldown = 30.0
new Float:godmode_time = 10.0

new MsgSayText
new g_MsgScreenFade
new g_maxplayers

public plugin_precache()
{
    register_plugin("[ZP] Class: Human: Invulnurable", ZP_VERSION_STRING, "_RedGamer_")
    
    register_forward(FM_PlayerPreThink, "client_prethink")
    register_logevent("roundStart", 2, "1=Round_Start")
    
    g_human_invul = zp_class_human_register(humanclass1_name, humanclass1_info, humanclass1_health, humanclass1_speed, humanclass1_gravity)
    new index
    for (index = 0; index < sizeof humanclass1_models; index++)
    zp_class_human_register_model(g_human_invul, humanclass1_models[index])
    
    MsgSayText = get_user_msgid("SayText")
    g_MsgScreenFade = get_user_msgid("ScreenFade")
    g_maxplayers = get_maxplayers()
}

public client_prethink(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id)){
            {
                use_ability(id)
                Action(id)
            }
        }
    }
}

public Action(id)
{
    if (godmode[id] == 1)
    {
        set_user_godmode(id, 1)
    }
    else
    {
        set_user_godmode(id, 0)
    }
    return PLUGIN_HANDLED
}

public roundStart()
{
    for (new i = 1; i <= g_maxplayers; i++)
    {
        godmode_cooldown[i] = floatround(alt_cooldown)
        godmode_used[i] = 0
        godmode[i] = 0
        reset_values(i)
    }
}

public ShowHUD(id)
{
    new id = TASKID_WAIT_HUD;
    if (is_user_alive(id))
    {
        godmode_cooldown[id] -= 1
        set_hudmessage(200, 100, 0, 0.80, 0.87, 0, 1.0, 1.1, 0.0, 0.0, -1)
        show_hudmessage(id, "[Неуязвимость: %d]", godmode_cooldown[id])
    }
    else
    {
        remove_task(id + TASKID_WAIT_HUD)
    }
}

public use_ability(id)
{
    if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        if (pev(id, pev_button) & IN_USE && !(pev(id, pev_oldbuttons) & IN_USE))
        {
            if (godmode_used[id] == 0)
            {
                orange_screen(id)
                set_user_rendering(id, kRenderFxGlowShell, 255, 165, 0, kRenderNormal, 0)
                godmode[id] = 1
                godmode_used[id] = 1
                
                godmode_cooldown[id] = floatround(alt_cooldown)
                
                //set_task(1.0, "ShowHUD", id + 111, _, _, "a", godmode_cooldown[id])
                set_user_godmode(id, 1)
                client_print(id, print_chat, "[TEST] - Ability used")
                set_task(1.0, "ShowHUD", id + TASKID_WAIT_HUD, _, _, .flags = "b");
                
                set_task(godmode_time, "godmode_disable", id + TIME_GODMODE); 
            }
        }
    }
}

public godmode_disable(id)
{
    new id = TIME_COOLDOWN;
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        set_user_rendering(id)
        godmode[id] = 0
        set_task(alt_cooldown, "set_ability_godmode_cooldown", id + TIME_COOLDOWN)
        set_user_godmode(id, 0)
    }
}

public orange_screen(id)
{
    message_begin(MSG_ONE, g_MsgScreenFade, _, id)
    write_short(FADE_TIME)
    write_short(HOLD_TIME)
    write_short(FADE_IN)
    write_byte(R)
    write_byte(G)
    write_byte(B)
    write_byte(FADE_ALPHA)
    message_end()
}

public set_ability_godmode_cooldown(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_used[id] = 0
    }
}

public reset_values(id)
{
    remove_task(id + TIME_COOLDOWN)
    remove_task(id + TIME_GODMODE)
}

public zp_fw_core_cure_pre(id)
{
    if (zp_class_human_get_next(id) == g_human_invul)
    {
        if (zp_level(id) < LVL_COUNT)
        {
            zp_colored_print(id, "^x01[^x04ZP^x01] Вы не достигли ^x04%d ^x01уровня!", LVL_COUNT)
            zp_class_human_set_next(id, 0)
        }
        else
        {
            zp_class_human_set_next(id, g_human_invul)
        }
    }
}

public zp_fw_core_cure_post(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        godmode_cooldown[id] = floatround(alt_cooldown)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

public zp_fw_core_infect_post(id)
{
    if (zp_get_user_zombie(id) || zp_get_user_nemesis(id))
    {
        set_user_rendering(id)
        godmode[id] = 0
        godmode_used[id] = 0
    }
}

zp_colored_print(target, const message[], any:...)
{
    static buffer[512], i, argscount
    argscount = numargs()
    
    if (!target)
    {
        static player
        for (player = 1; player <= g_maxplayers; player++)
        {
            if (!is_user_connected(player))
            continue;
            
            static changed[5], changedcount
            changedcount = 0
            
            for (i = 2; i < argscount; i++)
            {
                if (getarg(i) == LANG_PLAYER)
                {
                    setarg(i, 0, player)
                    changed[changedcount] = i
                    changedcount++
                }
            }
            
            vformat(buffer, charsmax(buffer), message, 3)
            
            message_begin(MSG_ONE_UNRELIABLE, MsgSayText, _, player)
            write_byte(player)
            write_string(buffer)
            message_end()
            
            for (i = 0; i < changedcount; i++)
            setarg(changed[i], 0, LANG_PLAYER)
        }
    }
    else
    {
        vformat(buffer, charsmax(buffer), message, 3)
        
        message_begin(MSG_ONE, MsgSayText, _, target)
        write_byte(target)
        write_string(buffer)
        message_end()
    }
}
 
Сообщения
812
Реакции
510
Помог
12 раз(а)
незачем вам миллион тасков
пресинк заменил на objcaps, т.к. кнопку E зажимаете
в 67 строке добавил проверку на кнопку перезарядки, т.е. чтобы вызвать спелл надо зажимать E + R
худ переделал немного

PHP:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <fun>
#include <zp50_class_human>
#include <zp50_class_nemesis>
#include <zp50_items>
#include <zombieplague>
#include <zp_level_system>

#define LVL_COUNT 20

//ID Tasks
#define TASKID_WAIT_HUD 7721

// Screen Fade
#define FADE_TIME 2048 // 1 sec. = 4096
#define HOLD_TIME 40960 // 2 sec. = 4096*2
#define FADE_IN 0x0000
#define R 255
#define G 160
#define B 0
#define FADE_ALPHA 100

// Invulnurable Attributes
new const humanclass1_name[] = "Invulnurable Human"
new const humanclass1_info[] = "[Invulnurability on ALT]"
new const humanclass1_models[][] = { "leet" }
const humanclass1_health = 150
const Float:humanclass1_speed = 1.0
const Float:humanclass1_gravity = 1.0

new g_human_invul

new Float:g_flGodmode_cooldown[33], Float:g_flGodmode_spelltime[33];

new Float:alt_cooldown = 30.0
new Float:godmode_time = 10.0

new MsgSayText
new g_MsgScreenFade
new g_maxplayers

public plugin_precache()
{
    register_plugin("[ZP] Class: Human: Invulnurable", ZP_VERSION_STRING, "_RedGamer_")
   
    RegisterHam(Ham_ObjectCaps, "player", "fw_PlayerPressUse");
    register_logevent("roundStart", 2, "1=Round_Start")
   
    g_human_invul = zp_class_human_register(humanclass1_name, humanclass1_info, humanclass1_health, humanclass1_speed, humanclass1_gravity)
    new index
    for (index = 0; index < sizeof humanclass1_models; index++)
    zp_class_human_register_model(g_human_invul, humanclass1_models[index])
   
    MsgSayText = get_user_msgid("SayText")
    g_MsgScreenFade = get_user_msgid("ScreenFade")
    g_maxplayers = get_maxplayers()
}

public fw_PlayerPressUse(id)
{
    if (zp_class_human_get_current(id) == g_human_invul)
    {
        if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id)){
            {
                if (pev(id, pev_button) & IN_RELOAD) {
                    use_ability(id);
                }
            }
        }
    }
}

public roundStart()
{
    for (new i = 1; i <= g_maxplayers; i++)
    {
        g_flGodmode_cooldown[i] = 0.0;
        reset_values(i)
    }
}

public ShowHUD(id)
{
    new id = TASKID_WAIT_HUD;
    if (is_user_alive(id))
    {
        new Float:flGameTime = get_gametime();

        new szText[64];
        // Cooldown
        if (g_flGodmode_cooldown[id] > flGameTime) {
           
            formatex(szText, charsmax(szText), "[Перезарядка: %.0f]", g_flGodmode_cooldown[id] - flGameTime);
        }
        else {
            remove_task(id + TASKID_WAIT_HUD);
            g_flGodmode_cooldown[id] = 0.0;
        }

        // время действия спелла неуязв.
        if (g_flGodmode_spelltime[id]) {

            if (g_flGodmode_spelltime[id] < flGameTime) {
                set_user_rendering(id);
                set_user_godmode(id, 0);

                g_flGodmode_spelltime[id] = 0.0;
            }
            else {
                formatex(szText, charsmax(szText), "[Неуязвимость: %.0f]", g_flGodmode_spelltime[id] - flGameTime);
            }
        }

        if (szText[0] != EOS) {
            set_hudmessage(200, 100, 0, 0.80, 0.87, 0, 1.0, 1.1, 0.0, 0.0, -1);
            show_hudmessage(id, szText);
        }
    }
    else
    {
        remove_task(id + TASKID_WAIT_HUD);

        if (is_user_connected(id)) {

            // по идее в спавне должно ресетаться , но я в этом не уверен
            set_user_godmode(id, 0);
        }
    }
}

public use_ability(id)
{
    if (is_user_alive(id) && (zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        if (pev(id, pev_button) & IN_USE && !(pev(id, pev_oldbuttons) & IN_USE))
        {
            new Float:flGameTime = get_gametime();

            // if (!g_flGodmode_cooldown[id] && g_flGodmode_cooldown[id] > flGameTime)
            if (!g_flGodmode_cooldown[id])
            {
                orange_screen(id)
                set_user_rendering(id, kRenderFxGlowShell, 255, 165, 0, kRenderNormal, 0)
               
                g_flGodmode_cooldown[id] = flGameTime + alt_cooldown + godmode_time; // Время перезарядки начинается после окончания спела неуязв.
                g_flGodmode_spelltime[id] = flGameTime + godmode_time;

                set_user_godmode(id, 1)
                client_print(id, print_chat, "[TEST] - Ability used")
                set_task(1.0, "ShowHUD", id + TASKID_WAIT_HUD, _, _, .flags = "b");
            }
            else {
                client_print(id, print_center, "[ Перезарядка: %.0f ]", g_flGodmode_cooldown[id] - flGameTime);
            }
        }
    }
}

public orange_screen(id)
{
    message_begin(MSG_ONE, g_MsgScreenFade, _, id)
    write_short(FADE_TIME)
    write_short(HOLD_TIME)
    write_short(FADE_IN)
    write_byte(R)
    write_byte(G)
    write_byte(B)
    write_byte(FADE_ALPHA)
    message_end()
}

public reset_values(id)
{
    remove_task(id + TASKID_WAIT_HUD);
    g_flGodmode_cooldown[id] = 0.0;
    g_flGodmode_spelltime[id] = 0.0;
}

public zp_fw_core_cure_pre(id)
{
    if (zp_class_human_get_next(id) == g_human_invul)
    {
        if (zp_level(id) < LVL_COUNT)
        {
            zp_colored_print(id, "^x01[^x04ZP^x01] Вы не достигли ^x04%d ^x01уровня!", LVL_COUNT)
            zp_class_human_set_next(id, 0)
        }
        else
        {
            zp_class_human_set_next(id, g_human_invul)
        }
    }
}

public zp_fw_core_cure_post(id)
{
    if ((zp_class_human_get_current(id) == g_human_invul) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id))
    {
        reset_values(id);
    }
}

public zp_fw_core_infect_post(id)
{
    if (zp_get_user_zombie(id) || zp_get_user_nemesis(id))
    {
        set_user_rendering(id);
        reset_values(id);
    }
}

stock zp_colored_print(target, const message[], any:...)
{
    static buffer[512], i, argscount
    argscount = numargs()
   
    if (!target)
    {
        static player
        for (player = 1; player <= g_maxplayers; player++)
        {
            if (!is_user_connected(player))
            continue;
           
            static changed[5], changedcount
            changedcount = 0
           
            for (i = 2; i < argscount; i++)
            {
                if (getarg(i) == LANG_PLAYER)
                {
                    setarg(i, 0, player)
                    changed[changedcount] = i
                    changedcount++
                }
            }
           
            vformat(buffer, charsmax(buffer), message, 3)
           
            message_begin(MSG_ONE_UNRELIABLE, MsgSayText, _, player)
            write_byte(player)
            write_string(buffer)
            message_end()
           
            for (i = 0; i < changedcount; i++)
            setarg(changed[i], 0, LANG_PLAYER)
        }
    }
    else
    {
        vformat(buffer, charsmax(buffer), message, 3)
       
        message_begin(MSG_ONE, MsgSayText, _, target)
        write_byte(target)
        write_string(buffer)
        message_end()
    }
}
 
Последнее редактирование:
Сообщения
418
Реакции
-7
Предупреждения
8
BalbuR, спасибо большое, буду дома, попробую. Про get_gametime были мысли, но не мог сообразить куда это записать)
 
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу