Raised This Month: $ Target: $400
 0% 

I need on retrieveing individual data.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KoNz
Junior Member
Join Date: Apr 2011
Location: Finland
Old 02-10-2013 , 09:10   I need on retrieveing individual data.
Reply With Quote #1

pInfo[33][Class][Data]

I need to get [data] info from a player and change it.

Need more info? Ill gladly add. I found this from...

https://forums.alliedmods.net/showpo...&postcount=198

EDIT: The topic was 3 months old and wasnt really active so I felt like making new thread. And this could help other players too.

EDIT2: What is this called anyway?
__________________

Replace it.

Last edited by KoNz; 02-10-2013 at 09:12.
KoNz is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 10:06   Re: I need on retrieveing individual data.
Reply With Quote #2

Depends on what you want to change:
PHP Code:
pInfo[id][Dog][Level]++; // Increases "Dog" level by 1
pInfo[id][Bear][EXP] += 50// Increases "Bear" EXP by 50 

Last edited by nnajko; 02-10-2013 at 10:08.
nnajko is offline
KoNz
Junior Member
Join Date: Apr 2011
Location: Finland
Old 02-10-2013 , 10:07   Re: I need on retrieveing individual data.
Reply With Quote #3

Quote:
Originally Posted by nnajko View Post
Depends on what you want to change, for example increasing the players "Dog" level by one:
PHP Code:
pInfo[id][Dog][Level]++; 
Ahh, I see now!
But how I can check which class does a person have? [Class]?
Do I need new variable for that? or something?

Example I wanna add xp on his class which he used.
__________________

Replace it.

Last edited by KoNz; 02-10-2013 at 10:08.
KoNz is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 10:10   Re: I need on retrieveing individual data.
Reply With Quote #4

Yeah use a variable
PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

enum _:Class
{
    
Dog 0,
    
Bear,
    
Cat
}

enum Data
{
    
Level,
    
EXP
}

new 
pInfo[33][Class][Data];
new 
g_iPlayerClass[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test""CmdTest");
}

public 
CmdTest(id)
{
    
g_iPlayerClass[id] = Dog;
    
    
pInfo[id][g_iPlayerClass[id]][EXP] += 50;


Last edited by nnajko; 02-10-2013 at 10:13.
nnajko is offline
KoNz
Junior Member
Join Date: Apr 2011
Location: Finland
Old 02-10-2013 , 10:12   Re: I need on retrieveing individual data.
Reply With Quote #5

Quote:
Originally Posted by nnajko View Post
Yeah use a variable
PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_iPlayerClass[33];

enum _:Class
{
    
Dog 0,
    
Bear,
    
Cat
}

enum Data
{
    
Level,
    
EXP
}

new 
pInfo[33][Class][Data];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test""CmdTest");
}

public 
CmdTest(id)
{
    
g_iPlayerClass[id] = Dog;
    
    
pInfo[id][g_iPlayerClass[id]][Level]++;

Hmm i think that woudlnt work on my case... Lemme show u what I've done. (Btw im unsure how to save individual xp too.)

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#define MAXCLASSES 5
new const CLASSES[MAXCLASSES][] = {
    
"None",
    
"Dog",
    
"Cat",
    
"Horse",
    
"Cow"

enum Class
{
    
None,
    
Dog,
    
Cat,
    
Horse,
    
Cow
}
new const 
LEVELS[6] = {
    
100
    
200
    
400
    
800,
    
1600,
    
3200
}
enum Data
{
    
Level,
    
EXP
}
new 
pInfo[33][Class][Data]
new 
PlayerXP[33],PlayerLevel[33],PlayerClass[33]
new 
XP_Kill,XP_Knife,XP_Hs,SaveXP,g_vault
public plugin_init()
{
    
register_plugin("XpMod""1.0""Fxfighter")
 
    
register_event("DeathMsg""eDeath""a"
 
    
SaveXP register_cvar("SaveXP","1")
    
XP_Kill register_cvar("XP_per_kill""20")
    
XP_Hs register_cvar("XP_hs_bonus","20")
    
XP_Knife register_cvar("XP_knife_bonus","20")
    
g_vault nvault_open("animod")
 
    
register_clcmd("say /class""ChangeClass")
    
register_clcmd("say_team /class""ChangeClass")
    
register_clcmd("say /xp""ShowHud")
    
register_clcmd("say_team /xp""ShowHud")
}
public 
eDeath(  )  

    new 
attacker read_data
    new 
iVictim read_data
     
    if(
attacker == iVictim || !is_user_connected(attacker) || get_user_team(attacker) == get_user_team(iVictim)) return; 
     
    new 
headshot read_data
     
    new 
weapon[7
    
read_data4weaponcharsmaxweapon ) )
    
  
    
PlayerXP[attacker] += get_pcvar_num(XP_Kill)
  
    if(
headshot
    
PlayerXP[attacker] += get_pcvar_num(XP_Hs
  
    if(
equal(weapon"knife")) 
    
PlayerXP[attacker] += get_pcvar_num(XP_Knife
  
  
    while(
PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) 
    { 
      
PlayerLevel[attacker] += 
      client_print
(attackerprint_chat"[Animal Mod] Congratulations! You are a level %i %s!"PlayerLevel[attacker],CLASSES[PlayerClass[attacker]])
    } 
    
ShowHud(attacker
    
SaveData(attacker
}
public 
ShowHud(id)
{
    
set_hudmessage(255000.750.0106.015.0)
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s",PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]])
}
public 
ChangeClass(id)
{
    new 
menu menu_create("Class Menu" "Class_Handle");
    
menu_additem(menu ,"Dog""1" 0);
    
menu_additem(menu ,"Cat""2" 0);
    
menu_additem(menu ,"Horse""3" 0);
    
menu_additem(menu ,"Cow""4" 0);
 
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL);
 
    
menu_display(id menu 0);
 
    return 
PLUGIN_CONTINUE;
}
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 are now a %s",CLASSES[i])
    }
    else
    {
        
client_print(id,print_chat,"You are alredy a %s",CLASSES[i])
    }
 
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE
}
public 
client_connect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
LoadData(id)
    }
}
public 
client_disconnect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
SaveData(id)
    }
    
