AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set specific price for each player (https://forums.alliedmods.net/showthread.php?t=328016)

Siveroo 10-21-2020 23:25

set specific price for each player
 
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

Napoleon_be 10-22-2020 10:52

Re: set specific price for each player
 
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.

Siveroo 10-23-2020 01:38

Re: set specific price for each player
 
Quote:

Originally Posted by Napoleon_be (Post 2722189)
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

CrazY. 10-23-2020 07:51

Re: set specific price for each player
 
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.

Siveroo 10-24-2020 10:17

Re: set specific price for each player
 
Quote:

Originally Posted by CrazY. (Post 2722283)
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 :wink:

Xalus 10-24-2020 12:16

Re: set specific price for each player
 
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.

CrazY. 10-24-2020 16:22

Re: set specific price for each player
 
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


All times are GMT -4. The time now is 13:52.

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