Item shop plugin_handled not working

Сообщения
47
Реакции
1
Hello, basically i have this item shop, where people can buy things off, every item can be made like in zombie plague extra shop, its like an API. For example i have armor, people can buy 100 armor for theirselves, but i want the armor limitation to be set, for example 1 time per round.
Problem starts when i buy it off the extra item shop, first time is all good for the armor plugin, but when i buy the second time, the shop still removes my money(says i bought it), but the armor plugin says that i have reached my limit.
Can anyone help?

Here is the menu handler for the API shop:
C++:
public menu1_handle_human(id, menu, item)
{
    if(item == MENU_EXIT || is_user_zombie(id))
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    
    static data[6], szName[64], access, callback
    static temp_integer1
    menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
    
    temp_integer1 = str_to_num(data)
    
    static cost, wp_name[64], wp_desc[64]
    cost = ArrayGetCell(Item_Cost, temp_integer1)
    ArrayGetString(Item_Name, temp_integer1, wp_name, sizeof(wp_name))
    ArrayGetString(Item_Desc, temp_integer1, wp_desc, sizeof(wp_desc))
    
    if(cs_get_user_money(id) >= cost)
    {
        client_printc(id, "!g*!n You bought !t%s!n for !g%i$!n!", wp_name, cost)
        
        cs_set_user_money(id, cs_get_user_money(id) - cost)
        
        static g_dummy
        ExecuteForward(g_selected_forward, g_dummy, id, temp_integer1)
    } else {
        client_printc(id, "!g*!n You don't have enough money for !t%s!n (price: !g%i$!n)", wp_name, cost)
    }
        // i guess soemthing is wrong here?
    return PLUGIN_CONTINUE
}

Is there a missing forward at the end? So it works with my armor plugin?

Here is armor plugin example:
C++:
if (itemid == g_itemid_humanarmor)
    {
        if(is_user_zombie(player))
            return PLUGIN_HANDLED

        else if(pev(player, pev_armorvalue) >= g_armor_limit)
        {
            client_print_color(player, print_chat, "^4* ^1You already have maxed your armor!")
            return PLUGIN_HANDLED
        }

        else if(g_ItemCount[player] >= 1)
        {
            client_print_color(player, print_chat, "^4* ^1You can buy armor only^3 1 ^1time in a round!")
            return PLUGIN_HANDLED
        }
        else
        {
        g_ItemCount[player]++
        set_pev(player, pev_armorvalue, float(min(pev(player, pev_armorvalue)+g_armor_amount, g_armor_limit)))
        engfunc(EngFunc_EmitSound, player, CHAN_BODY, g_sound_buyarmor, 1.0, ATTN_NORM, 0, PITCH_NORM)
        }
    }
 
Сообщения
677
Реакции
579
Предупреждения
8
Помог
9 раз(а)
В апи плагине не реализована обратная связь вот и вся проблема. Как минимум нужен что-то типа ITEM_PURCHASED и ITEM_IGNORE для апи.

А на армор плагине надо правильнее юзать просто условие "if" вместо "else if" ну и последний "else" не нужен.
 
Сообщения
47
Реакции
1
Feedback is not implemented in the api plugin, that's the whole problem. At least you need something like ITEM_PURCHASED and ITEM_IGNORE for api.

And on the armor plugin, it is more correct to use just the "if" condition instead of "else if" and the last "else" is not needed.
Are there any examples on internet on how could i do that?
 
Сообщения
47
Реакции
1
Sorry for double post, but i cant edit my last post.
I think im getting really close, but it seems not to work, it still removes money and says that i bought the item.

C++:
if(cs_get_user_money(id) >= cost)
    {
        client_printc(id, "!g*!n You bought !t%s!n for !g%i$!n!", wp_name, cost)
       
        cs_set_user_money(id, cs_get_user_money(id) - cost)
       
        static g_dummy
        ExecuteForward(g_selected_forward, g_dummy, id, temp_integer1)
    } else {
        client_printc(id, "!g*!n You don't have enough money for !t%s!n (price: !g%i$!n)", wp_name, cost)
        // i added this but it doesnt still work
        temp_integer1++
        ExecuteForward(g_selected_forward, g_forward_return, id, temp_integer1)
        if (g_forward_return >= BIO_PLUGIN_HANDLED)
        cs_set_user_money(id, cost)
    }
 
Сообщения
677
Реакции
579
Предупреждения
8
Помог
9 раз(а)
Foxculated, Ваш способ костыль. Вам нужно использовать static g_dummy (это значение return) да возьмите и смотрите любой shop плагин (их полно) как она работает.
 
