AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save .... (https://forums.alliedmods.net/showthread.php?t=222175)

med 07-30-2013 17:37

Save ....
 
hello all ..... i am new at scripting and i need help

How to save data ? The best way

like money ect ........

Black Rose 07-30-2013 18:09

Re: Save ....
 
Do you mean save within your script or more of a permanent save in a database, like vault or a SQL?

med 07-31-2013 04:34

Re: Save ....
 
i mean like vault ...
exemple ! this a part of plugin..
new icoins // kill = 3 coins
how to save this .. if server restart or shutdown or change maps..

grs4 07-31-2013 10:23

Re: Save ....
 
Very Simple:
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <nvault>
#include <hamsandwich>

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

#define TASK_HUD 3035

new vault
new coins[33]
new nicks[33][33]

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    vault = nvault_open("coins") // coins - name of the file
   
    register_event("DeathMsg", "DeathMsg", "a")
    RegisterHam(Ham_Spawn, "player", "Respawn", 1)
}
public client_connect(id)
{
    get_user_name(id, nicks[id], 32)
    Load(id)
    set_task(1.0, "ShowHud", id+TASK_HUD)
}
public client_disconnect(id)
{
    Save(id)
    replace(nicks[id], 32, nicks[id], "")
}
public Respawn(id)
{
    if(is_user_alive(id))
    {
        Save(id)
        if(!task_exists(id+TASK_HUD))
            set_task(1.0, "ShowHud", id+TASK_HUD)
    }
}
public DeathMsg()
{
    new attacker = read_data(1)
    new victim = read_data(2)
   
    if(is_user_alive(attacker) && is_user_connected(victim) && get_user_team(attacker) != get_user_team(victim))
    {
        coins[attacker]++
        Save(attacker)
    }
}
public ShowHud(id)
{
    id-=TASK_HUD
    if(is_user_alive(id))
    {
        set_hudmessage(255, 255, 0, 0.02, 0.29, 0, 6.0, 1.1)
        show_hudmessage(id, "Coins: %d", coins[id])
        set_task(0.9, "ShowHud", id+TASK_HUD)
    }
    else
    {
        remove_task(id+TASK_HUD)
        return PLUGIN_CONTINUE
    }
   
    return PLUGIN_CONTINUE
}
       
public Save(id)
{
    nvault_set(vault, nicks[id], coins[id])
}
public Load(id)
{
    new coin[5]
    nvault_get(vault, nicks[id], coin)
    coins[id] = str_to_num(coin)
}
public plugin_end()
{
    nvault_close(vault)
}

Coins ++ when player kill enemy on him team

med 07-31-2013 16:26

Re: Save ....
 
ty :)

grs4 07-31-2013 17:35

Re: Save ....
 
np

simanovich 07-31-2013 20:00

Re: Save ....
 
With witch system you want to work?
SQL?
Vault (includes nVault, fVault and nfVault)?
File Save (not as Vault)?


All times are GMT -4. The time now is 15:49.

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