View Single Post
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 08-25-2023 , 19:24   Wrong values in the menu
Reply With Quote #1

Does anyone know why the value of the days is not being changed? Because each day should have a different value based on the day's calculation.

PHP Code:
public iSelect_Periodo(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED
 
    new 
iCash GetUserCash(id); 
    new 
iNameItem[32]; 
    
ArrayGetString(iArrayItemNameiNextShopItem[id], iNameItemsizeof(iNameItem)); 
    new 
iCostItem GetArrayInfo(iNextShopItem[id], INFO_COST); 
    
//new iMoedaItem = GetArrayInfo(iNextShopItem[id], INFO_MOEDA); 
    
new szTitle[228]; 
    
formatex(szTitlecharsmax(szTitle), "\d%s Quantos dias você quer? ^n\r» \yCash:\d %i^n^n\w Item Selecionado:\y %s"PREFIXMENUiCashiNameItem); 
 
    new 
iMenu menu_create(szTitle"_iSelect_Periodo"); 
    new 
iCalCashPercent CalculaCash(iCostItemget_pcvar_numcvar_cash_divide)); 
 
    new 
iCheckCost[4][128], iCheckCost2[4][128]; 
    new 
iDuration[4] = {173090}; 
 
    for (new 
04i++) { 
        
iCheckCost[i][0] = GetUserCash(id) < CalculaDia(iCalCashPercentiDuration[i]) ? 'd' 'w'
        
iCheckCost2[i][0] = GetUserCash(id) < CalculaDia(iCalCashPercentiDuration[i]) ? 'd' 'r'
 
        
formatex(szTitlecharsmax(szTitle), "\%c %i Dias\%c [ Cash: %i ]"iCheckCost[i][0], iDuration[i], iCheckCost2[i][0], iCostItem); 
        
menu_additem(iMenuszTitlefmt("%d"i+1), 0); 
    } 
 
    
menu_setprop(iMenuMPROP_EXITNAME"\d Cancelar Compra"); 
    
menu_display(idiMenu0); 
 
    return 
PLUGIN_HANDLED
}

public 
_iSelect_Periodo(idiMenuitem)
{
    if (
item == MENU_EXIT) {
        
iNextShopItem[id] = 0;
        
iNextShopMoeda[id] = 0;
        
iNextShopDays[id] = 0;
        
iNextShopBody[id] = 0;
        
menu_destroy(iMenu);
        return 
PLUGIN_HANDLED;
    }

    new 
iKey item 1;
    new 
iDuration[4] = {173090};

    
// Check if the selected item is valid
    
if (iKey || iKey >= sizeof(iDuration))
    {
        
// Dealing with an invalid selection
        
iSelect_Periodo(id);
        return 
PLUGIN_HANDLED;
    }

    
// Get information on the selected item
    
new iNameItem[32];
    
ArrayGetString(iArrayItemNameiNextShopItem[id], iNameItemsizeof(iNameItem));
    new 
iCostItem GetArrayInfo(iNextShopItem[id], INFO_COST);
    new 
iMoedaItem GetArrayInfo(iNextShopItem[id], INFO_MOEDA);

    
// Check if the player has enough resources to buy the item
    
if (iMoedaItem == CASH && GetUserCash(id) < iCostItem iDuration[iKey])
    {
        
// Dealing with a lack of money
        
iSelect_Periodo(id);
        
client_print_color(idprint_team_default"^x01Você não tem dinheiro suficiente!");
        return 
PLUGIN_HANDLED;
    }
    
// Process the purchase of the item

    
SetUserCash(idGetUserCash(id) - iCostItem iDuration[iKey]);
    
SetLog(LOG_LOJA"O PLAYER %s COMPROU %s POR %i DIAS E PAGOU %i CASH!"iNameItemiDuration[iKey], iCostItem iDuration[iKey]);
    
UpdateBancoCash(id);

    
// Atualizar o inventário do jogador
    
SetInventoryItem(idGetArrayInfo(iNextShopItem[id], INFO_ID), GetArrayInfo(iNextShopItem[id], INFO_TIPO), TEMPORARIOiDuration[iKey]);
    
//set_task(2.0, "recarregar_inventario", id + TASK_LOAD_INVENTARIO);
    
client_print_color(idprint_team_default"^x01Você adquiriu %s %s por %d dia%s, verifique seu inventário!"iTipo_Item[GetArrayInfo(iNextShopItem[id], INFO_TIPO)], iNameItemiDuration[iKey], iDuration[iKey] == "" "s");

    
// Limpar as variáveis de compra
    
iNextShopItem[id] = 0;
    
iNextShopMoeda[id] = 0;
    
iNextShopDays[id] = 0;
    
iNextShopBody[id] = 0;

    
// Destruir o menu
    
menu_destroy(iMenu);

    return 
PLUGIN_HANDLED;
}

stock CalculaCash(valorcalc){
    new 
iReturn
    iReturn 
valor calc;
    
    return 
iReturn;
}

stock CalculaDiavalor_itemdata ){
    new 
iReturn
    
switch( data ){
        case 
1iReturn valor_item;
        case 
7iReturn valor_item + ( 0,315 valor_item 100 );
        case 
30iReturn valor_item + ( 0,595 valor_item 100 );
        case 
90iReturn valor_item + ( 0,1120 valor_item 100 );
    }

    return 
iReturn;

yagami is offline