Raised This Month: $ Target: $400
 0% 

need some logical help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 01-03-2011 , 11:57   need some logical help
Reply With Quote #1

Why the hell when I choose to withdraw 2000 money, and I've already got 15000 on me, the bank balance increases...

iMoney[] is money in bank

PHP Code:
if(iMoney[id] >= 2000)
            {
                if(
cs_get_user_money(id) <= 14000)
                {
                    
cs_set_user_money(idcs_get_user_money(id) + 2000)
                    
iMoney[id]-=2000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 2000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) > 14000)
                {
                    
iMoney[id]-= 16000 cs_get_user_money(id);
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                    
cs_set_user_money(id16000)
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id); 
Screenies -

Before withdraw:



After:





Also need help with this, because it is not working, like there is menu option other value, when u choose it you get messagemode ...

here is the code:

PHP Code:
    new szArg[4]
    
read_argv(1szArgcharsmax(szArg))
    new 
iArg str_to_num(szArg)
    if(
iMoney[id] >= iArg)
    {
        if(
cs_get_user_money(id) + iArg >= 16000)
        {
            
iMoney[id]-= 16000 cs_get_user_money(id);
            
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
            
cs_set_user_money(id16000)
        }
        else
        {
             
iMoney[id]-= iArg;
         
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"iArg)
         
cs_set_user_money(idcs_get_user_money(id) + iArg )
        }
    }
    else
    {
    
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
    }
    
Save_MySql(id);

When I click on Other value, messagemode comes up but when I enter some numbers and press Enter - nothing happens

Last edited by reinert; 01-03-2011 at 12:07.
reinert is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2011 , 14:27   Re: need some logical help
Reply With Quote #2

Show the full code. I see several flaws in your logic but really need to see the whole code for an appropriate fix IMO.


Food for thought:

PHP Code:
                else if(cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                } 
is unreachable code.
__________________

Last edited by fysiks; 01-03-2011 at 14:32.
fysiks is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-03-2011 , 15:04   Re: need some logical help
Reply With Quote #3

Um there is nothing new in my full code, the biggest part of my code is menus and their options such as this. Could you just say me the leaks you see :S

If this first code gets fixed I will fix another codes too :S

By the way, to check if user already has 16000 money, then I've to check it in the top, right ?

Could you say the flaws that you see ?

Last edited by reinert; 01-03-2011 at 15:20.
reinert is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2011 , 16:45   Re: need some logical help
Reply With Quote #4

Show the full code because I'm sure the source of your logical errors are much larger than the code that you posted.

For the messagemode thing I do need to see the whole code anyways.
__________________
fysiks is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-03-2011 , 16:56   Re: need some logical help
Reply With Quote #5

The whole code is very long, other things I've tested, they work... the only thing is bad is withdraw...

PHP Code:
public WithdrawMenu(id)
{
    new 
title[64];
    
formatex(title63"\wWithdraw money:^nBank balance: \y[\w %d$ \y]"iMoney[id] )
    new 
withdraw_menu menu_create(title"Withdraw_Menu_handler");
    
    if(
iMoney[id] >= 1000)
    {
    
menu_additem(withdraw_menu"\w1000$""1"0);
    }
    else
    {
    
menu_additem(withdraw_menu"\d1000$""1"0);
    }
    
    if(
iMoney[id] >= 2000)
    {
    
menu_additem(withdraw_menu"\w2000$""2"0);
    }
    else
    {
    
menu_additem(withdraw_menu"\d2000$""2"0);
    }
    
    if(
iMoney[id] >= 4000)
    {
    
menu_additem(withdraw_menu"\w4000$""3"0);
    }
    else
    {
    
menu_additem(withdraw_menu"\d4000$""3"0);
    }
    
    if(
iMoney[id] >= 8000)
    {
    
menu_additem(withdraw_menu"\w8000$""4"0);
    }
    else
    {
    
menu_additem(withdraw_menu"\d8000$""4"0);
    }
    
    if(
iMoney[id] >= 16000)
    {
    
menu_additem(withdraw_menu"\w16000$""5"0);
    }
    else
    {
    
menu_additem(withdraw_menu"\d16000$""5"0);
    }
    
    
menu_additem(withdraw_menu"\yOther value^n""6"0);
    
    
menu_additem(withdraw_menu"\wBack""7"0);
        
    
menu_setprop(withdraw_menuMPROP_EXITMEXIT_ALL);
    
    
menu_display(idwithdraw_menu0);
}