Сообщения
47
Реакции
1
Foxculated, Ваш способ костыль. Вам нужно использовать static g_dummy (это значение return) да возьмите и смотрите любой shop плагин (их полно) как она работает.
Thanks for help, i did something like this based on shop plugin i found, but now it doesnt give me the item when i buy it, the console sends no logs about it.
C++:
    static g_dummy

    if(cs_get_user_money(id) <= cost) {
        client_printc(id, "!g*!n You don't have enough money for !t%s!n (price: !g%i$!n)", wp_name, cost)
        return PLUGIN_HANDLED
    }

    temp_integer1++
    ExecuteForward(g_selected_forward, g_dummy, id, temp_integer1)
    if (g_dummy >= BIO_PLUGIN_HANDLED)
    cs_set_user_money(id, cost)
       
    return PLUGIN_CONTINUE
 
Сообщения
677
Реакции
579
Предупреждения
8
Помог
9 раз(а)
temp_integer1++

Что это ? И зачем вызвать форвард 2 раза? Короче ищите и изучайте как это работает если есть интерес.
 
Сообщения
47
Реакции
1
So this is the menu handler right now... Could anyone help me please what should i do?
When i try to buy item, it doesnt respond, it gives 0 information.

C++:
public menu1_handle_human(id, menu, item)
{
    if(item == MENU_EXIT || is_user_zombie(id))
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    
    static data[6], szName[64], access, callback
    static temp_integer1
    menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
    
    temp_integer1 = str_to_num(data)
    
    static cost, wp_name[64], wp_desc[64]
    cost = ArrayGetCell(Item_Cost, temp_integer1)
    ArrayGetString(Item_Name, temp_integer1, wp_name, sizeof(wp_name))
    ArrayGetString(Item_Desc, temp_integer1, wp_desc, sizeof(wp_desc))

    if(cs_get_user_money(id) <= cost) {
        client_printc(id, "!g*!n You don't have enough money for !t%s!n (price: !g%i$!n)", wp_name, cost)
        return PLUGIN_HANDLED
    }

    static g_dummy

    ExecuteForward(g_selected_forward, g_dummy, id, temp_integer1)
    if (g_dummy >= BIO_PLUGIN_HANDLED)
    cs_set_user_money(id, cost)
        
    return PLUGIN_HANDLED
}
 
Сообщения
47
Реакции
1
Thanks for your help, i tried Ocixcrom shop API, but it didnt fit my needs...
I wanted just something simple for myself.

I managed to make the code work, but now it doesnt remove my money for purchase, it just gives me the item... Someone can help me please?

C++:
static g_dummy

    ExecuteForward(g_selected_forward, g_dummy, id, temp_integer1)
    if (g_dummy >= BIO_PLUGIN_HANDLED)
    cs_set_user_money(id, cs_get_user_money(id) - cost)
        
return PLUGIN_HANDLED
 
Сообщения
677
Реакции
579
Предупреждения
8
Помог
9 раз(а)
Что за BIO_PLUGIN_HANDLED?
Возвращается ли это значение в плагине предмета?
Зачем использовать static везде? (даже там где не нужно)

cs_get_user_money(id) <= cost
Почему игрок не может взять предмет если у него деньги равно к стоимости предмета?

Почему не используйте таб? Код в одном столбце с условиями не читабельно и непредсказуемо.

Я могу конечно скинуть вам готовое решение но это не интересно.
 
Сообщения
47
Реакции
1
What is BIO_PLUGIN_HANDLED?
Is this value returned in the item plugin?
Why use static everywhere? (even where not needed)

cs_get_user_money(id) <= cost
Why can't a player take an item if he has money equal to the cost of the item?

Why don't you use tab? Code in one column with conditions is not readable and unpredictable.

Of course, I can throw you a ready-made solution, but it's not interesting.
Hello.
I made in .inc #define BIO_PLUGIN_HANDLED 97, its a custom forwarded return.

Google translate is kinda bad, but i updated the script
Now is the problem that i can buy the item, but the money doesnt get spent. It stays always on 16000, but the item is rewarded.

Here is an example video of what the bug is: https://imgur.com/a/rkb3bl9

