• Гость, перед открытием темы прочитай описание раздела, чтобы не ошибиться. Любые вопросы по настройке сервера создаются в разделе Технической Поддержки.

Помощь Монеты уходят в минус при покупке

Romik67ru

Участник
Сообщения
22
Симпатии
0
Баллы
57
#1
Есть 2 плагина:
1. Система коинов
2. Магазин за эти коины.

Всё работает, но купить "VIP на карту" можно даже с 0 балансом. Монеты уходят в минус.
Другие пункты вроде бы работают, т.к купить их с 0 балансом нельзя.
 

Romik67ru

Участник
Сообщения
22
Симпатии
0
Баллы
57
#2
Код:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Coins System"
#define VERSION "1.1"
#define AUTHOR "6u3oH"

#define CLASSNAME_DEFAULT "info_null"
#define CLASSNAME_SET "info_coin"
#define PATH_DATABASE "addons/amxmodx/data/coins_system.dat"
#define COIN_MODEL "models/anti_coin/bitcoins.mdl"
#define COIN_SOUND "coin/coin.wav"

#define PDATA_KILLHEAD_OFFSET 75
#define PDATA_PLAYER_OFFSET 5

/*----------------------------------------------------------
 ------------------------ Настройки ------------------------
 ---------------------------------------------------------*/

#define VIP_FLAG ADMIN_LEVEL_H

#define COIN_GIVE_KILL 1 // Сколько монет давать за простое убийство
#define COIN_GIVE_KILL_HEAD 2 // Сколько монет давать за убийство в голову
#define COIN_GIVE_KILL_KNIFE 3 // Сколько монет давать за убийство ножом

#define COIN_DROP_COINS // Закоментируйте строку, чтобы монеты с игрока не выпадали
#define COIN_NUM_DROPKILL_MIN 1 // Минимальное кол-во монет, выпадающих при смерти игрока
#define COIN_NUM_DROPKILL_MAX 1 // Максимальное кол-во монет, выпадающих при смерти игрока

#define COIN_TIME_REMOVE 30 // Через сколько секунд удаляются выпавшие монеты (закоментриуйте, чтобы удалялись только в конце раунда)

/*----------------------------------------------------------
 ------------------------ Настройки ------------------------
 ---------------------------------------------------------*/

new g_iMaxPlayers;
new g_iCoin[33];

public plugin_precache()
{
    precache_model(COIN_MODEL);
    precache_sound(COIN_SOUND);
}

public plugin_cfg() write_file(PATH_DATABASE, "[База данных] [Coins System]", 0);
public client_connect(id) load_coins(id);
public client_disconnected(id) save_coins(id);

public plugin_natives()
{
    register_native("get_user_coins", "get_user_coins", true)
    register_native("set_user_coins", "set_user_coins", true)
}

public get_user_coins(id) return g_iCoin[id];
public set_user_coins(id, iNum) g_iCoin[id] = iNum;

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
    
    RegisterHam(Ham_Killed, "player", "fw_KilledPlayerPost", true);
    
    #if defined COIN_DROP_COINS
        RegisterHam(Ham_Touch, CLASSNAME_DEFAULT, "fw_TouchCoinPost", true);
        register_event("HLTV", "Event_RoundStart", "a", "1=0", "2=0");
        #if defined COIN_TIME_REMOVE
            RegisterHam(Ham_Think, CLASSNAME_DEFAULT, "fw_ThinkCoinPost", true);
        #endif
    #endif

    g_iMaxPlayers = get_maxplayers();
    set_task(2.0, "Task_HudMsg", .flags = "b");
}