public 
Withdraw_Menu_handler(idwithdraw_menuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(withdraw_menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(withdraw_menuitemaccessdata,5iName63callback);
    new 
key str_to_num(data);
        
    switch(
key)
    {
        case 
1:
        {
            if(
iMoney[id] >= 1000)
            {
                if(
cs_get_user_money(id) <= 15000)
                {
                    
cs_set_user_money(idcs_get_user_money(id) + 1000)
                    
iMoney[id]-=1000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 1000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) > 15000)
                {
                    
iMoney[id]-= 16000 cs_get_user_money(id);
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                    
cs_set_user_money(id16000)
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id);
        }
        case 
2:
        {
            if(
iMoney[id] >= 2000)
            {
                if(
cs_get_user_money(id) <= 14000)
                {
                    
cs_set_user_money(idcs_get_user_money(id) + 2000)
                    
iMoney[id]-=2000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 2000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) > 14000)
                {
                    
iMoney[id]-= 16000 cs_get_user_money(id);
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                    
cs_set_user_money(id16000)
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id);
        }
        case 
3:
        {
            if(
iMoney[id] >= 4000)
            {
                if(
cs_get_user_money(id) <= 12000)
                {
                    
cs_set_user_money(idcs_get_user_money(id) + 4000)
                    
iMoney[id]-=4000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 4000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) > 12000)
                {
                    
iMoney[id]+= 16000 cs_get_user_money(id);
                    
cs_set_user_money(id16000)
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id);
        }
        case 
4:
        {
            if(
iMoney[id] >= 8000)
            {
                if(
cs_get_user_money(id) <= 8000)
                {
                    
cs_set_user_money(idcs_get_user_money(id) + 8000)
                    
iMoney[id]-=8000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 8000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) > 8000)
                {
                    
iMoney[id]+= 16000 cs_get_user_money(id);
                    
cs_set_user_money(id16000)
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id);
        }
        case 
5:
        {
            if(
iMoney[id] >= 16000)
            {
                if(
cs_get_user_money(id) == 0)
                {
                    
cs_set_user_money(id16000)
                    
iMoney[id]-=16000;
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn 16000$ money from your bank account")
                }
                else if(
cs_get_user_money(id) < 16000)
                {
                    
iMoney[id]+= 16000 cs_get_user_money(id);
                    
cs_set_user_money(id16000 cs_get_user_money(id))
                    
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
                }
                else if(
cs_get_user_money(id) == 16000)
                {
                    
client_printc(id"\g[ BANK ]\n You already have maximum amount of money")
                }
                    
                
Save_MySql(id);
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
            }
            
            
WithdrawMenu(id);
        }
        case 
6:
        {
            if(
iMoney[id] > 0)
            {
            
client_cmd(id"messagemode Withdraw_Other_Value")
            
client_printc(id"\g[ BANK ]\n Enter the value you would like to withdraw")
            }
            else
            {
            
client_printc(id"\g[ BANK ]\n You can't withdraw 0$ money.")
            }
        }
    }
    
    
menu_destroy(withdraw_menu);
    return 
PLUGIN_HANDLED;
}

public 
Withdraw_Other_Value(id)
{
    new 
szArg[4]
    
read_argv(1szArgcharsmax(szArg))
    new 
iArg str_to_num(szArg)
    if(
iMoney[id] >= iArg)
    {
        if(
cs_get_user_money(id) + iArg >= 16000)
        {
            
iMoney[id]-= 16000 cs_get_user_money(id);
            
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"16000 cs_get_user_money(id))
            
cs_set_user_money(id16000)
        }
        else
        {
             
iMoney[id]-= iArg;
         
client_printc(id"\g[ BANK ]\n You've just withdrawn %d$ money from your bank account"iArg)
         
cs_set_user_money(idcs_get_user_money(id) + iArg )
        }
    }
    else
    {
    
client_printc(id"\g[ BANK ]\n You can't withdraw that much, you have only %d$"iMoney[id])
    }
    
Save_MySql(id);


Hope it's enough...
reinert is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2011 , 21:45   Re: need some logical help
Reply With Quote #6

Here is my version. Try it "as-is" and see how you like it. It should be much easier to modify like this.

PHP Code:
public WithdrawMenu(id)
{
    new 
title[64]
    
formatex(title63"\wWithdraw money:^nBank balance: \y[\w %d$ \y]"iMoney[id] )
    new 
withdraw_menu menu_create(title"Withdraw_Menu_handler")
    
    
menu_additem(withdraw_menu"1000$""1000")
    
menu_additem(withdraw_menu"2000$""2000")
    
menu_additem(withdraw_menu"4000$""4000")
    
menu_additem(withdraw_menu"8000$""8000")
    
menu_additem(withdraw_menu"16000$""16000")
    
    
menu_additem(withdraw_menu"\yOther value^n""-1"0)
    
menu_additem(withdraw_menu"\wBack""-2"0)
    
    
menu_setprop(withdraw_menuMPROP_EXITMEXIT_ALL)
    
    
menu_display(idwithdraw_menu0)
}

public 
Withdraw_Menu_handler(idwithdraw_menuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(withdraw_menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64]
    new 
_accesscallback
    
    menu_item_getinfo
(withdraw_menuitem_accessdatacharsmax(data), iName63callback)
    new 
iValue str_to_num(data)
    
    switch( 
iValue )
    {
        case -
1:
        {
            
client_cmd(id"messagemode Withdraw_Other_Value")
            
client_print(idprint_chat"[ BANK ] Enter the value you would like to withdraw")
        }
        case -
2:
        {
            
// Back (whatever that means)
        
}
        default:
        {
            if( 
MakeWithdrawal(idiValue) )
            {
                
Save_MySql(id)
            }
            
WithdrawMenu(id)
        }
    }
    
menu_destroy(withdraw_menu)
    return 
PLUGIN_HANDLED
}

public 
Withdraw_Other_Value(id)
{
    new 
szArg[4]
    
read_argv(1szArgcharsmax(szArg))
    new 
iArg str_to_num(szArg)
    
    if( 
MakeWithdrawal(idiArg) )
    {
        
Save_MySql(id)
    }
    
WithdrawMenu(id)
}  

stock bool:MakeWithdrawal(idiAmount)
{
    new 
iUserMoney cs_get_user_money(id)
    
    if( 
iMoney[id] < iAmount )
    {
        
// Withdrawal amount exceeds available funds.
        
client_print(idprint_chat"[ BANK ] Withdrawal amount exeeds available funds.")
        return 
false
    
}
    else if( 
iUserMoney iAmount 16000 )
    {
        
// Withdrawal will make in-game money exceed $16000.
        
client_print(idprint_chat"[ BANK ] In-game funds cannot exceed $16000.")
        return 
false
        
// Optionally you could process a partial withdrawal to be at $16000 in-game (must return true instead of false).
    
}
    else
    {
        
// Funds exist and won't exceed in-game limit
        
cs_set_user_money(idiUserMoney iAmount)
        
iMoney[id] -= iAmount
        client_print
(idprint_chat"[ BANK ] You have withdrawn $%d.")
        return 
true
    
}
    return 
false

__________________
fysiks is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-04-2011 , 05:14   Re: need some logical help
Reply With Quote #7

Ok thanks, I will try it, And I'm almost sure that this line:

client_print(id, print_chat, "[ BANK ] You have withdrawn $%d.")

should be

client_print(id, print_chat, "[ BANK ] You have withdrawn $%d.", iAmount)


other value still doesn't work, and menu closes sometimes itself I don't want it :S, And is it possible to make that if user has less than 16000 in bank, the 16000 option will be shown in grey. And I like my menu style more, because I think it's easier :S


I just want some logical help here:

If user has more than 15000 (15001, 15002 etc..), and he choose to withdraw 1000 money, the maximum amount of money is 16000, so how could I make, that he gets maximum, but the rest money goes back to his bank balance.

something like that, yeah ?

iMoney[id]-= 1000 - (16000 - cs_get_user_money(id))

I've got 15500 on me, 1000 - (16000 - 15500)) = 500. I think I'm right xD

Last edited by reinert; 01-04-2011 at 05:32.
reinert is offline
shuttle_wave
Veteran Member
Join Date: Apr 2009
Location: New Zealand
Old 01-04-2011 , 05:24   Re: need some logical help
Reply With Quote #8

correct sir.

Quote:
Originally Posted by reinert View Post
Ok thanks, I will try it, And I'm almost sure that this line:

client_print(id, print_chat, "[ BANK ] You have withdrawn $%d.")

should be

client_print(id, print_chat, "[ BANK ] You have withdrawn $%d.", iAmount)


other value still doesn't work, and menu closes sometimes itself I don't want it :S, And is it possible to make that if user has less than 16000 in bank, the 16000 option will be shown in grey. And I like my menu style more, because I think it's easier :S

__________________
JailBreak Mod with Plugin API ( 90% ) Public
shuttle_wave is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-04-2011 , 15:45   Re: need some logical help
Reply With Quote #9

Could someone help me ? :S
reinert is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 01-04-2011 , 18:19   Re: need some logical help
Reply With Quote #10

After reading it few times... I still don't get what you want help with.
matsi 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 01:57.


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