Raised This Month: $32 Target: $400
 8% 

set specific price for each player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Siveroo
Junior Member
Join Date: Apr 2020
Old 10-21-2020 , 23:25   set specific price for each player
Reply With Quote #1

so basically i have a custom shop, i wanna make it so that for every VIP, they will have some discount on that shop, my idea is that to make an array that will contain every price of every item for every player, so basically a 2d array. here's bit of my code..

Code:
enum _: COD_ITEM {     ITEM_EQUIPMENT,     ITEM_AMMO,     ITEM_BUFF,     ITEM_EXPERIENCE,     ITEM_PERK_I,     ITEM_PERK_II,     MAX_ITEM } new const cod_defaultPrice[MAX_ITEM] = {     8000,     8000,     10000,     16000,     8500,     10000 } new cod_itemPrice[33][MAX_ITEM]; public client_authorized(id) {     new flag = get_user_flags(id);     if (flag & ADMIN_LEVEL_E)     {         for (new item = 0; item < MAX_ITEM; item++)         {             cod_itemPrice[id][item] = cod_defaultPrice[item] *3 / 4         }     }     else     {         for (new item = 0; item < MAX_ITEM; item++)         {             cod_itemPrice[id][item] = cod_defaultPrice[item]         }     } }

now my question is that, using the code above, will there be any flaw or possible bug that will happen?

or maybe you can give me another example/code that does the same job in a better way

btw currently i cant test on multiplayer, but i need to get it done asap, that's why im asking it here in the first place

Last edited by Siveroo; 10-21-2020 at 23:27.
Siveroo is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-22-2020 , 10:52   Re: set specific price for each player
Reply With Quote #2

You don't need to be on a multiplayer server to test this, you could easily test it yourself. So far i don't see anything that could cause any problems, the message is: test it.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Siveroo
Junior Member
Join Date: Apr 2020
Old 10-23-2020 , 01:38   Re: set specific price for each player
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
You don't need to be on a multiplayer server to test this, you could easily test it yourself. So far i don't see anything that could cause any problems, the message is: test it.
yeah, but i couldn't simulate what will happen with multiple players
Siveroo is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 10-23-2020 , 07:51   Re: set specific price for each player
Reply With Quote #4

You could just multiply the default price by the percent of discount instead of doing this
Code:
cod_itemPrice[id][item] = cod_defaultPrice[item] *3 / 4
You will have something like this
Code:
// 1.0 is 100 percent
new price = floatround(cod_itemPrice[id][item] * 0.25) // 75% off
So if you want, say 25% off, multiply the defaultPrice by 0.75
If you want 70% off, multiply by 0.3
etc.
__________________








CrazY. is offline
Old 10-24-2020, 10:09
Siveroo
This message has been deleted by Siveroo. Reason: i missunderstand what he's actually trying to say, so my reply is irrelevant
Siveroo
Junior Member
Join Date: Apr 2020
Old 10-24-2020 , 10:17   Re: set specific price for each player
Reply With Quote #5

Quote:
Originally Posted by CrazY. View Post
You could just multiply the default price by the percent of discount instead of doing this
Code:
cod_itemPrice[id][item] = cod_defaultPrice[item] *3 / 4
You will have something like this
Code:
// 1.0 is 100 percent
new price = floatround(cod_itemPrice[id][item] * 0.25) // 75% off
So if you want, say 25% off, multiply the defaultPrice by 0.75
If you want 70% off, multiply by 0.3
etc.
well, that works aswell, but that's not a big problem tho, i also mastered basic mathematics
Siveroo is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 10-24-2020 , 12:16   Re: set specific price for each player
Reply With Quote #6

Is there need for a global variable to save each-player prices?

You could simple use formatex(menu_itemname, charsmax(menu_itemname), "%s\y $%i", cod_itemname[item], (flag & ADMIN_LEVEL_E) ? floatround( cod_defaultPrice[item] * 0,75 ) : cod_defaultPrice[item])
When looping throught items to create player menu.

And in the handler you do the same check for taking the cash from player.
__________________
Retired.
Xalus is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 10-24-2020 , 16:22   Re: set specific price for each player
Reply With Quote #7

The plugin is pretty simple, there is nothing you really need to improve
You can go with xalus method but there's no benefit, choose whatever is easier for you to work with
__________________








CrazY. 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 03:23.


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