public fw_KilledPlayerPost(iVictim, iAttacker, iCorpse)
{
    if(!is_user_connected(iVictim))
        return;
    
    #if defined COIN_DROP_COINS
    if(g_iCoin[iVictim] > 0)
    {
        new Float: fOrigin[3], Float: fVelocity[3];
        pev(iVictim, pev_origin, fOrigin);
        
        new iRandom = random_num(COIN_NUM_DROPKILL_MIN, COIN_NUM_DROPKILL_MAX);
        
        for(new i; i <= iRandom; i++)
        {
            if(!g_iCoin[iVictim])
                break;
            
            new iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, CLASSNAME_DEFAULT));
            
            set_pev(iEnt, pev_classname, CLASSNAME_SET);
            set_pev(iEnt, pev_origin, fOrigin);
            set_pev(iEnt, pev_solid, SOLID_TRIGGER);
            set_pev(iEnt, pev_movetype, MOVETYPE_BOUNCE);
            
            engfunc(EngFunc_SetSize, iEnt, Float: {-10.0, -10.0, -10.0}, Float: {10.0, 10.0, 10.0});
            engfunc(EngFunc_SetModel, iEnt, COIN_MODEL);
        
            set_pev(iEnt, pev_velocity, fVelocity);
            
            #if defined COIN_TIME_REMOVE
            set_pev(iEnt, pev_nextthink, get_gametime() + COIN_TIME_REMOVE);
            #endif
        }
    }
    #endif
    
    if(!is_user_connected(iAttacker))
        return;
    
    if(iVictim == iAttacker)
        return;
    
    new iGiveCoin = g_iCoin[iAttacker];
    
    if(iAttacker == pev(iVictim, pev_dmg_inflictor) && get_user_weapon(iAttacker) == CSW_KNIFE)
        iGiveCoin = COIN_GIVE_KILL_KNIFE;
    else if(get_pdata_int(iVictim, PDATA_KILLHEAD_OFFSET, PDATA_PLAYER_OFFSET) == HIT_HEAD)
        iGiveCoin = COIN_GIVE_KILL_HEAD;
    else
        iGiveCoin = COIN_GIVE_KILL;
        
    if(get_user_flags(iAttacker) & VIP_FLAG)
        iGiveCoin *= 2;
        
    g_iCoin[iAttacker] += iGiveCoin;
        
    set_hudmessage(0, 255, 0, -1.0, 0.26, 0, 0.1, 2.0, 0.1, 0.1, -1);
    show_hudmessage(iAttacker, "+%i монет", iGiveCoin);
}

#if defined COIN_DROP_COINS
public fw_TouchCoinPost(iEnt, id)
{
    if(!pev_valid(iEnt) || !is_user_alive(id))
        return;
            
    static sClassName[32];
    pev(iEnt, pev_classname, sClassName, charsmax(sClassName));
        
    if(!equal(sClassName, CLASSNAME_SET))
        return;
        
    g_iCoin[id]++;
    emit_sound(id, CHAN_WEAPON, COIN_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    
    set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME);
}

public Event_RoundStart()
{
    new iEnt = FM_NULLENT;
    
    while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", CLASSNAME_SET)))
        if(pev_valid(iEnt))
            set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME);
}
#endif

#if defined COIN_TIME_REMOVE
public fw_ThinkCoinPost(iEnt)
{
    if(!pev_valid(iEnt))
        return;
        
    static sClassName[32];
    pev(iEnt, pev_classname, sClassName, charsmax(sClassName));
    
    if(!equal(sClassName, CLASSNAME_SET))
        return;
        
    set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME);
}
#endif

public Task_HudMsg()
{
    set_hudmessage(200, 200, 200, 0.01, 0.90, 0, 0.1, 2.0, 0.1, 0.1, 4);
    
    for(new id = 1; id < g_iMaxPlayers; id++)
    {
        if(!is_user_alive(id))
            continue;
        
    }
}

