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

Solved Adding price and limit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
Old 01-26-2021 , 05:33   Adding price and limit
Reply With Quote #1

Hello, I have problem with this plugin.

I try adding a price and limit at the same item but it doesn't work..
Code:
PHP Code:
    else if(key == 3)
    {
        if((
zp_ammopacks_get(id) >= 50) || (limit_antidote[id] < 2))
        {
            
ze_give_antidote(id)
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
            
limit_antidote[id]++
        }
        else(
zp_ammopacks_get(id) <= 50)
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tAnti-Dote")
        }
        if(
limit_antidote[id] > 2)
        {
            
limit_antidote[id]++
            
client_printcolored("!g[=SG=] !nYou've reached the limit !g[2/2]")
        }
    }
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED

__________________

Last edited by nG_getwreck; 01-28-2021 at 20:15.
nG_getwreck is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-26-2021 , 05:51   Re: Adding price and limit
Reply With Quote #2

PHP Code:

    
else if(key == 3)
    {
        if(
limit_antidote[id] >= 2)
        {
            
client_printcolored("!g[=SG=] !nYou've reached the limit !g[2/2]")
        }

        else if((
zp_ammopacks_get(id) >= 50))
        {
            
ze_give_antidote(id)
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
            
limit_antidote[id]++
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tAnti-Dote")
        }
    } 
code order.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-27-2021 at 03:03. Reason: Added else
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-26-2021 , 08:52   Re: Adding price and limit
Reply With Quote #3

Code:
if ( key == 3 )
{
	if ( zp_ammopacks_get ( pEntity ) < PRICE )
		return 1;

	if ( limit_antidote [ pEntity ] >= LIMIT_ANTIDOTE )
		return 1;

	limit_antidote [ pEntity ]++;
	zp_ammopacks_set ( pEntity, zp_ammopacks_get ( pEntity ) - PRICE );
	ze_give_antidote ( pEntity );
}
__________________
LondoN is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-26-2021 , 09:17   Re: Adding price and limit
Reply With Quote #4

Quote:
Originally Posted by LondoN View Post
Code:
if ( key == 3 )
{
	if ( zp_ammopacks_get ( pEntity ) < PRICE )
		return 1;

	if ( limit_antidote [ pEntity ] >= LIMIT_ANTIDOTE )
		return 1;

	limit_antidote [ pEntity ]++;
	zp_ammopacks_set ( pEntity, zp_ammopacks_get ( pEntity ) - PRICE );
	ze_give_antidote ( pEntity );
}
can you explain why are you using return ? when the menu isn't destroyed ?

and why did you change id to pEntity ?

don't give any misleading code if you don't understand enough.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-26-2021 at 09:18.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-26-2021 , 09:24   Re: Adding price and limit
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
can you explain why are you using return ? when the menu isn't destroyed ?

and why did you change id to pEntity ?

don't give any misleading code if you don't understand enough.
this is my style of codding..
but you're right about the return situation.

when i was do some tests for myself, if i don't used the return on verifications like this the code keeped running. for ex

Code:
if(money < price)
print(id, "no enought money")
else
give_bonus(id)
if my money was lower than the price the code keeped running, the print with no money shows but the bonus always execute.

idk, i just sayed, it's the 'metod' what works fine to me..
__________________
LondoN is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 01-27-2021 , 02:23   Re: Adding price and limit
Reply With Quote #6

PHP Code:
    else if(key == 3)
    {
        if(
limit_antidote[id] == 2//You only need to check if it equal 2 (max purchase), since it shouldn't be > 2 in the first place
            
client_printcolored("!g[=SG=] !nYou've reached the limit !g[2/2]")
        else 
        {
            
//everthing inside here only happened when limit < 2
            
if(zp_ammopacks_get(id) < 50
                
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tAnti-Dote")
            else    
            {
                
//everthing inside here only happened when limit < 2 and AP >= 50
                
ze_give_antidote(id)
                
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
                
limit_antidote[id]++
            }
        }  
    }
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED

__________________
My plugin:

Last edited by Celena Luna; 01-27-2021 at 02:26.
Celena Luna is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-27-2021 , 03:05   Re: Adding price and limit
Reply With Quote #7

Oh wasn't paying attention.

Selena works but would be rather using else if than using else twice.

I fixed the code on post 2
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-27-2021 at 03:05.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
Old 01-28-2021 , 20:15   Re: Adding price and limit
Reply With Quote #8

Thanks for you answers, I prefer what natsheh suggests.

Solved
__________________
nG_getwreck 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 02:51.


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