PlayerXP[id] = 0
    PlayerLevel
[id] = 0
    PlayerClass
[id] = 0
}
public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
playerxp[32], playerlevel[32]
 
    
parse(vaultdataplayerxp31playerlevel31)
 
    
PlayerXP[id] = str_to_num(playerxp)
    
PlayerLevel[id] = str_to_num(playerlevel)
 
    return 
PLUGIN_CONTINUE


Some of this what u might see messy is my own trying
__________________

Replace it.

Last edited by KoNz; 02-10-2013 at 10:13.
KoNz is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 10:24   Re: I need on retrieveing individual data.
Reply With Quote #6

Instead of creating
PHP Code:
PlayerXP[33];
PlayerLevel[33]; 
You could make use of your variable pInfo;
PHP Code:
new pInfo[33][Class][Data]; 
Example, you use:
PHP Code:
PlayerXP[attacker] += get_pcvar_num(XP_Kill); 
Instead of
PHP Code:
pInfo[attacker][PlayerClass[attacker]][EXP] += get_pcvar_num(XP_Kill); 
So to print out player level for the current class, you would use:
PHP Code:
pInfo[id][PlayerClass[id]][Level]; 
That way you will have different levels and exp for each class, and I think that's what you want?

Last edited by nnajko; 02-10-2013 at 10:26.
nnajko is offline
KoNz
Junior Member
Join Date: Apr 2011
Location: Finland
Old 02-10-2013 , 10:27   Re: I need on retrieveing individual data.
Reply With Quote #7

Last time I used it that way but gave me warning but never tested it. Meybe I should test it now.
(Tag mismatch)
PHP Code:
pInfo[attacker][PlayerClass[attacker]][EXP] += get_pcvar_num(XP_Kill); 
__________________

Replace it.

Last edited by KoNz; 02-10-2013 at 10:28.
KoNz is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 10:32   Re: I need on retrieveing individual data.
Reply With Quote #8

Change
PHP Code:
enum Class
{
    
None,
    
Dog,
    
Cat,
    
Horse,
    
Cow
}

enum Data
{
    
Level,
    
EXP

to

PHP Code:
enum _:Class
{
    
None,
    
Dog,
    
Cat,
    
Horse,
    
Cow
}

enum _:Data
{
    
Level,
    
EXP

Notice the
PHP Code:
_
nnajko is offline
KoNz
Junior Member
Join Date: Apr 2011
Location: Finland
Old 02-10-2013 , 10:54   Re: I need on retrieveing individual data.
Reply With Quote #9

Okay my problem is that i cant make class names visible ingame. But it recognizes them.
If u try change twice to same class it says uve already that class in use.
So my problem is that I've managed to make individual xp for classes but it wont save them.

EDIT: Adding code in a moment... fixing couple things i found.


EDIT2: Added script. And it crashed on level up.

EDIT3: Found reason and fixed why crash. I used wrong way to check Level xp needing. Atm problem is doesn't show up class name and doesnt save xp. (There is individual xp but not saved)

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#define MAXCLASSES 5
enum _:Class
{
    
None,
    
Dog,
    
Cat,
    
Horse,
    
Cow
}
new const 
LEVELS[6] = {
    
100
    
200
    
400
    
800,
    
1600,
    
3200
}
enum _:Data
{
    
Level,
    
EXP
}
new 
pInfo[33][Class][Data]
new 
PlayerXP[33],PlayerLevel[33],PlayerClass[33]
new 
XP_Kill,XP_Knife,XP_Hs,SaveXP,g_vault
public plugin_init()
{
    
register_plugin("XpMod""1.0""Fxfighter")
 
    
register_event("DeathMsg""eDeath""a"
 
    
SaveXP register_cvar("SaveXP","1")
    
XP_Kill register_cvar("XP_per_kill""20")
    
XP_Hs register_cvar("XP_hs_bonus","20")
    
XP_Knife register_cvar("XP_knife_bonus","20")
    
g_vault nvault_open("animod")
 
    
register_clcmd("say /class""ChangeClass")
    
register_clcmd("say_team /class""ChangeClass")
    
register_clcmd("say /xp""ShowHud")
    
register_clcmd("say_team /xp""ShowHud")
}
public 
eDeath(  )  

    new 
attacker read_data
    new 
iVictim read_data
     
    if(
attacker == iVictim || !is_user_connected(attacker) || get_user_team(attacker) == get_user_team(iVictim)) return; 
     
    new 
headshot read_data
     
    new 
weapon[7
    
read_data4weaponcharsmaxweapon ) )
    
  
    
pInfo[attacker][PlayerClass[attacker]][EXP] += get_pcvar_num(XP_Kill); 
  