public load_coins(id)
{
    new iLine = 1, iLen, sData[64], sKey[38], sAuthID[38];
    get_user_authid(id, sAuthID, charsmax(sAuthID));
    
    while((iLine = read_file(PATH_DATABASE, iLine, sData, charsmax(sData), iLen)))
    {
        parse(sData, sKey, 37);
        
        if(equal(sKey, sAuthID))
        {
            parse(sData, sKey, 37, sKey, 37);
            g_iCoin[id] = str_to_num(sKey);
            
            return;
        }
    }
    
    g_iCoin[id] = 0;
}

public save_coins(id)
{
    new iLine = 1, iLen, sData[64], sKey[38], sAuthID[38];
    get_user_authid(id, sAuthID, charsmax(sAuthID));
    
    while((iLine = read_file(PATH_DATABASE, iLine, sData, charsmax(sData), iLen)))
    {
        parse(sData, sKey, 37);
        
        if(equal(sKey, sAuthID))
        {
            format(sData, charsmax(sData), "%s %i", sAuthID, g_iCoin[id]);
            write_file(PATH_DATABASE, sData, iLine-1);
            
            return;
        }
    }
    
    format(sData, charsmax(sData), "%s %i", sAuthID, g_iCoin[id]);
    write_file(PATH_DATABASE, sData, -1);
}
 

Romik67ru

Участник
Сообщения
22
Симпатии
0
Баллы
57
#3
Код:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fun>
#include <colorchat>

#define NAME "Coins Shop"
#define VERSION    "0.1"
#define AUTHOR "Sokrat"

#define VIPFLAG ADMIN_LEVEL_G                        //Флаг VIP (ADMIN_...)

new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0

new jumpnum[33] = 0
new bool:dojump[33] = false

new vip, respawn, secondjump, multipledamage
new take_vip[33], take_respawn[33], take_secondjump[33], take_multipledamage[33]

native get_user_coins(id)
native set_user_coins(id, iNum)

public plugin_init()
{
    register_plugin(NAME, VERSION, AUTHOR)
    
    register_event("HLTV", "round_start", "a", "1=0", "2=0")
    RegisterHam(Ham_TakeDamage, "player", "damager", 0)

    register_menu("Menu 1", keys, "func_Coinshop")
    register_clcmd("say /coins", "Coinshop")
    
    register_cvar("amx_maxjumps", "1")                         //Количество дополнительных прыжков
    register_cvar("shop_vip", "200")                         //Цена "VIP на карту"
    register_cvar("shop_respawn", "50")                     //Цена "Воскрешение"
    register_cvar("shop_secondjump", "25")                     //Цена "Двойной прыжок"
    register_cvar("shop_multipledamage", "80")                 //Цена "Множитель урона"
}

public client_putinserver(id) {
    take_vip[id] = 0
    take_respawn[id] = 0
    take_secondjump[id] = 0
    take_multipledamage[id] = 0
}

public client_disconnect(id) {
    take_vip[id] = 0
    take_respawn[id] = 0
    take_secondjump[id] = 0
    take_multipledamage[id] = 0
}

public round_start(id)
{
    take_respawn[id] = 0
}

