Raised This Month: $ Target: $400
 0% 

Saving problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LyleChriss
Junior Member
Join Date: Dec 2015
Location: Hungary
Old 12-11-2015 , 14:37   Saving problem
Reply With Quote #1

Hello guys!

EDIT: I'm so sorry yesterday I didn't searched enough to find the solution but it was in a tutorial's example. Anyway I leave here my post, so if someone needs it, he/she can use it. The solution is in the last example of this tutorial:
https://forums.alliedmods.net/showthread.php?t=91503

I made a weapon skin plugin which reads the things from a .ini file. (Yeah, I know, there are tons of this type of plugins, but why not write one on my own.)

Already at the save method, I had problems, but I figured out, what to do. But now, I can't make a load function for it, because I dont' know how to read in with parse into "unknown" numbers of arrays.*

Unknown numbers of arrays* because I don't want to edit the load and save methods if I add another weapon into the menu.

Here's the code. I hope that someone can help me.

Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <fakemeta>
#include <csstats>

new skins_types[][] =
{
    "AK47",
    "AWP",
    "M4A1"
}

new g_vault
new Array:Skin_Type, Array:Skin_Name, Array:Skin_Cost, Array:Skin_Model
new skins_count, fgy[33], skin_chosen[sizeof skins_types][33]

public plugin_init() {
    register_plugin("Fegyver skin menü", "3.0", "LyleChriss")
    
    register_clcmd("say /menu", "cmd_menu")
    register_clcmd("say /skin", "cmd_menu")
    
    register_event("CurWeapon", "EvCurWeapon", "be", "1=1")
    
    g_vault = nvault_open("fegyverskin")
}

public plugin_cfg()
{
    new skins_file[64]
    get_configsdir(skins_file,charsmax(skins_file))
    format(skins_file,charsmax(skins_file),"%s/skins.ini",skins_file)
    if(!file_exists(skins_file))
        set_fail_state("skins.ini nem talalhato")
    for(new line;line<file_size(skins_file,1);line++)
    {
        new readdata[1024],txtlen
        new d1[64],d2[64],d3[64],d4[64],d5[64]
        read_file(skins_file,line,readdata,charsmax(readdata),txtlen)
        parse(readdata,d1,63,d2,63,d3,63,d4,63,d5,63)
        if(readdata[0]==';'||equal(readdata,"")||equal(d2,""))
            continue
        ArrayPushCell(Skin_Type,str_to_num(d1))
        ArrayPushString(Skin_Name,d2)
        ArrayPushCell(Skin_Cost,str_to_num(d3))
        ArrayPushString(Skin_Model, d4)
        skins_count++
    } 
}

public plugin_precache()
{
    Skin_Type=ArrayCreate(1,1)
    Skin_Name=ArrayCreate(64)
    Skin_Cost=ArrayCreate(1,1)
    Skin_Model=ArrayCreate(64)
    
    static string[100];
    
    for (new i = 0; i < ArraySize(Skin_Model); i++)
    {
        ArrayGetString(Skin_Model, i, string, charsmax(string))
        precache_model(string)
    }
}

public cmd_menu(id)
{
    new title[256],item[128]
    new szStats[8],szBHits[8];
    get_user_stats(id,szStats,szBHits);
    
    format(title,charsmax(title),"\Válaszd ki a fegyvered típusát!^n\wÖléseid: \r%s", szStats[0])
    
    new menu=menu_create(title,"skin_type_handler")
    for(new i=0;i<sizeof skins_types;i++)
    {
        new count
        for(new j;j<skins_count;j++)
            if(ArrayGetCell(Skin_Type,j)==i) count++
        format(item,charsmax(item),"\w%s \y(%d db)",skins_types[i],count)
        menu_additem(menu,item)
    }
    menu_display(id,menu)
}

