AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   XP Mod, setting lvls, exp, saving (https://forums.alliedmods.net/showthread.php?t=134549)

t3hNox 08-06-2010 05:40

XP Mod, setting lvls, exp, saving
 
Hi,
I had already posted for help in XP Mod tutorial topic but I didn't succeed to get enough help.

So I want to modify the code from XP Mod (original code here) so that every class would have individual levels and experience.
wrecked_ gave me code for starting:
PHP Code:

enum Class
{
    
Dog,
    
Bear,
    
Cat
}

enum Data
{
    
Level,
    
EXP
}

new 
pInfo[33][Class][Data]

// pInfo now holds each class and the player's Level+EXP with each

// pInfo[id][Bear][Level] = Level of the player when his class is Bear
// pInfo[id][Cat][EXP] = EXP of the player when his class is Cat 

I don't really understand how multidimensional arrays and enum work in this case so there are few things I'd like to ask.

Storing player's level and experience in a variable for saving in nvault would look like this ?
PHP Code:

new pCatLevel[33], pCatEXP[33]
pInfo[id][Cat][Level] = pCatLevel[id]
pInfo[id][Cat][EXP] = pCatEXP[id

I don't know how to assign pInfo[33][Class][Data] Class value. Umm.. pInfo[id][Class] = Cat ?
I'm trying this:
PHP Code:

public Class_Handle(id menu item
{
    if(
item == MENU_EXIT
    {
 
        
menu_destroy(menu);
 
    }
 
    new 
szCommand[6] , szName[64];
    new 
access callback;
 
    
menu_item_getinfo(menu item access szCommand szName 63 callback);
 
    new 
str_to_num(szCommand)
    if(
PlayerClass[id] != i)
    {
        
PlayerClass[id] = i
        client_print
(id,print_chat,"You have selected %s class.",CLASSES[i])
        
                
//Look here below.
        
switch(i)
        {
            case 
1pInfo[id][Class] = Dog
            
case 2pInfo[id][Class] = Bear 
            
case 3pInfo[id][Class] = Cat
        
}
    }
    else
    {
        
client_print(id,print_chat,"You are alredy a %s.",CLASSES[i])
    }
 
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE


I need to figure out these things :)

katna 08-06-2010 15:01

Re: XP Mod, setting lvls, exp, saving
 
the way you made it is that every id has this
PHP Code:

pInfo[id][Dog][Level]
pInfo[id][Dog][Exp]

pInfo[id][Bear][Level]
pInfo[id][Bear][Exp]

pInfo[id][Cat][Level]
pInfo[id][Cat][Exp

which is wrong cause you want to save the Class, Level, Xp ( Not xp and level for every class)
you should do this
PHP Code:

enum Class 

    
Dog 0
    
Bear
    
Cat 
}
enum Data 

    
Classes
    
Level
    
EXP
}

pInfo[33][Data

and then if you want to change a value
PHP Code:

pInfo[id][Classes] = Class:Dog// changing is class to a dog

pInfo[id][Level] = 100 // Making is level 100

pInfo[id][Exp] = 300 // Making is exp 300 


t3hNox 08-06-2010 15:42

Re: XP Mod, setting lvls, exp, saving
 
Thank you.
I want to make when a player connects to the server he has no class and then through a menu he choses his class. It means that I need to have enum Class something like a default value.
Will this do the trick ?
PHP Code:

enum Class 

    
None 0//No class
    
Dog
    
Bear
    
Cat 



And how can I set player exp and level value to his current class in Death event (when he is the killer - read_data(1)) ? :/ How can I get his class from enum ?
If I do pInfo[id][Exp] += 10 will it add 10 to the class that is already defined in pInfo[id][Classes] = Class: xx (if yes, that it would be ok, as adding any exp or level in death event will happen only if any class, other than None, is set) ?

katna 08-07-2010 03:43

Re: XP Mod, setting lvls, exp, saving
 
PHP Code:

new const ExpNeeded[5] = // 5 equal the max levels
{
        
100,
        
300,
        
600,
        
1000,
        
2000


PHP Code:

register_event("DeathMsg""eDeath""a"); 

PHP Code:

public eDeath( )
{
    new 
attacker read_data(1);
    new 
victim read_data(2);
        
pInfo[attacker][Exp] += 20;
        
pInfo[victim][Exp] -= 5;
        while(
pInfo[attacker][Exp] >= ExpNeeded[pInfo[attacker][Level]])
        {
                
// Leveled up
                
pInfo[attacker][Level] += 1;
                
client_print(id,print_chat,"Congratulation! you just leveled up!");
        }




t3hNox 08-07-2010 04:23

Re: XP Mod, setting lvls, exp, saving
 
Thanks. I'll will try things out and post if I will have any problems (but hopefully not :)).

infek 08-07-2010 04:31

Re: XP Mod, setting lvls, exp, saving
 
Quote:

Originally Posted by katna (Post 1263965)
[php]
new const ExpNeeded[5] = // 5 equal the max levels
{
100, <-- This is Level 0
300, <-- This will be the first level -iNfek
600,
1000,
2000
}

Actually you need 6
PHP Code:

new const ExpNeeded[6] = // 6 equal the max levels
{
        
0// Not a Level 0 Level
        
100// Needed Points for 1st Level
        
300// Needed Points for 2nd Level
        
600// Needed Points for 3rd Level
        
1000// Needed Points for 4th Level
        
2000 // Needed Points for 5th Level



t3hNox 08-07-2010 05:57

Re: XP Mod, setting lvls, exp, saving
 
Thanks, I'll note that.

Unfortunately for me it seems that creating such class system will not be possible for me with my current pawn skills.

When I began writing what ablilities a player will have according to his level after respawn I realised that only method I know to do that is making a switch(). There would be one switch for class and one for player's level - basically switch in switch.

Saving and loading data from nVault with pInfo[33][Data] array is still mysterious for me. :)


All times are GMT -4. The time now is 00:06.

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