public Coinshop(id)
{
    vip = get_cvar_num("shop_vip")
    respawn = get_cvar_num("shop_respawn")
    secondjump = get_cvar_num("shop_secondjump")
    multipledamage = get_cvar_num("shop_multipledamage")

    static menu[650], iLen
    iLen = 0
    iLen = formatex(menu[iLen], charsmax(menu) - iLen, "\r|JP| \wМагазин за монеты \r|JP|^n \dВаши монеты: \y%i шт\d.^n^n", get_user_coins(id))

    if (get_user_coins(id) >= vip)
    {   
        if (take_vip[id] == 0)
        {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \wVIP на карту \d[\y%i\d]^n", vip)
            keys |= MENU_KEY_1
        }
        else if (take_vip[id] == 1)
        {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \dVIP на карту \d[\d%i\d] [Вы уже купили VIP]^n", vip)
        }
        else if (get_user_flags(id) & VIPFLAG)
        {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \dVIP на карту \d[\d%i\d] [У вас уже есть VIP]^n", vip)
        }
    }
    else
    {
        iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \dVIP на карту \d[\d%i\d]^n", vip)
        keys |= MENU_KEY_1
    }

    if (get_user_coins(id) >= respawn && !is_user_alive(id)) {
        if (take_respawn[id] == 0) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r2. \wВоскрешение \d[\y%i\d]^n", respawn)
            keys |= MENU_KEY_2
        }
        else if (take_respawn[id] == 1) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r2. \dВоскрешение \d[\d%i\d] [Вы уже воскрешались]^n", respawn)
            keys &= ~MENU_KEY_2
        }
    }
    else if (is_user_alive(id)) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r2. \dВоскрешение \d[\d%i\d] [Вы живы]^n", respawn)
            keys &= ~MENU_KEY_2
    }
    else {
        iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r2. \dВоскрешение \d[\d%i\d]^n", respawn)
        keys &= ~MENU_KEY_2
    }
    
    if (get_user_coins(id) >= secondjump) {
        if (take_secondjump[id] == 0) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r3. \wДвойной прыжок \d[\y%i\d]^n", secondjump)
            keys |= MENU_KEY_3
        }
        else if (take_secondjump[id] == 1) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r3. \dДвойной прыжок \d[\d%i\d] [Куплено]^n", secondjump)
            keys &= ~MENU_KEY_3
        }
    }
    else if (take_secondjump[id] == 1) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r3. \dДвойной прыжок \d[\d%i\d] [Куплено]^n", secondjump)
            keys &= ~MENU_KEY_3
        }
    else {
        iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r3. \dДвойной прыжок \d[\d%i\d]^n", secondjump)
        keys &= ~MENU_KEY_3
    }
    
    if (get_user_coins(id) >= multipledamage) {
        if (take_multipledamage[id] == 0) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r4. \wМножитель урона \d[\y%i\d]^n", multipledamage)
            keys |= MENU_KEY_4
        }
        else if (take_multipledamage[id] == 1) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r4. \dМножитель урона \d[\d%i\d] [Куплено]^n", multipledamage)
            keys &= ~MENU_KEY_4
        }
    }
    else if (take_multipledamage[id] == 1) {
            iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r4. \dМножитель урона \d[\d%i\d] [Куплено]^n", multipledamage)
            keys &= ~MENU_KEY_4
        }
    else {
        iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r4. \dМножитель урона \d[\d%i\d]^n", multipledamage)
        keys &= ~MENU_KEY_4
    }

    iLen += formatex(menu[iLen], charsmax(menu) - iLen, "^n\r0. \d|Выход|")
    keys |= MENU_KEY_0

    show_menu(id, keys, menu, -1, "Menu 1")
    return PLUGIN_HANDLED
}

public func_Coinshop(id, key)
{
    vip = get_cvar_num("shop_vip")
    respawn = get_cvar_num("shop_respawn")
    secondjump = get_cvar_num("shop_secondjump")
    multipledamage = get_cvar_num("shop_multipledamage")
    
    switch(key)
    {
        case 0: {
            if(get_user_coins(id) < vip && get_user_flags(id) & VIPFLAG) return PLUGIN_HANDLED
            else {
                set_user_coins(id, get_user_coins(id) - vip)
                take_vip[id] = 1
                screen_fade(id)
                set_user_flags(id, VIPFLAG)
                ColorChat(id, GREEN, "^1[^4Магазин^1] ^1Вы купили ^3VIP ^1на всю карту. Монет осталось: ^4%i шт^1.", get_user_coins(id))
            }
        }
        case 1: {
            if(get_user_coins(id) < respawn && is_user_alive(id)) return PLUGIN_HANDLED
            else {
                set_user_coins(id, get_user_coins(id) - respawn)
                take_respawn[id] = 1
                screen_fade(id)
                ExecuteHam( Ham_CS_RoundRespawn, id)
                ColorChat(id, GREEN, "^1[^4Магазин^1] ^1Вы купили ^3Воскрешение^1. Монет осталось: ^4%i шт^1.", get_user_coins(id))
            }
        }
        case 2: {
            if(get_user_coins(id) < secondjump && !is_user_alive(id)) return PLUGIN_HANDLED
            else {
                set_user_coins(id, get_user_coins(id) - secondjump)
                take_secondjump[id] = 1
                screen_fade(id)
                ColorChat(id, GREEN, "^1[^4Магазин^1] ^1Вы купили ^3Двойной Прыжок^1. Монет осталось: ^4%i шт^1.", get_user_coins(id))
            }
        }
        case 3: {
            if(get_user_coins(id) < multipledamage && !is_user_alive(id)) return PLUGIN_HANDLED
            else {
                set_user_coins(id, get_user_coins(id) - multipledamage)
                take_multipledamage[id] = 1
                screen_fade(id)
                ColorChat(id, GREEN, "^1[^4Магазин^1] ^1Вы купили ^3Множитель Урона^1. Монет осталось: ^4%i шт^1.", get_user_coins(id))
            }
        }
    }
    return PLUGIN_HANDLED
}

