AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   save on/off (https://forums.alliedmods.net/showthread.php?t=326964)

anakonda001 08-25-2020 14:55

save on/off
 
Hi, how do I save the on/off values in the menu after changing the map? when the map changes, the on/off menu changes

in the sounds plugin I use this
new g_hVault = INVALID_HANDLE;
new bool:g_bDisabled[MAX_PLAYERS + 1];

on/off sounds are saved but the labels themselves are not in the menu, you need to save them in the menu too after changing the map

Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>

#pragma tabsize 0

#define PLUGIN  "Menu"
#define VERSION "2.0"
#define AUTHOR  "lol ;D"

new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_0

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_menu("Menu 1", keys, "func_menu")
        register_clcmd("menu", "server_menu" )

}

public client_authorized(id)
{
    client_cmd(id, "bind ^"F3^" ^"menu^"")
}

public server_menu(id)
{
    new name[32]
    get_user_name(id, name, 31)
    static menu[650], iLen
    iLen = 0
    iLen = formatex(menu[iLen], charsmax(menu) - iLen, "\yMenu players (1\2)^n\yHello, \w%s^n^n", name)

    if(Music[id])
    {
          iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \wsound grenade: \rOff^n")
          keys |= MENU_KEY_1
    }
    else
    {
          iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r1. \wsound grenade: \yOn^n")
          keys |= MENU_KEY_1
    }

    iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r2. \wfurther^n")
    keys |= MENU_KEY_2

    iLen += formatex(menu[iLen], charsmax(menu) - iLen, "\r0. \wexit^n^n")
    keys |= MENU_KEY_0

    show_menu(id, keys, menu, -1, "Menu 1")
    return PLUGIN_HANDLED
}

public func_menu(id, key)
{
    switch(key)
    {
          case 0:
          {
              if(!g_Disabled[id])
              {
                    client_cmd(id, "say /gsound")
                    g_Disabled[id] = true
              }
              else
              {
                    client_cmd(id, "say /gsound")
                    g_Disabled[id] = false
              }
              server_menu(id)
          }
    }
    return PLUGIN_HANDLED
}

stock GetAliveCt()
{
        new CountCt, i
        for(i = 1; i <= get_maxplayers(); i++)
                if(is_user_alive(i) && is_user_connected(i) && get_user_team(i) == 2)
                        CountCt++
        return CountCt
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/


fysiks 08-25-2020 22:08

Re: save on/off
 
If you want data to be preserved between maps, you need to save the data and re-load it on the next map. Since this is per-user data, you need to save their SteamID along with the data of interest. Then, in plugin_init(), you can load the file into the plugin (using a Trie would be the most efficient but an array would be more straight forward). Then, in client_authorized(), you would look in that data to find the SteamID and then set that value to your array for that player.

There are several ways to save the data. A plain text file and nVault are two ways to do this.

Also note that forcing a bind or other setting on a player is called "slowhacking" and is not supported here. Please remove it from your code.

anakonda001 08-26-2020 03:17

Re: save on/off
 
Quote:

Originally Posted by fysiks (Post 2715542)
If you want data to be preserved between maps, you need to save the data and re-load it on the next map. Since this is per-user data, you need to save their SteamID along with the data of interest. Then, in plugin_init(), you can load the file into the plugin (using a Trie would be the most efficient but an array would be more straight forward). Then, in client_authorized(), you would look in that data to find the SteamID and then set that value to your array for that player.

There are several ways to save the data. A plain text file and nVault are two ways to do this.

Also note that forcing a bind or other setting on a player is called "slowhacking" and is not supported here. Please remove it from your code.

I have a sound plugin connected to nVault, can you do what I want here?

HamletEagle 08-26-2020 05:48

Re: save on/off
 
Quote:

Originally Posted by anakonda001 (Post 2715567)
I have a sound plugin connected to nVault, can you do what I want here?

This is the scripting HELP section, not "do it for me section", so no, he can not do what you want. But he(or someone else) can HELP you do it yourself.
Start by trying to code it yourself, and if you get stuck or have specific questions, ask here(you should also show what you tried in terms of code).

anakonda001 08-26-2020 08:35

Re: save on/off
 
Quote:

Originally Posted by HamletEagle (Post 2715576)
This is the scripting HELP section, not "do it for me section", so no, he can not do what you want. But he(or someone else) can HELP you do it yourself.
Start by trying to code it yourself, and if you get stuck or have specific questions, ask here(you should also show what you tried in terms of code).

I don’t understand anything in scripting, if I could, I would try it myself, but I don’t understand how to do it


All times are GMT -4. The time now is 13:48.

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