AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save to .ini or .txt files (https://forums.alliedmods.net/showthread.php?t=193205)

Randomize 08-17-2012 11:30

Save to .ini or .txt files
 
Can someone make this save to .ini or .txt file?

PHP Code:

    g_vault nvault_open("animod")
    
//we just opened a new connection NVAULT connection
    // we will call it animod

    
register_clcmd("say /rank""ShowHud")
    
register_clcmd("say_team /rank""ShowHud")
}
public 
client_connect(id)
{
    if(
get_pcvar_num(SavePoint) == 1)
    {
        
        
LoadData(id)
    }
    if(
get_pcvar_num(SaveExp) == 1)
    {
        
        
LoadData(id)
    }
}
public 
client_disconnect(id)
{
    if(
get_pcvar_num(SavePoint) == 1)
    {
    
        
SaveData(id)
    }
    if(
get_pcvar_num(SaveExp) == 1)
    {
    
        
SaveData(id)
    }
    
PlayerPoint[id] = 0
    PlayerExp
[id] = 0
}
public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerPoint[id],PlayerExp[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerPoint[id],PlayerExp[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
playerpoint[32], playerexp[32]
 
    
parse(vaultdataplayerpoint31playerexp31)
 
    
PlayerPoint[id] = str_to_num(playerpoint)
    
PlayerExp[id] = str_to_num(playerexp)
 
    return 
PLUGIN_CONTINUE



matsi 08-17-2012 14:18

Re: Save to .ini or .txt files
 
Quote:

Originally Posted by Randomize (Post 1774081)
Can someone make this save to .ini or .txt file?

PHP Code:

    g_vault nvault_open("animod")
    
//we just opened a new connection NVAULT connection
    // we will call it animod

    
register_clcmd("say /rank""ShowHud")
    
register_clcmd("say_team /rank""ShowHud")
}
public 
client_connect(id)
{
    if(
get_pcvar_num(SavePoint) == 1)
    {
        
        
LoadData(id)
    }
    if(
get_pcvar_num(SaveExp) == 1)
    {
        
        
LoadData(id)
    }
}
public 
client_disconnect(id)
{
    if(
get_pcvar_num(SavePoint) == 1)
    {
    
        
SaveData(id)
    }
    if(
get_pcvar_num(SaveExp) == 1)
    {
    
        
SaveData(id)
    }
    
PlayerPoint[id] = 0
    PlayerExp
[id] = 0
}
public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerPoint[id],PlayerExp[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerPoint[id],PlayerExp[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
playerpoint[32], playerexp[32]
 
    
parse(vaultdataplayerpoint31playerexp31)
 
    
PlayerPoint[id] = str_to_num(playerpoint)
    
PlayerExp[id] = str_to_num(playerexp)
 
    return 
PLUGIN_CONTINUE



There is no reason saving them in .txt file but thats your problem. Since you can't do this yourself this is more of request than "scripting help".

Why do you want to save in .txt file?

So correct section:
Suggestions / Requests
( Don't repost )

Liverwiz 08-17-2012 14:38

Re: Save to .ini or .txt files
 
You might be able to do SaveData by doing log_to_file("data.txt", "%s; %s", vaultkey, vaultdata)

But you'll have to get a bit creative in LoadDAta so you can properly seperate the key from the data, and read each line and its timestamp. What's the fun if i give you all the answers. :P

Torge 08-17-2012 16:00

Re: Save to .ini or .txt files
 
You can also use fvault.

Look at your "Doesn't work :/" thread I posted a example for you.

Randomize 08-18-2012 01:44

Re: Save to .ini or .txt files
 
matsi: I make my own launcher for counter strike, it detects the value of the points and exp
LiverWiz is there any tutor?
Torge: I had tried it, it saves to .txt but the CS doesn't load the .txt file again, so the exp and point start from 0 again

Liverwiz 08-18-2012 12:27

Re: Save to .ini or .txt files
 
Quote:

Originally Posted by Randomize (Post 1774868)
LiverWiz is there any tutor?

not much that i've seen. But there is a whole library of file minipulation. Look around.

Randomize 08-19-2012 08:34

Re: Save to .ini or .txt files
 
what do you mean with file manipulation? O.o

Liverwiz 08-19-2012 10:10

Re: Save to .ini or .txt files
 
http://www.amxmodx.org/funcwiki.php?go=inc&id=3
File I/O, directory usage, processing, etc. You could also use it in cooperation with regex to make things even easier.


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

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