AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Using BuildPath() (https://forums.alliedmods.net/showthread.php?t=198608)

GsiX 10-18-2012 09:49

Using BuildPath()
 
PHP Code:

if ( !FileExists"addons/sourcemod/data/l4d2_luffy.txt" )) 
    { 
        
decl String:path[256]; 
        
BuildPathPath_SMpathsizeofpath ), "data/l4d2_luffy.txt"); 
        
ServerCommand"clear" );
        
PrintToServer"[LUFFY]: File path created: addons/sourcemod/data/l4d2_luffy.txt" ); 
    } 

It doesn't create the file for me. Any thought?

FaTony 10-18-2012 10:08

Re: Using BuildPath()
 
It doesn't do what you think it does. Since SourcePawn exposes it's deep C roots, you need to use OpenFile which uses fopen under the hood. BuildPath is needed to correctly resolve paths relative to SM directory, so first you build path and then open file with, say, "w" mode to create one.

GsiX 10-18-2012 10:18

Re: Using BuildPath()
 
Thank FaTony, this gonna take log way. Is the file is automatically created or i need to manually create 1?

Yay.. she say undefined symbol path on the OpenFile things.
PHP Code:

public OnConfigsExecuted()
{
    if ( !
FileExists"addons/sourcemod/data/l4d2_luffy_rpg.txt" )) 
    { 
        
decl String:path[256]; 
        
BuildPathPath_SMpathsizeofpath ), "data/l4d2_luffy_rpg.txt"); 
        
ServerCommand"clear" );
        
PrintToServer"[LUFFY]: File path created: addons/sourcemod/data/l4d2_luffy.txt" ); 
    }
    new 
Handle:p_Handle OpenFilepath"w+" );


EDIT: Sorry my bad.. its inside the jailll.. that y..

EDIT EDIT: okay 1st step done.. how can i write down player data in there? say i wan to save number or anyting and save it forever. I m looking at exvel save score plugin but i dont understand it. I don wan copy paste, i wan to understand and produce mine.

FaTony 10-18-2012 10:36

Re: Using BuildPath()
 
Well... It's preferable to store player data in SQL rather than plain text. If it's something simple, you can use clientprefs.

Powerlord 10-18-2012 10:37

Re: Using BuildPath()
 
Quote:

Originally Posted by GsiX (Post 1821074)
Thank FaTony, this gonna take log way. Is the file is automatically created or i need to manually create 1?

Yay.. she say undefined symbol path on the OpenFile things.
PHP Code:

public OnConfigsExecuted()
{
    if ( !
FileExists"addons/sourcemod/data/l4d2_luffy_rpg.txt" )) 
    { 
        
decl String:path[256]; 
        
BuildPathPath_SMpathsizeofpath ), "data/l4d2_luffy_rpg.txt"); 
        
ServerCommand"clear" );
        
PrintToServer"[LUFFY]: File path created: addons/sourcemod/data/l4d2_luffy.txt" ); 
    }
    new 
Handle:p_Handle OpenFilepath"w+" );


EDIT: Sorry my bad.. its inside the jailll.. that y..

EDIT EDIT: okay 1st step done.. how can i write down player data in there? say i wan to save number or anyting and save it forever. I m looking at exvel save score plugin but i dont understand it. I don wan copy paste, i wan to understand and produce mine.

If you're writing player data, consider using the SourceMod Client Preferences API instead. Just make sure you set the CookieAccess appropriately... specifically to CookieAccess_Protected or CookieAccess_Private if you don't want users to be able to change it.

Hmm, I just noticed how terribad the wiki page is for ClientPrefs. Rewrite time for it, methinks!

FaTony 10-18-2012 10:43

Re: Using BuildPath()
 
If you want to look at quality implementation using clientprefs, click on money system in my sig.

GsiX 10-18-2012 10:55

Re: Using BuildPath()
 
What i try to do is saving player point into file when they disconnected. Load the point again after the same id is rejoin. Its like rewrite the point for the same steamid or create new for new player join. I m not sure if cookie is the option.

And FaTonny.. this is my first time looking into your code. It very well writen

Powerlord 10-18-2012 11:54

Re: Using BuildPath()
 
I added a quick example to the Client Preferences API wiki page.

Anyway, so you want to do something like this?

PHP Code:

#include <clientprefs>
new Handle:g_hMoneyCookie;
new 
g_Money[MAXPLAYERS+1] = { -1, ... };

public 
OnPluginStart()
{
    
g_hMoneyCookie RegClientCookie("myplugin_money""MyPlugin Money"CookieAccess_Protected);
}

public 
OnClientCookiesCached(client)
{
    
decl String:sMoney[11];
    
GetClientCookie(clientg_hMoneyCookiesMoneysizeof(sMoney));
    
g_Money[client] = StringToInt(sMoney);
}

public 
OnClientDisconnect_Post(client)
{
    
decl String:sMoney[11];
    
IntToString(g_Money[client], sMoneysizeof(sMoney));
    
SetClientCookie(clientg_hMoneyCookiesMoney);
    
g_Money[client] = -1;


Assuming you're storing the client's money in g_Money that is.

FaTony 10-18-2012 13:00

Re: Using BuildPath()
 
Clientprefs desperately need Getter and Setter for int and float. I wanted to write a patch but never got to it.

GsiX 10-18-2012 17:50

Re: Using BuildPath()
 
Sorry i try my best to figure out what to do and where to begin but i pass out.. Here the part i dont undestand.

Quote:

g_hMoneyCookie = RegClientCookie( "myplugin_money", "MyPlugin Money", CookieAccess_Protected );
Is that unique variable or variable that i specify for the cookie call?
And where is the data path saved?


All times are GMT -4. The time now is 11:42.

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