Raised This Month: $51 Target: $400
 12% 

Using BuildPath()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 10-18-2012 , 09:49   Using BuildPath()
Reply With Quote #1

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?
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-18-2012 , 10:08   Re: Using BuildPath()
Reply With Quote #2

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.
__________________
FaTony is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 10-18-2012 , 10:18   Re: Using BuildPath()
Reply With Quote #3

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 i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 10-18-2012 at 10:35.
GsiX is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-18-2012 , 10:36   Re: Using BuildPath()
Reply With Quote #4

Well... It's preferable to store player data in SQL rather than plain text. If it's something simple, you can use clientprefs.
__________________
FaTony is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-18-2012 , 10:37   Re: Using BuildPath()
Reply With Quote #5

Quote:
Originally Posted by GsiX View Post
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!
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-18-2012 , 10:43   Re: Using BuildPath()
Reply With Quote #6

If you want to look at quality implementation using clientprefs, click on money system in my sig.
__________________
FaTony is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 10-18-2012 , 10:55   Re: Using BuildPath()
Reply With Quote #7

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
GsiX is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-18-2012 , 11:54   Re: Using BuildPath()
Reply With Quote #8

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.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-18-2012 , 13:00   Re: Using BuildPath()
Reply With Quote #9

Clientprefs desperately need Getter and Setter for int and float. I wanted to write a patch but never got to it.
__________________
FaTony is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 10-18-2012 , 17:50   Re: Using BuildPath()
Reply With Quote #10

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?
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 10-18-2012 at 17:57.
GsiX 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 10:00.


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