Raised This Month: $ Target: $400
 0% 

[resolved] Vault and Events


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 10-22-2006 , 01:09   [resolved] Vault and Events
Reply With Quote #1

I want to make this plugin record the player's score and deaths in the vault and load them up whenever the player connects. So, the player's score and deaths are never set back to 0.

Here's the not-working code, it doesn't even show any of the client_print's when I tested it. And it didn't want to show up in amx_plugins until I added the register_concmd().

I never learned to use the vault, this is just ripped from the "XP based plugin" thread. And I don't know what the difference between register_message() and register_event() is...

Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <vault> new score[33] new deaths[33] new currentscore[33] new currentdeaths[33] new g_scoreinfo public plugin_init() {     register_plugin("Kill/Death Records", "1.0", "fluffy")     register_concmd("say saveme", "SaveXP")     g_scoreinfo = get_user_msgid("ScoreInfo")     //register_event("ScoreInfo", "ScoreInfo", "a") } public SaveXP(id) {     new authid[32];     get_user_authid(id,authid,31);         new vaultkey[64], vaultdata[64];         format(vaultkey,63,"score-%s",authid)     format(vaultdata,63,"%i",currentscore[id])     set_vaultdata(vaultkey,vaultdata)         format(vaultkey,63,"deaths-%s",authid)     format(vaultdata,63,"%i",currentdeaths[id])     set_vaultdata(vaultkey,vaultdata) } public LoadXP(id) {     new authid[32];     get_user_authid(id,authid,31);         new vaultkey[64], vaultdata[64];         format(vaultkey,63,"score-%s",authid)     get_vaultdata(vaultkey,vaultdata,63)     score[id] = str_to_num(vaultdata)         format(vaultkey,63,"deaths-%s",authid)     get_vaultdata(vaultkey,vaultdata,63)     deaths[id] = str_to_num(vaultdata)     } public client_connect(id) {     client_print(id, print_console, "Kill/Death Loaded.")     LoadXP(id) } public client_disconnect(id) {           client_print(id, print_console, "Kill/Death Saved.")     SaveXP(id) } public ScoreInfo() {     new playerid, playerscore, playerdeaths, data4, data5         playerid = read_data(1)         if(is_user_bot(playerid))     {         return PLUGIN_HANDLED     }         client_print(playerid, print_chat, "ScoreInfo function called.")         playerscore = read_data(2)     playerdeaths = read_data(3)         data4 = read_data(4)     data5 = read_data(5)         format(currentscore[playerid], 32, "%i", playerscore + score[playerid])         format(currentdeaths[playerid],32, "%i", playerdeaths + deaths[playerid])         message_begin(MSG_ALL, g_scoreinfo, {0,0,0}, playerid)     write_byte(playerid)     write_short(playerscore)     write_short(playerdeaths)     write_short(data4)     write_short(data5)     message_end()         return PLUGIN_CONTINUE }

Last edited by stupok; 10-23-2006 at 18:49.
stupok is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 10-22-2006 , 01:27   Re: Vault and Events
Reply With Quote #2

Try using client_authorized or client_putinserver instead of client_connect.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-22-2006 , 01:40   Re: Vault and Events
Reply With Quote #3

Doesn't change a thing.
stupok is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 10-22-2006 , 02:42   Re: Vault and Events
Reply With Quote #4

Try using nVault.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 10-22-2006 , 07:32   Re: Vault and Events
Reply With Quote #5

you have to use client_authorized... client_connect wont work...
[ --<-@ ] Black Rose is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-22-2006 , 14:15   Re: Vault and Events
Reply With Quote #6

I don't know how to use nVault, or any kind of vault for that matter. There is also a problem with my ScoreInfo event, because NONE of the client_print's get executed, and at least the ScoreInfo one should.

I tried client_putinserver, and it may no change. client_authorized should not be any different.

EDIT: I got the client_print for the ScoreInfo function to show up, but the other two on LoadXP and SaveXP do not show.

Here's the code I used:
Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <vault> new score[33] new deaths[33] new currentscore[33] new currentdeaths[33] //new g_scoreinfo public plugin_init() {     register_plugin("Kill/Death Records", "1.0", "fluffy")     register_concmd("say saveme", "SaveXP")     //g_scoreinfo = get_user_msgid("ScoreInfo")     register_event("ScoreInfo", "ScoreInfo", "a") } public SaveXP(id) {     new authid[32];     get_user_authid(id,authid,31);         new vaultkey[64], vaultdata[64];         format(vaultkey,63,"score-%s",authid)     format(vaultdata,63,"%i",currentscore[id])     set_vaultdata(vaultkey,vaultdata)         format(vaultkey,63,"deaths-%s",authid)     format(vaultdata,63,"%i",currentdeaths[id])     set_vaultdata(vaultkey,vaultdata) } public LoadXP(id) {     new authid[32];     get_user_authid(id,authid,31);         new vaultkey[64], vaultdata[64];         format(vaultkey,63,"score-%s",authid)     get_vaultdata(vaultkey,vaultdata,63)     score[id] = str_to_num(vaultdata)         format(vaultkey,63,"deaths-%s",authid)     get_vaultdata(vaultkey,vaultdata,63)     deaths[id] = str_to_num(vaultdata)     } public client_putinserver(id) {     client_print(id, print_console, "Kill/Death Loaded.")     LoadXP(id) } public client_disconnect(id) {           client_print(id, print_console, "Kill/Death Saved.")     SaveXP(id) } public ScoreInfo() {     new playerid, playerscore, playerdeaths, data4, data5         playerid = read_data(1)         if(is_user_bot(playerid))     {         return PLUGIN_HANDLED     }         client_print(playerid, print_chat, "ScoreInfo function called.")         playerscore = read_data(2)     playerdeaths = read_data(3)         data4 = read_data(4)     data5 = read_data(5)         format(currentscore[playerid], 32, "%i", playerscore + score[playerid])         format(currentdeaths[playerid],32, "%i", playerdeaths + deaths[playerid])         message_begin(MSG_ALL, 83, {0,0,0}, playerid)     //message_begin(MSG_ALL, g_scoreinfo, {0,0,0}, playerid)     write_byte(playerid)     write_short(playerscore)     write_short(playerdeaths)     write_short(data4)     write_short(data5)     message_end()         return PLUGIN_CONTINUE }

Last edited by stupok; 10-22-2006 at 14:29.
stupok is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-22-2006 , 15:56   Re: Vault and Events
Reply With Quote #7

This deserves a new post! I fixed all the kinks and here is the working code, though there may be some performance issues. I think the server lags a little with this plugin running...

Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <vault> #include <engine> new score[33] new deaths[33] new currentscore[33] new currentdeaths[33] new framecount public plugin_init() {     register_plugin("Kill/Death Records", "1.0", "fluffy")     register_concmd("say /save", "SaveXP")     register_event("ScoreInfo", "ScoreInfo", "a") } public server_frame() {     if(++framecount > 90)     {         for(new i = 0; i <= 32; i++)         {             if(is_user_bot(i))             {                 return PLUGIN_HANDLED             }                     new authid[32], vaultstring[256]             get_user_authid(i,authid,31)                         new xe[256]             num_to_str(currentscore[i], xe, 255)                         format(vaultstring, 255, "score%s=", authid)             set_vaultdata(vaultstring, xe)                         num_to_str(currentdeaths[i], xe, 255)                         format(vaultstring, 255, "deaths%s=", authid)             set_vaultdata(vaultstring, xe)             return PLUGIN_CONTINUE         }     }     return PLUGIN_CONTINUE } public SaveXP(id) {         if(is_user_bot(id))     {         return PLUGIN_HANDLED     }         new authid[32], vaultstring[256]     get_user_authid(id,authid,31)         new xe[256]     num_to_str(currentscore[id], xe, 255)         format(vaultstring, 255, "score%s=", authid)     set_vaultdata(vaultstring, xe)         num_to_str(currentdeaths[id], xe, 255)         format(vaultstring, 255, "deaths%s=", authid)     set_vaultdata(vaultstring, xe)     return PLUGIN_CONTINUE } public LoadXP(id) {     if(is_user_bot(id))     {         return PLUGIN_HANDLED     }         new authid[32], vaultstring[256]     get_user_authid(id, authid, 31)         format(vaultstring, 255, "score%s=", authid)         if(vaultdata_exists(vaultstring))     {         new xe[256]         get_vaultdata(vaultstring, xe, 255)         score[id] = str_to_num(xe)     }         format(vaultstring, 255, "deaths%s=", authid)         if(vaultdata_exists(vaultstring))     {         new xe[256]         get_vaultdata(vaultstring, xe, 255)         deaths[id] = str_to_num(xe)     }     return PLUGIN_CONTINUE } public client_putinserver(id) {     LoadXP(id) } public client_disconnect(id) {     SaveXP(id) } public ScoreInfo() {     new playerid, playerscore, playerdeaths, data4, data5         playerid = read_data(1)         if(is_user_bot(playerid))     {         return PLUGIN_HANDLED     }         client_print(playerid, print_chat, "ScoreInfo function called.")         playerscore = read_data(2)     playerdeaths = read_data(3)         data4 = read_data(4)     data5 = read_data(5)         currentscore[playerid] = playerscore + score[playerid]     currentdeaths[playerid] = playerdeaths + deaths[playerid]         message_begin(MSG_ALL, 83, {0,0,0}, playerid)     write_byte(playerid)     write_short(currentscore[playerid])     write_short(currentdeaths[playerid])     write_short(data4)     write_short(data5)     message_end()         return PLUGIN_CONTINUE }
stupok is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 10-22-2006 , 19:24   Re: [resolved, optimization?] Vault and Events
Reply With Quote #8

Optimization: Don't use server frame like that to save every so often.

nVault is faster than vault.

You should check if the player aleast connected when saving it for all the server.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
stupok
Veteran Member
Join Date: Feb 2006
Old 10-23-2006 , 17:10   Re: [resolved, optimization?] Vault and Events
Reply With Quote #9

Could you give me some tips on nvault, before I look it up myself? Or some links you find to be useful?

Also, the reason I use server_frame is because my server crashes sometimes, with 24-25 bots running around and other plugins running, so I want to ensure the data gets saved without the player having to disconnect.

Good point about checking if connected before saving.

Thanks +k

EDIT: I'll mess around with nvault when I have more time, but for now I got rid of engine, so I call the SaveXP function on the ScoreInfo event. That way, no score will ever be lost . And, no need that way to check if client is connected . This plugin is pretty well optimized IMO.

Last edited by stupok; 10-23-2006 at 18:50.
stupok 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 04:44.


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