AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP]How to make points as deathrun? (https://forums.alliedmods.net/showthread.php?t=194850)

sintetic 08-31-2012 20:55

[HELP]How to make points as deathrun?
 
Hello there as the title I need to know how can I creat points as deathrun,I mean I have menu with weapons which cost money,like that a deagle from my menu cost 500$ it's ok.But I want it to cost points like this,deagle cost 1,2 points,how can I make points as the deathrun shops or etc?
If you can put as more as information you can,because I am still newbie at scripting/coding :)

Infernuz 08-31-2012 20:58

Re: [HELP]How to make points as deathrun?
 
Show what you have done and what kind of points you want.

PHP Code:

new deathrun_point 0

This will create a new variable which will store some points.

Is that what you need?

sintetic 08-31-2012 21:10

Re: [HELP]How to make points as deathrun?
 
Well I think that I can explain you,you know deathrun shops,there are some VIP extras like "speed"
and for example "speed" costs 20 points,no 20$ or 2000$ 20k$,I need to know how can I create such as points,so when I purchase an item it to takes down from my points,like -1,2. That's my question,but thanks for the answer.

Infernuz 08-31-2012 21:27

Re: [HELP]How to make points as deathrun?
 
No I don't know "deathrun shops" since I haven't played on those servers. But I can help with points.

You can create a array of players for which will hold all players points like this.

We assume that this are our 32 players
PHP Code:

new deathrun_points[32] = 0

And this is our function to call when a player clicks on it.

myMenuItem(id, item) - Where id is a player identificator and item is an integer.
case 1: - Is a grenade that costs 500$.

PHP Code:

public myMenuItem(iditem) {
    new 
user_money cs_get_user_money(id);
    
    switch(
item) {
        case 
1: {
            if(
user_money >= 500) {
                
// bla bla, give player a grenade.
                
                // this removes 500 from their money.
                
cs_set_user_money(iduser_money 500); 
            }
        }
        
// more other cool items.
    
}
}



We want to perfom a check if player have any points, so now we modify this function a bit so it looks like this.

PHP Code:

public myMenuItem(iditem) {
    new 
user_money cs_get_user_money(id);
        
    switch(
item) {
        case 
1: {
            if(
user_money >= 500) {
                
// bla bla, give play grenade.
                
                // this removes 500 from their money.
                
cs_set_user_money(iduser_money 500); 
            } else if(
deathrun_points[id] >= 2) {
                
                
// this removes 2 points from player.
                
deathrun_points[id] = deathrun_points[id] - 2;
            } else {
                
client_cmd(1,print_chat,"Man, no money or points. Sorry, no grenade for you.");
            }
        }
        
// more other cool items.
    
}
}  



CODE FIX: If you look closely, I have modified the if statement and added an else check.


And our final code will be this.
PHP Code:

new deathrun_points[32] = 0;

public 
myMenuItem(iditem) {
    new 
user_money cs_get_user_money(id);
        
    switch(
item) {
        case 
1: {
            if(
user_money >= 500) {
                
// bla bla, give play grenade.
                
                // this removes 500 from their money.
                
cs_set_user_money(iduser_money 500); 
            } else if(
deathrun_points[id] >= 2) {
                
                
// this removes 2 points from player.
                
deathrun_points[id] = deathrun_points[id] - 2;
            } else {
                
client_cmd(1,print_chat,"Man, no money or points. Sorry, no grenade for you.");
            }
        }
        
// more other cool items.
    
}


Have you understood anything of this?

sintetic 08-31-2012 21:41

Re: [HELP]How to make points as deathrun?
 
Ok,but as you said it removes only 500 $ from their money,but what about the points as you typed
PHP Code:

if(user_money >= 500 || deathrun_points[id] >= 2

It removes only the money,example there is "deathrun_points[id] >= 2)" but we don't have them in game,so the "HE Grenade" removes only money,but without points,so my idea was that I don't need money,let's forget about them. How can I create function for points,that in game they will cost something,like the grenade cost 1,2 of points,but as I choose the HE grenade it doesn't bought me (I have removed all my money) in fact points are only in script,but not in game so how can I make that to remove from points like this,if I have 10 points in game,I want to purchase a HE grenade for 2 points,how can I create this.And thank you for fast answers. :)

Infernuz 08-31-2012 22:24

Re: [HELP]How to make points as deathrun?
 
Quote:

Ok,but as you said it removes only 500 $ from their money,but what about the points as you typed
I only now noticed my mistakes in code. I have corrected it. Thank you for pointing.

Quote:

How can I create function for points,that in game they will cost something,like the grenade cost 1,2 of points,but as I choose the HE grenade it doesn't bought me (I have removed all my money) in fact points are only in script
Ehm. This is basicly how it looks like. It's only an example and shouldn't acctualy be like that in your plugin. You can create it in your coding style.

===========================================
It looks like you didn't understand me well. I'll try to explain my code more clearly.

This is the place where points are stored for each player. It's an array that holds points for each of the player on your server.
More about arrays here: http://wiki.amxmodx.org/Pawn_Tutorial#Arrays
PHP Code:

new deathrun_points[32]; 

This is the function that should be called if player clicks on the item in menu.
More about function here: http://wiki.amxmodx.org/Pawn_Tutorial#Functions
PHP Code:

public myMenuItem(iditem) { 

This is a switch statement that swaps your items throw it's list. In our case it's item and it should contain 1.
More about switch statement: http://wiki.amxmodx.org/Pawn_Tutorial#Switch_Statements
PHP Code:

switch(item) { 

This is an if check. I perform it to check if player with id have 2 points in HIS array deathrun_points[id].
More about if here: http://wiki.amxmodx.org/Pawn_Tutorial#If_Statements
PHP Code:

if(deathrun_points[id] >= 2) { 


And this is the final part.

Buy a grenade only with points.
PHP Code:

new deathrun_points[32];

public 
myMenuItem(iditem) {
    switch(
item) {
        case 
1: {
                if(
deathrun_points[id] >= 2) {
                    
// bla bla...give grenade
                    
                    // remove 2 points.
                    
deathrun_points[id] = deathrun_points[id] - 2;
                } else {
                    
client_cmd(id,print_chat,"What the heck?! No points.");
                }
        }
        
// more other cool items.
    
}


Buy grenade with money and points.
PHP Code:

new deathrun_points[32];

public 
myMenuItem(iditem) {
    new 
user_money cs_get_user_money(id);
        
    switch(
item) {
        case 
1: {
            if(
user_money >= 500) {
                
// bla bla, give play grenade.
                
                // this removes 500 from their money.
                
cs_set_user_money(iduser_money 500); 
            } else if(
deathrun_points[id] >= 2) {
                
                
// this removes 2 points from player.
                
deathrun_points[id] = deathrun_points[id] - 2;
            } else {
                
client_cmd(1,print_chat,"Man, no money or points. Sorry, no grenade for you.");
            }
        }
        
// more other cool items.
    
}


If you understood everything, you could move to the next step. How to save and get the data. Nvault or MySQL. Else there's no point to continue.


All times are GMT -4. The time now is 08:22.

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