[pedido] Explicación guardado de heromod nvault
#1
Espero que este posteado en la seccion correcta :/

Bueno queria perdirles si me podrian hacer como un tutorial explicando como funciona el guardado del super hero mod (no explicar el uso de las funciones de nvault sino que se me complica entender las variables y los datos que va tomando...)

superheronvault.inc

Código PHP:
// SuperHero nVault Include File
// Version 1.2.0

//----------------------------------------------------------------------------------------------
// Abstract Methods that must be implemented by a save superhero include file...
//
// memoryTableWrite()
// loadXP(id, const savekey[32])
// cleanXP(clearAll = false)
//----------------------------------------------------------------------------------------------

#if defined _shsave_included || !defined SHCORE
    #endinput
#endif
#define _shsave_included

//Include the nvault file
#include <nvault>

//Global to save the vault handle
new gVaultHandle

//----------------------------------------------------------------------------------------------
saving_init()
{
    
gVaultHandle nvault_open("superhero")

    if ( 
gVaultHandle == INVALID_HANDLE ) {
        
debugMsg(00"Error opening nVault file: superhero.vault")
    }
}
//----------------------------------------------------------------------------------------------
public memoryTableWrite()
{
    if ( !
get_pcvar_num(sh_savexp) ) return

    
debugMsg(03"Writing XP Data to nVault file")

    
// Write Memory Table to File
    
for ( new 1gMemoryTableCountx++ ) {
        if ( 
gMemoryTableKeys[x][0] != '^0' ) {
            
writeData(x)
        }
        
// Can even clear the MemoryKey - if a player is disconnected no reason to save again and again...
        
gMemoryTableKeys[x][0] = '^0'
    
}

    
// No need to keep disconnected players around if this has been flushed...
    
gMemoryTableCount 33
}
//----------------------------------------------------------------------------------------------
writeData(id)
{
    
// Formats Player Information and writes to file:
    // "name" XP USERFLAGS "SKILL1" "SKILL2" ...
    
static data[1501]
    new 
heroIndexlen
    
new powerCount gMemoryTablePowers[id][0]

    
data[0] = '^0'

    
len += formatex(data[len], charsmax(data)-len"^"%s^" %d %d"gMemoryTableNames[id], gMemoryTableXP[id], gMemoryTableFlags[id])

    for ( new 
1<= powerCount && <= gSuperHeroCount && len charsmax(data); x++ ) {
        
heroIndex gMemoryTablePowers[id][x]
        if ( -
heroIndex gSuperHeroCount ) {
            
len += formatex(data[len], charsmax(data)-len" ^"%s^""gSuperHeros[heroIndex][hero])
        }
    }

    
nvault_set(gVaultHandlegMemoryTableKeys[id], data)

    if ( 
id <= SH_MAXSLOTS ) {
        
gChangedHeroes[id] = false
    
}
}
//----------------------------------------------------------------------------------------------
loadXP(id, const savekey[32])
{
    static 
Right[1501], temp
    Right
[0] = '^0'

    
if ( nvault_lookup(gVaultHandlesavekeyRightcharsmax(Right), temp) ) {
        
// parseXP

        // "name" XP USERFLAGS "SKILL1" "SKILL2" ...
        
new heroIndexpowerCountmaxPowersplayerLevel
        
static Left[32]
        
Left[0] = '^0'

        
// Get the name out
        
strbrkqt(RightLeftcharsmax(Left), Rightcharsmax(Right))
        
Left[0] = '^0'

        
// Get the XP out and save it
        
strbrkqt(RightLeftcharsmax(Left), Rightcharsmax(Right))
        
gPlayerXP[id] = str_to_num(Left)
        
gPlayerLevel[id] = playerLevel getPlayerLevel(id)
        
setLevel(idplayerLevel)
        
Left[0] = '^0'

        
// Get the User Flags out and save them
        
strbrkqt(RightLeftcharsmax(Left), Rightcharsmax(Right))
        
gPlayerFlags[id] = str_to_num(Left)

        
// Now load in all the skills
        
powerCount 0
        maxPowers 
min(get_pcvar_num(sh_maxpowers), SH_MAXLEVELS)

        while ( 
Right[0] != '^0' && powerCount maxPowers ) {
            
Left[0] = '^0'
            
strbrkqt(RightLeftcharsmax(Left), Rightcharsmax(Right))
            
heroIndex getHeroID(Left)
            if ( -
heroIndex gSuperHeroCount ) {
                if ( 
getHeroLevel(heroIndex) <= playerLevel ) {
                    
gPlayerPowers[id][0] = ++powerCount
                    gPlayerPowers
[id][powerCount] = heroIndex
                    initHero
(idheroIndexSH_HERO_ADD)
                }
            }
        }
    }

    
memoryTableUpdate(id)

    return 
true
}
//----------------------------------------------------------------------------------------------
cleanXP(bool:clearAll)
{
    if ( 
clearAll ) {
        
nvault_prune(gVaultHandle00)
    }
    else if ( 
get_pcvar_num(sh_savexp) ) {
        new 
xpSaveDays get_pcvar_num(sh_xpsavedays)

        if ( 
xpSaveDays ) return

        
nvault_prune(gVaultHandle0get_systime() - (xpSaveDays 24 3600))
    }
}
//----------------------------------------------------------------------------------------------
saving_end()
{
    
//Close the vault to save all the data
    
nvault_close(gVaultHandle)
}
//---------------------------------------------------------------------------------------------- 

dejo el sma del heromod para que se fijen
si es complicado explicarlos no se hagan drama , pero si me pueden ayudar se los agradeceria. Un saludo!


Archivos adjuntos
.sma   Descargar AMXX / superheromod.sma (Tamaño: 187.26 KB / Descargas: 13)
Responder


Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)