Raised This Month: $ Target: $400
 0% 

Bool function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
STr!ker
Senior Member
Join Date: Jun 2009
Location: Germany
Old 11-04-2011 , 19:34   Bool function
Reply With Quote #1

Hey i have a bool function in a buymenu. I can set if he has bought a weapon to bool = 1 or 0, but how i can check, set the player can buy the thing 2 times and not more.

1 time is easy to check (bool =1 (if bool = 1 = Stop=
but he should can buy something 2 times. how to do this?
STr!ker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-04-2011 , 19:54   Re: Bool function
Reply With Quote #2

There's no third value/condition in a bool but that doesn't mean your problem can't be solved.

Instead of using a bool and setting to true, use an integer and on each buy attempt do
PHP Code:
if ( ++NumBuy <= )
   
//give item 
__________________

Last edited by Bugsy; 11-04-2011 at 19:57.
Bugsy is offline
STr!ker
Senior Member
Join Date: Jun 2009
Location: Germany
Old 11-05-2011 , 00:51   Re: Bool function
Reply With Quote #3

For an example, can you change it me in a simple weapongive script?

PHP Code:
public cmdMenu(id)
{
 if( 
got_weapon[id] )
    {
        
client_print(idprint_chat"%L"LANG_PLAYER"HAVEALREADY")
        return 
PLUGIN_CONTINUE
    
}
    
showMenu(id)
    return 
PLUGIN_CONTINUE

and then the switchcase for the weapons:

PHP Code:
    switch(key)
    {
        case 
1:
        {

            
give_item(id"weapon_ak47")
            
give_item(id"weapon_deagle")
            
cs_set_user_bpammo(id,CSW_AK47,90)
            
cs_set_user_bpammo(id,CSW_DEAGLE,35)
            
got_weapon[id] = true
        

sorry, but i am new @ c++ and i donīt know ALL but i have done a look at many plugins and all what I see is.. well nothing i just trie to fix something and it will work, or not

so what i have tried is to use instead of got_weapon[id], if ( ++NumBuy <= 2 ) in the public_cmdMenu. But NumBuy is undefined

Last edited by STr!ker; 11-05-2011 at 01:01.
STr!ker is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-05-2011 , 01:10   Re: Bool function
Reply With Quote #4

Quote:
Originally Posted by STr!ker View Post
so what i have tried is to use instead of got_weapon[id], if ( ++NumBuy <= 2 ) in the public_cmdMenu. But NumBuy is undefined
A very important lesson you should learn is that you can't just copy paste code. 99% of the time it WILL NOT work correctly. You have to modifiy it in some way to make it work correctly.
__________________

Last edited by fysiks; 11-05-2011 at 01:11.
fysiks is offline
STr!ker
Senior Member
Join Date: Jun 2009
Location: Germany
Old 11-05-2011 , 01:19   Re: Bool function
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
A very important lesson you should learn is that you can't just copy paste code. 99% of the time it WILL NOT work correctly. You have to modifiy it in some way to make it work correctly.
but what can i do, when i donīt understand the integer? I have read already wikis in google. So you can make me a little example.

Last edited by STr!ker; 11-06-2011 at 10:09.
STr!ker is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-05-2011 , 10:12   Re: Bool function
Reply With Quote #6

PHP Code:
new g_times_used[33]

public 
player_spawn(id)
{
    
g_times_used[id] = 0
}

public 
cmdMenu(id)
{
    if( 
g_times_used[id] >= )
    {
        
client_print(idprint_chat"%L"LANG_PLAYER"HAVEALREADY")
        return 
PLUGIN_CONTINUE
    
}
    
showMenu(id)
    return 
PLUGIN_CONTINUE

PHP Code:
    g_times_used[id]++
    switch(
key)
    {
        case 
1:
        {
            
give_item(id"weapon_ak47")
            
give_item(id"weapon_deagle")
            
cs_set_user_bpammo(id,CSW_AK47,90)
            
cs_set_user_bpammo(id,CSW_DEAGLE,35)
        } 
__________________
Impossible is Nothing
Sylwester is offline
STr!ker
Senior Member
Join Date: Jun 2009
Location: Germany
Old 11-05-2011 , 13:29   Re: Bool function
Reply With Quote #7

it says me that the symbol is undefinied :S How to fix it. I have tried to get the code to this, but it should work, because it has both switch case and there isnīt a big different^^

Last edited by STr!ker; 11-06-2011 at 10:08.
STr!ker is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-05-2011 , 15:29   Re: Bool function
Reply With Quote #8

Quote:
Originally Posted by STr!ker View Post
it says me that the symbol is undefinied :S How to fix it. I have tried to get the code to this, but it should work, because it has both switch case and there isnīt a big different^^
Because you didn't even use the code you posted in #3. The code that he gave you was for the code in post #3.
__________________

Last edited by fysiks; 11-05-2011 at 15:31.
fysiks is offline
STr!ker
Senior Member
Join Date: Jun 2009
Location: Germany
Old 11-05-2011 , 21:12   Re: Bool function
Reply With Quote #9

Yes i just needed an example to understand it, but now i have tried to solve the problem with the example to understand all of that. But the bullsh**t donīt work
STr!ker is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-05-2011 , 22:30   Re: Bool function
Reply With Quote #10

You have to put the g_times_used[id]++ where the buying is actually happening.
__________________
fysiks 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 14:15.


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