/*==========================================Скрин-Фейд при покупке==========================================*/
public screen_fade(id) {
    message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
    write_short(1<<10)
    write_short(1<<10)
    write_short(0x0000)
    write_byte(139)
    write_byte(0)
    write_byte(255)
    write_byte(50)
    message_end()
}

/*=============================================Множитель Урона=============================================*/
public damager(victim, inflicator, attacker, Float:damage){
    if( take_multipledamage[attacker] == 0) return
    if(!is_user_connected(attacker)) return
    if(victim == attacker || !victim) return

    SetHamParamFloat(4, damage * 1.9)
}

/*=============================================Двойной прыжок=============================================*/
public client_PreThink(id)
{
    if(!is_user_alive(id)) return PLUGIN_CONTINUE
    if (take_secondjump[id] == 0) return PLUGIN_CONTINUE
    new nbut = get_user_button(id)
    new obut = get_user_oldbutton(id)
    if((nbut & IN_JUMP) && !(get_entity_flags(id) & FL_ONGROUND) && !(obut & IN_JUMP))
    {
        if(jumpnum[id] < get_cvar_num("amx_maxjumps"))
        {
            dojump[id] = true
            jumpnum[id]++
            return PLUGIN_CONTINUE
        }
    }
    if((nbut & IN_JUMP) && (get_entity_flags(id) & FL_ONGROUND))
    {
        jumpnum[id] = 0
        return PLUGIN_CONTINUE
    }
    return PLUGIN_CONTINUE
}

public client_PostThink(id)
{
    if(!is_user_alive(id)) return PLUGIN_CONTINUE
    if (take_secondjump[id] == 0) return PLUGIN_CONTINUE
    if(dojump[id] == true)
    {
        new Float:velocity[3]   
        entity_get_vector(id,EV_VEC_velocity,velocity)
        velocity[2] = random_float(265.0,285.0)
        entity_set_vector(id,EV_VEC_velocity,velocity)
        dojump[id] = false
        return PLUGIN_CONTINUE
    }
    return PLUGIN_CONTINUE
}
 

Romik67ru

Участник
Сообщения
22
Симпатии
0
Баллы
57
#4
Проверка на баланс вроде бы есть... (я не сильно разбираюсь)
 

ko1dun

Модератор
Сообщения
142
Симпатии
34
Баллы
104
#5
Проверка не корректная
case 0
if(get_user_coins(id) < vip || get_user_flags(id) & VIPFLAG) return PLUGIN_HANDLED
case 1
if(get_user_coins(id) < respawn || is_user_alive(id)) return PLUGIN_HANDLED
case 2
if(get_user_coins(id) < secondjump || !is_user_alive(id)) return PLUGIN_HANDLED
 
Сверху