AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Bool function (https://forums.alliedmods.net/showthread.php?t=171345)

STr!ker 11-04-2011 19:34

Bool function
 
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?

Bugsy 11-04-2011 19:54

Re: Bool function
 
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 


STr!ker 11-05-2011 00:51

Re: Bool function
 
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 :D 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

fysiks 11-05-2011 01:10

Re: Bool function
 
Quote:

Originally Posted by STr!ker (Post 1590295)
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.

STr!ker 11-05-2011 01:19

Re: Bool function
 
Quote:

Originally Posted by fysiks (Post 1590301)
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.

Sylwester 11-05-2011 10:12

Re: Bool function
 
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)
        } 


STr!ker 11-05-2011 13:29

Re: Bool function
 
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^^

fysiks 11-05-2011 15:29

Re: Bool function
 
Quote:

Originally Posted by STr!ker (Post 1590697)
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.

STr!ker 11-05-2011 21:12

Re: Bool function
 
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 :mrgreen:

fysiks 11-05-2011 22:30

Re: Bool function
 
You have to put the g_times_used[id]++ where the buying is actually happening.


All times are GMT -4. The time now is 14:15.

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