Raised This Month: $51 Target: $400
 12% 

[Help] point system


Post New Thread Reply   
 
Thread Tools Display Modes
hannes
Member
Join Date: Sep 2010
Old 10-20-2014 , 03:09   Re: [Help] point system
Reply With Quote #11

Quote:
Originally Posted by zmd94 View Post
Please close your nVault.
PHP Code:
public plugin_end()
{
    
nvault_close(g_vault)


Had to edit
Code:
public client_authorized( id )
{
    get_user_authid(id, g_iAuthID[ id ] , charsmax( g_iAuthID[] ) );
    LoadData(id)
}
Edit:
Now the code looks like this :
PHP Code:
/* Plugin generated by AMXX-Studio */

new const PLUGIN[] =    "Point"
new const VERSION[] =     "0.0.1"
new const AUTHOR[] =    "hannes"

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <chatcolor>

new g_iAuthID[33][36]
new 
Points[33]
new 
XP_Kill
new XP_Knife
new XP_Hs
new g_vault


public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
 
    
register_event("DeathMsg""eDeath""a") ;
    
    
XP_Kill register_cvar("XP_per_kill""2");
    
XP_Hs register_cvar("XP_hs_bonus","2");
    
XP_Knife register_cvar("XP_knife_bonus","2");
    
g_vault nvault_open("point");
    
    
register_clcmd("say /points""SayPoints");
    
register_clcmd("say_team /points""SayPoints");
}

public 
eDeath(  ) 
{
    new 
attacker read_data)
    new 
headshot read_data)
    new 
clipammoweapon get_user_weapon(attacker,clip,ammo);
 
    
Points[attacker] += get_pcvar_num(XP_Kill)
 
    if(
headshot)
    
Points[attacker] += get_pcvar_num(XP_Hs)
 
    if(
weapon == CSW_KNIFE)
    
Points[attacker] += get_pcvar_num(XP_Knife)
 
    
SaveData(attacker)
}

public 
plugin_end()
{
    
nvault_close(g_vault)
}

public 
SayPoints(id)
{
    
ColorChat(idGREY"^4*^3 You have ^4%d^3 Points -^3 [^4v%s^3]" Points[id] , VERSION );
}

public 
client_authorizedid )
{
    
get_user_authid(idg_iAuthIDid ] , charsmaxg_iAuthID[] ) );
    
LoadData(id)
}

public 
client_disconnect(id)
{
    
SaveData(id)
}

public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)

    new 
vaultkey[64]
    new 
vaultdata[256]

    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#",Points[id])

    
nvault_setg_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#",Points[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
points[32]
 
    
parse(vaultdatapoints31)
 
    
Points[id] = str_to_num(points)
 
    return 
PLUGIN_CONTINUE

Should i change anything? or isit good like this?
thanks!
__________________

Last edited by hannes; 10-20-2014 at 03:41.
hannes is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 10-20-2014 , 03:53   Re: [Help] point system
Reply With Quote #12

You can add this code in the plugin_init():
PHP Code:
    if(g_vault == INVALID_HANDLE)
        