public skin_type_handler(id,menu,key)
{
    if(key==MENU_EXIT)
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    new item[128]
    new menu2=menu_create("\yVálassz fegyver kinézetet!","skin_handler")
    new name[64]
    new szStats[8],szBHits[8];
    new szKell[32]
    get_user_stats(id,szStats,szBHits);
    get_user_name(id,name,charsmax(name))
    for(new i=0;i<skins_count;i++)
    {
        if(ArrayGetCell(Skin_Type,i)!=key)
            continue
        new name[64]
        ArrayGetString(Skin_Name,i,name,charsmax(name))
        new cost = ArrayGetCell(Skin_Cost,i)
        
        
        formatex(szKell, charsmax(szKell), "[Még %d ölés]", cost-szStats[0])
        formatex(item, charsmax(item), "%s %s", name, szStats[0] < cost ? szKell : "[Elérve]")
        new num[64]
        num_to_str(i,num,charsmax(num))
        menu_additem(menu2,item,num)
    }
    menu_setprop(menu2,MPROP_PERPAGE,5)
    menu_display(id,menu2)
    return PLUGIN_CONTINUE
}

public skin_handler(id,menu,key)
{
    if(key==MENU_EXIT)
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    new access,data[32],callback,name[64]
    menu_item_getinfo(menu,key,access,data,charsmax(data),_,_,callback)
    new skinid=str_to_num(data)
    new cost=ArrayGetCell(Skin_Cost,skinid)
    ArrayGetString(Skin_Name,skinid,name,charsmax(name))
    new szStats[8],szBHits[8];
    get_user_stats(id,szStats,szBHits);
    if(szStats[0] >= cost)
    {
        for(new i=0;i<sizeof skins_types;i++)
        {
            if(ArrayGetCell(Skin_Type,skinid) == i) skin_chosen[i][id] = skinid
        }
        client_print(id, print_chat, "Sikeresen kiválasztottad a(z) %s skint!", name)
    }
    else
    {
        client_print(id, print_chat, "Nincs elég ölésed ezen skin használatához!")
    }
    return PLUGIN_CONTINUE
}

public EvCurWeapon(id)
{
    fgy = get_user_weapon2(id)
    new num, model[64]
    
    for(new i=0;i<sizeof skins_types;i++)
    {
        if(equali(skins_types[i], fgy))
        {
            num = skin_chosen[i][id]
            ArrayGetString(Skin_Model, num, model, charsmax(model))
            set_pev(id, pev_viewmodel2, model)
        }
    }
    
}

public client_disconnect(id)
{
    if(!is_user_bot(id) && !is_user_hltv(id))
    {
        save(id)
    }
    for(new i=0; i< sizeof skins_types; i++)
    {
        skin_chosen[i][id] = 9999
    }
}

public client_connect(id)
{
    for(new i=0; i< sizeof skins_types; i++)
    {
        skin_chosen[i][id] = 9999
    }
    if(!is_user_bot(id) && !is_user_hltv(id))
    {
        //load(id)
    }
}

public save(id)
{
    new vaultkey[64], vaultdata[2048], Len
    get_user_authid(id, vaultkey, charsmax(vaultkey))
    
    for(new i=0; i< sizeof skins_types; i++)
    {
        Len += format(vaultdata[Len], 2048-Len, "%i ", skin_chosen[i][id])
    }
    nvault_set(g_vault, vaultkey, vaultdata)
}

/*public load(id)
{
    new vaultkey[64], vaultdata[2048], Len
    get_user_authid(id, vaultkey, charsmax(vaultkey))
    
    for(new i=0; i< sizeof skins_types; i++)
    {
        Len += format(vaultdata[Len], 2048-Len, "%i", skin_chosen[i][id])
    }
    if(nvault_get(vault, vaultkey, vaultdata, charsmax(vaultdata))) 
    {
        new skin[sizeof skins_types][32]
    */    

//==========================//
//                  Stocks                   //
//=========================//
stock get_user_weapon2( id )
{
    new szWeapon[20];
    get_weaponname(get_user_weapon(id), szWeapon, charsmax(szWeapon));
    replace(szWeapon, charsmax(szWeapon), "weapon_", "");

    return szWeapon;
}
PS: If you read it, thanks Connor for the stock.
And sorry if I made mistakes both in the code and it the post /English/. The first is because I am still learning and the second too...

Last edited by LyleChriss; 12-12-2015 at 06:01. Reason: Resolved
LyleChriss 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 18:01.


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