    if(
headshot
    
pInfo[attacker][PlayerClass[attacker]][EXP] += get_pcvar_num(XP_Hs
  
    if(
equal(weapon"knife")) 
    
pInfo[attacker][PlayerClass[attacker]][EXP] += get_pcvar_num(XP_Knife
  
  
    while(
pInfo[attacker][PlayerClass[attacker]][EXP] >= LEVELS[PlayerLevel[attacker]]) 
    { 
      
pInfo[attacker][PlayerClass[attacker]][Level] += 1
      client_print
(attackerprint_chat"[Animal Mod] Congratulations! You are a level %i %s"pInfo[attacker][PlayerClass[attacker]][Level],pInfo[attacker][PlayerClass[attacker]])
    } 
    
ShowHud(attacker)
    
SaveData(attacker
}
public 
ShowHud(id)
{
    
set_hudmessage(255000.750.0106.015.0)
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s",pInfo[id][PlayerClass[id]][Level],pInfo[id][PlayerClass[id]][EXP],pInfo[id][PlayerClass[id]])
}
public 
ChangeClass(id)
{
    new 
menu menu_create("Class Menu" "Class_Handle");
    
menu_additem(menu ,"Dog""1" 0);
    
menu_additem(menu ,"Cat""2" 0);
    
menu_additem(menu ,"Horse""3" 0);
    
menu_additem(menu ,"Cow""4" 0);
 
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL);
 
    
menu_display(id menu 0);
 
    return 
PLUGIN_CONTINUE;
}
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)
    {
        
SaveData(id)
        
PlayerClass[id] = i
        client_print
(id,print_chat,"You are now a %s",PlayerClass[id])
    }
    else
    {
        
client_print(id,print_chat,"You are alredy a %s",PlayerClass[id])
    }
 
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE
}
public 
client_connect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
LoadData(id)
    }
}
public 
client_disconnect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
        
SaveData(id)
    }
    
pInfo[id][PlayerClass[id]][EXP] = 0
    pInfo
[id][PlayerClass[id]][Level] = 0
}
public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",pInfo[id][PlayerClass[id]][EXP],pInfo[id][PlayerClass[id]][Level])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",pInfo[id][PlayerClass[id]][EXP],pInfo[id][PlayerClass[id]][Level])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
playerxp[32], playerlevel[32]
 
    
parse(vaultdataplayerxp31playerlevel31)
 
    
pInfo[id][PlayerClass[id]][EXP] = str_to_num(playerxp)
    
pInfo[id][PlayerClass[id]][Level] = str_to_num(playerlevel)
 
    return 
PLUGIN_CONTINUE

__________________

Replace it.

Last edited by KoNz; 02-10-2013 at 11:03.
KoNz is offline
nnajko
Senior Member
Join Date: May 2009
Location: Sweden
Old 02-10-2013 , 11:08   Re: I need on retrieveing individual data.
Reply With Quote #10

You still need this to print out the name of the class
PHP Code:
new const CLASSES[MAXCLASSES][] = 
{
    
"None",
    
"Dog",
    
"Cat",
    
"Horse",
    
"Cow"

To print out the class name
PHP Code:
CLASSES[PlayerClass[id]] 
Also change this
PHP Code:
while(pInfo[attacker][PlayerClass[attacker]][EXP] >= LEVELS[PlayerLevel[attacker]])  

to this
PHP Code:
if(pInfo[attacker][PlayerClass[attacker]][EXP] >= LEVELS[PlayerLevel[attacker]])  

Since you don't need a loop for that.

A typical save function would look something like this:
PHP Code:
public SaveData(id)
{
    new 
szAuth[35];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    new 
szKey[64], szData[255];
    for( new 
0MAXCLASSESi++ )
    {
        
formatex(szDatacharsmax(szData), "%s%i#%i#"szDatapInfo[id][i][EXP], pInfo[id][i][Level]);
    }
    
    
formatex(szKeycharsmax(szKey), "%s-Mod"szAuth);
    
    
nvault_set(g_vaultszKeyszData);

nnajko 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 20:32.


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