C++:
public menu1_handle_human(id, menu, item)
{
    if(item == MENU_EXIT || is_user_zombie(id))
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
  
    new data[6], szName[64], access, callback
    new item_id
    menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
  
    item_id = str_to_num(data)
  
    static cost, wp_name[64]
    cost = ArrayGetCell(Item_Cost, item_id)

    ArrayGetArray(Item_Name, item_id, wp_name)

    if(cs_get_user_money(id) >= cost) cs_set_user_money(id, cs_get_user_money(id) - cost)
    else {
        client_printc(id, "!g*!n You don't have enough money for !t%s!n (price: !g%i$!n)", wp_name, cost)
        return PLUGIN_HANDLED
    }
  
    ExecuteForward(g_selected_forward, g_dummy, id, item_id)
    if (g_dummy >= BIO_PLUGIN_HANDLED)
    cs_set_user_money(id, cost)

    menu_destroy(menu)
    return PLUGIN_HANDLED
}
 
Последнее редактирование:
Сообщения
47
Реакции
1
I think its working now, but is there an option that if BIO_PLUGIN_HANDLED is called, then dont flash the money? Because if it is called my money is set back to as it was, and it flashes, is there a way it doesnt flash?

C++:
new money = cs_get_user_money(id);

    if(cs_get_user_money(id) >= cost) cs_set_user_money(id, cs_get_user_money(id) - cost)
    else {
        client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
        return PLUGIN_HANDLED
    }
    
    ExecuteForward(g_selected_forward, g_dummy, id, item_id)
    if (g_dummy >= BIO_PLUGIN_HANDLED)
    cs_set_user_money(id, money, 0)
 
Сообщения
673
Реакции
242
Помог
11 раз(а)
Код:
new money = cs_get_user_money(id);

ExecuteForward(g_selected_forward, g_dummy, id, item_id)

if (g_dummy >= BIO_PLUGIN_HANDLE)
{
    return PLUGIN_HANDLED
}

if(cs_get_user_money(id) < cost)
{
    client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
    return PLUGIN_HANDLED
}

cs_set_user_money(id, cs_get_user_money(id) - cost)
 
Сообщения
47
Реакции
1
Код:
new money = cs_get_user_money(id);

ExecuteForward(g_selected_forward, g_dummy, id, item_id)

if (g_dummy >= BIO_PLUGIN_HANDLE)
{
    return PLUGIN_HANDLED
}

if(cs_get_user_money(id) < cost)
{
    client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money");
    return PLUGIN_HANDLED
}

cs_set_user_money(id, cs_get_user_money(id) - cost)
Thanks, working.
11 Июн 2023
Can't edit my post anymore, the money is not removed for purchase...
11 Июн 2023
Thanks, working.
11 Июн 2023

EDIT: I can buy armor for 3000 if i have 800 money.. How is that?
 
Сообщения
673
Реакции
242
Помог
11 раз(а)
Foxculated, у тебя зомби? за деньги какой натив отвечает?
 
Сообщения
673
Реакции
242
Помог
11 раз(а)
@Foxculated,покажи весь код брони
 
Сообщения
47
Реакции
1
@Foxculated, show me the whole armor code
C++:
#include <amxmodx>
#include <fakemeta>
#include <biohazard>
#include <bio_shop>

new const g_item_name[] = { "ARMOR" }
new const g_item_description[] = { "(100 ARMOR)" }
const g_item_cost = 3000

new const g_sound_buyarmor[] = { "items/tr_kevlar.wav" }
const g_armor_amount = 100
const g_armor_limit = 100

new g_ItemCount[33]

new g_itemid_humanarmor

public plugin_precache()
{
    precache_sound(g_sound_buyarmor)
}

public plugin_init()
{
    register_plugin("Armor", "1.0", "BIOHAZARD")
    register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")

    g_itemid_humanarmor = bio_register_item(g_item_name, g_item_cost, g_item_description, TEAM_HUMAN)
}

public bio_item_selected(player, itemid)
{
    if (itemid == g_itemid_humanarmor)
    {
        if(is_user_zombie(player))
            return BIO_PLUGIN_HANDLED

        if(pev(player, pev_armorvalue) >= g_armor_limit)
        {
            client_print_color(player, print_chat, "^4* ^1You already have maxed your armor!")
            return BIO_PLUGIN_HANDLED
        }

        if(g_ItemCount[player] >= 1)
        {
            client_print_color(player, print_chat, "^4* ^1You can buy armor only^3 1 ^1time in a round!")
            return BIO_PLUGIN_HANDLED
        }
        g_ItemCount[player]++
        set_pev(player, pev_armorvalue, float(min(pev(player, pev_armorvalue)+g_armor_amount, g_armor_limit)))
        engfunc(EngFunc_EmitSound, player, CHAN_BODY, g_sound_buyarmor, 1.0, ATTN_NORM, 0, PITCH_NORM)
    }
    return PLUGIN_CONTINUE
}

public EVENT_round_start()
{
    for (new id; id <= 32; id++) g_ItemCount[id] = 0;
}
 

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

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