Raised This Month: $51 Target: $400
 12% 

Wrong values in the menu


Post New Thread Reply   
 
Thread Tools Display Modes
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
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 08-25-2023 , 19:35   Re: Wrong values in the menu
Reply With Quote #2

Publica o código todo. Não percebo porque complicam o simples. Isto devia ser um plugin simples.

Post the whole code. I don’t understand why you complicate simple stuff. This should be a simple plugin.
__________________
Jhob94 is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 08-25-2023 , 19:58   Re: Wrong values in the menu
Reply With Quote #3

when dealing with fractional numbers you have to use a Float variables otherwise result will not be as expected
new Float:pi = 3.14
__________________
bigdaddy424 is offline
yagami
Senior Member
Join Date: Jan 2021
Old 08-25-2023 , 21:40   Re: Wrong values in the menu
Reply With Quote #4

Quote:
Originally Posted by Jhob94 View Post
Publica o código todo. Não percebo porque complicam o simples. Isto devia ser um plugin simples.

Post the whole code. I don’t understand why you complicate simple stuff. This should be a simple plugin.
Why am I rewriting old
it has a SHOP, TRADE, BLACK MARKET system
Currently I've only made a store
here is part of the menu where, when the player buys a skin, he chooses how many days he wants to keep the skin 1, 7, 30, 90 days and he needs to calculate the value based on the days in the price of the skins.
yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 08-25-2023 , 21:42   Re: Wrong values in the menu
Reply With Quote #5

Quote:
Originally Posted by bigdaddy424 View Post
when dealing with fractional numbers you have to use a Float variables otherwise result will not be as expected
new Float:pi = 3.14

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 
iCheckCost[4][128], iCheckCost2[4][128];
    new 
iDuration[4] = {173090};

    for (new 
04i++) {
        new 
iCalCashPercent CalculaDia(iCostItemiDuration[i]);

        
iCheckCost[i][0] = GetUserCash(id) < iCalCashPercent 'd' 'w';
        
iCheckCost2[i][0] = GetUserCash(id) < iCalCashPercent 'd' 'r';

        
formatex(szTitlecharsmax(szTitle), "\%c %i Dias\%c [ Cash: %i ]"iCheckCost[i][0], iDuration[i], iCheckCost2[i][0], iCalCashPercent);
        
menu_additem(iMenuszTitlefmt("%d"i+1), 0);
    }

    
menu_setprop(iMenuMPROP_EXITNAME"\d Cancelar Compra");
    
menu_display(idiMenu0);

    return 
PLUGIN_HANDLED;


I discovered something using if and for


in the original code if is used to calculate value
in the for I need to add inside the loop
yagami is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 09-13-2023 , 15:10   Re: Wrong values in the menu
Reply With Quote #6

Code:
        default:
            iReturn = valor_item;
    }

    return iReturn;
}
Quote:
// Default to 1-day cost if data is not recognized.

Last edited by Fuck For Fun; 09-13-2023 at 15:11.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
lexzor
Veteran Member
Join Date: Nov 2020
Old 09-16-2023 , 07:15   Re: Wrong values in the menu
Reply With Quote #7

Code:
public CalculaDia(Float:valor_item, data) {     new Float:fValueToMul     switch(data)     {         case 7: fValueToMul = 0.315         case 30: fValueToMul = 0.595         case 90: fValueToMul = 1.120     }     return floatround(valor_item + (floatmul(fValueToMul, valor_item) / 100.0)) }

Last edited by lexzor; 09-16-2023 at 07:17.
lexzor is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:18.


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