AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [resolved] Vault and Events (https://forums.alliedmods.net/showthread.php?t=46235)

stupok 10-22-2006 01:09

[resolved] Vault and Events
 
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 }

XxAvalanchexX 10-22-2006 01:27

Re: Vault and Events
 
Try using client_authorized or client_putinserver instead of client_connect.

stupok 10-22-2006 01:40

Re: Vault and Events
 
Doesn't change a thing. :?

SweatyBanana 10-22-2006 02:42

Re: Vault and Events
 
Try using nVault.

[ --<-@ ] Black Rose 10-22-2006 07:32

Re: Vault and Events
 
you have to use client_authorized... client_connect wont work...

stupok 10-22-2006 14:15

Re: Vault and Events
 
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 }

stupok 10-22-2006 15:56

Re: Vault and Events
 
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 }

teame06 10-22-2006 19:24

Re: [resolved, optimization?] Vault and Events
 
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.

stupok 10-23-2006 17:10

Re: [resolved, optimization?] Vault and Events
 
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. :D

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 :up:. And, no need that way to check if client is connected :up: :up:. This plugin is pretty well optimized IMO.


All times are GMT -4. The time now is 04:44.

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