set_fail_state("Error opening nVault"
So that, it will throw a plugin error if INVALID_HANDLE is returned.

Lastly, please get used to use charsmax or sizeof - 1 instead of writing the number.
zmd94 is offline
hannes
Member
Join Date: Sep 2010
Old 10-20-2014 , 04:13   Re: [Help] point system
Reply With Quote #13

Quote:
Originally Posted by zmd94 View Post
You can add this code in the plugin_init():
PHP Code:
    if(g_vault == INVALID_HANDLE)
        
set_fail_state("Error opening nVault"
So that, it will throw a plugin error if INVALID_HANDLE is returned.

Lastly, please get used to use charsmax or sizeof - 1 instead of writing the number.
Thanks, one more thing... how can i save & load users kills?

As you see im kinda new to amxx.
If you don't wanna help me more im fine, thanks for your help
__________________
hannes is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 10-20-2014 , 04:37   Re: [Help] point system
Reply With Quote #14

Sorry, what do you mean by users kills?

By the way, you have already saved the data with this code:
PHP Code:
public client_disconnect(id)
{
    
SaveData(id)

Next, I don't think this code is necessary:
PHP Code:
SaveData(attacker

Last edited by zmd94; 10-20-2014 at 04:41.
zmd94 is offline
hannes
Member
Join Date: Sep 2010
Old 10-20-2014 , 05:01   Re: [Help] point system
Reply With Quote #15

Quote:
Originally Posted by zmd94 View Post
Sorry, what do you mean by users kills?

By the way, you have already saved the data with this code:
PHP Code:
public client_disconnect(id)
{
    
SaveData(id)

Next, I don't think this code is necessary:
PHP Code:
SaveData(attacker

Okay thanks again ^^,
By users kill i mean that i save his total kills so i can print it like "* You have 34 Points and 23 Total kills"
__________________
hannes is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 10-20-2014 , 05:25   Re: [Help] point system
Reply With Quote #16

For total kills, you can just use "get_user_frag(id)".

Last edited by zmd94; 10-21-2014 at 10:17.
zmd94 is offline
hannes
Member
Join Date: Sep 2010
Old 10-20-2014 , 06:30   Re: [Help] point system
Reply With Quote #17

Quote:
Originally Posted by zmd94 View Post
For total kills, you can just use "get_user_frag(id)". By the way, just add this to your plugin_end():
PHP Code:
public plugin_end()
{
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum)
    
    new 
iPlayer
    
for(new 0iNumi++)
    {
        
iPlayer iPlayers[i]
        
        
SaveData(iPlayer)
    }
    
    
nvault_close(g_vault)

How could i do this better?

Warning: Loose indentation on line 62
1 Warning.

PHP Code:
/* Plugin generated by AMXX-Studio */

new const PLUGIN[] =    "Point"
new const VERSION[] =     "0.0.1"
new const AUTHOR[] =    "hannes"

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <cstrike>
#include <fun>
#include <chatcolor>

new g_iAuthID[33][36]
new 
Points[33]

new 
XP_Kill
new XP_Knife
new XP_Hs
new g_vault

new iFrags[33]
new 
iDeaths[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
 
    
register_event("DeathMsg""eDeath""a") ;
    
    
XP_Kill register_cvar("XP_per_kill""1");
    
XP_Hs register_cvar("XP_hs_bonus","1");
    
XP_Knife register_cvar("XP_knife_bonus","1");
    
    
register_clcmd("say /points""SayPoints");
    
register_clcmd("say_team /points""SayPoints");
    
register_clcmd("say /d" ,"Sayd");
    
    
g_vault nvault_open("point");
    
    if(
g_vault == INVALID_HANDLE)
        
set_fail_state("Error opening nVault");
}

public 
eDeath(  ) 
{
    new 
attacker read_data)
    new 
victim read_data)
    new 
headshot read_data)
    new 
clipammoweapon get_user_weapon(attacker,clip,ammo);
 
    
 
    
Points[attacker] += get_pcvar_num(XP_Kill)
 
    if(
headshot)
    
Points[attacker] += get_pcvar_num(XP_Hs)
 
    if(
weapon == CSW_KNIFE)
    
Points[attacker] += get_pcvar_num(XP_Knife
    
    if(
cs_get_user_team(attacker) != cs_get_user_team(victim)) {
        
iFrags[attacker]++
        
iDeaths[victim]++
    }
}

public 
plugin_end()
{
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum)
    
    new 
iPlayer
    
for(new 0iNumi++)
    {
        
iPlayer iPlayers[i]
        
        
SaveData(iPlayer)
    }
    
    
nvault_close(g_vault)
}  

public 
SayPoints(id)
{
    
ColorChat(idGREY"^4*^3 You have ^4%d^3 Points -^3 [^4v%s^3]" Points[id] , VERSION );
}

public 
client_authorizedid )
{
    
get_user_authid(idg_iAuthIDid ] , charsmaxg_iAuthID[] ) );
    
LoadData(id);
}

public 
client_disconnect(id)
{
    
SaveData(id);
}

public 
SaveData(id)
{
    new 
AuthID[35]; get_user_authid(idAuthIDcharsmax(AuthID))

    new 
vaultkey[64]
    new 
vaultdata[256]

    
format(vaultkeycharsmax(vaultkey),"%s-Mod",AuthID)
    
format(vaultdatacharsmax(vaultdata),"%i#%i#",Points[id], iFrags[id])
    
    
nvault_setg_vault vaultkey vaultdata );
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id)
{
    new 
AuthID[35]; get_user_authid(idAuthIDcharsmax(AuthID))
    new 
vaultkey[64],vaultdata[256]
    
    
format(vaultkey,charsmax(vaultkey),"%s-Mod",AuthID)
    
format(vaultdata,charsmax(vaultdata),"%i#%i#",Points[id], iFrags[id])
    
nvault_get(g_vault,vaultkey,vaultdata,charsmax(vaultdata))
    
replace_all(vaultdatacharsmax(vaultdata), "#"" ")
    new 
points[32],Frags[33], Deaths[33]
    
parse(vaultdatapointscharsmax(points), Fragscharsmax(Frags), Deathscharsmax(Deaths))
    
Points[id] = str_to_num(points)
    
iFrags[id] = str_to_num(Frags)
    
iDeaths[id] = str_to_num(Deaths)
    return 
PLUGIN_CONTINUE
}


public 
Sayd(id)
{
    
ColorChat(idGREY"^4*^3 You have ^4%d^3 Points & %d Kills & %d Deaths -^3 [^4v%s^3]" Points[id] , iFrags[id] , iDeaths[id] , VERSION );

__________________

Last edited by hannes; 10-20-2014 at 14:56.
hannes is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-21-2014 , 10:03   Re: [Help] point system
Reply With Quote #18

@hannes, lear how to search. Loose indentation warning is harmless, it just tells you that your code is not properly "arranged".
@zmd94 , why saving points on plugin_end ? It's enough to save when a player disconnect.
__________________

Last edited by HamletEagle; 10-21-2014 at 10:04.
HamletEagle is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 10-21-2014 , 10:17   Re: [Help] point system
Reply With Quote #19

If it is just enough to save when a player disconnect, then it is my mistake. ;)
zmd94 is offline
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 10-21-2014 , 10:23   Re: [Help] point system
Reply With Quote #20

Quote:
Originally Posted by HamletEagle View Post
@hannes, lear how to search. Loose indentation warning is harmless, it just tells you that your code is not properly "arranged".
@zmd94 , why saving points on plugin_end ? It's enough to save when a player disconnect.
At least there's no error xP
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
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 23:03.


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