Raised This Month: $ Target: $400
 0% 

Writing/Reading File Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 03-04-2006 , 19:33   Writing/Reading File Help
Reply With Quote #1

I'm trying to write a plugin that will allow admins to add EntMod users from the console, instead of opening the txt file myself and adding a user.

I've searched for threads that might help me write the plugin, but I couldn't find sufficient info.

I would greatly appreciate any help.

______________________________________

DETAILS

"amx_addentuser" should check to see if the target's steamid is already in the DF_admins.txt file, and if the steamid is not found, or if there is a "0" after "password;", add the target to the file or change the "0" to a "1".

The format for a user in the DF_admins.txt (Ent users file) is this:
Code:
STEAM_0:0:123456;password;1 //target's name
"amx_delentuser" should check to see if the target's steamid is already in the DF_admins.txt file, and if the steamid is found, change the "1" to a "0" in the above line (steamid;password;0).
______________________________________

Here is my attempt at coding this plugin: (not nearly finished)
Code:
#include <amxmodx> #include <amxmisc> #include <file> #include <string> #define PLUGIN "Add Ent Access" #define VERSION "1.0" #define AUTHOR "Fluffy" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("amx_addentuser", "addenter", ADMIN_LEVEL_B, "- adds an EntMod User <target> <pass>")     register_clcmd("amx_delentuser", "delenter", ADMIN_LEVEL_B, "- deletes an EntMod User") } public addenter(id, level, cid) {     if (!cmd_access(id, level, cid, 2))     return PLUGIN_HANDLED             new Player[24]         read_argv(1, Player, 23)             new Password[24]         read_argv(2, Password, 23)             new PlayerID[24] = get_user_userid(Player)         new szFile[24]         format( szFile, 23, "addons/EntMod/DF_admins.txt")     write_file(szFile,"%s;%s;1 //%s",PlayerID,Password,Player,-1) }
stupok is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-04-2006 , 20:16   Re: Writing/Reading File Help
Reply With Quote #2

Code:
#include <amxmodx> #include <amxmisc> #include <file> #include <string> #define PLUGIN "Add Ent Access" #define VERSION "1.0" #define AUTHOR "Fluffy" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("amx_addentuser", "addenter", ADMIN_LEVEL_B, "- adds an EntMod User <target> <pass>")     register_clcmd("amx_delentuser", "delenter", ADMIN_LEVEL_B, "- deletes an EntMod User") } public addenter(id, level, cid) {     if (!cmd_access(id, level, cid, 2))     return PLUGIN_HANDLED             new Player[24]         read_argv(1, Player, 23)             new Password[24]         read_argv(2, Password, 23)         remove_quotes(Player);         remove_quotes(Password);             new PlayerID[24] = get_user_userid(Player)         new szFile[24]         format( szFile, 23, "addons/EntMod/DF_admins.txt")     write_file(szFile,"%s;%s;1 //%s",PlayerID,Password,Player,-1) }

Try that
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-04-2006 , 22:03  
Reply With Quote #3

I appreciate your help, but I'm afraid I need much more help in order to write the entire plugin.
stupok is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-04-2006 , 22:24  
Reply With Quote #4

Then post your questions and we will help :)
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-04-2006 , 22:44  
Reply With Quote #5

Quote:
DETAILS

"amx_addentuser" should check to see if the target's steamid is already in the DF_admins.txt file, and if the steamid is not found, or if there is a "0" after "password;", add the target to the file or change the "0" to a "1".

The format for a user in the DF_admins.txt (Ent users file) is this:
Code:
Code:
STEAM_0:0:123456;password;1 //target's name

"amx_delentuser" should check to see if the target's steamid is already in the DF_admins.txt file, and if the steamid is found, change the "1" to a "0" in the above line (steamid;password;0).
That is what I hope to accomplish. I need help with reading txt files and writing txt files in order to write the plugin.
stupok is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-04-2006 , 23:59  
Reply With Quote #6

Alright, for this you are going to need to use strbreak() or some other forum of splitting a string

Ill see what I can find
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-05-2006 , 16:16  
Reply With Quote #7

I DO NOT CLAIM OWNERSHIP TO ANY OF THE CODE BELOW

I suppose I just wasn't clear enough, or was asking for too much. Sorry about that, I'll try to ask some simpler questions.

_____________________________________________ __________________
Code:
new Player[24]         read_argv(1, Player, 23)             new Password[24]         read_argv(2, Password, 23)             new PlayerID[24] = get_user_userid(Player)         remove_quotes(Player);         remove_quotes(Password);         remove_quotes(PlayerID);         new szFile[24]         format( szFile, 23, "addons/EntMod/DF_admins.txt")     write_file(szFile,"%s;%s;1 //%s",PlayerID,Password,Player,-1)

Will this code write the line below to a txt file in addons/EntMod (with strings in the place of the strings' names)? What mistakes am I making?

Code:
PlayerID;Password;1 //Player
_____________________________________________ _______________

I have more questions, but I'll stop here for now.
stupok is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-05-2006 , 16:20  
Reply With Quote #8

Code:
    new szFile[24]     new szText[101]     format( szFile, 23, "addons/EntMod/DF_admins.txt")     format( szText , 100 , "%s;%s;1 //%s",PlayerID,Password,Player)     write_file(szFile, szText ,-1)
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
stupok
Veteran Member
Join Date: Feb 2006
Old 03-05-2006 , 17:34  
Reply With Quote #9

Thanks Suicid3! (how do you give karma points?)

I have a new idea for this plugin, I hope you can help me with it.

But before I get into that, I'd like to finish fixing this code:
Code:
    #include <amxmodx>     #include <amxmisc> public plugin_init() {     register_plugin("Ent User Management","1.0","Fluffy")     register_concmd("amx_addentuser", "addent", ADMIN_LEVEL_B, "- adds ent user. <target> <password>")     register_concmd("amx_delentuser", "delent", ADMIN_LEVEL_B, "- disables ent user. <target> <password>") } public addent(id, level, cid) {     if (!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED     new Arg1[33],Arg2[33], pName[33], pAuth[33]         read_argv(1, Arg1, 32)     read_argv(2, Arg2, 32)         pName[33] = cmd_target(id, Arg1)     pAuth[33] = get_user_authid(Arg1, pAuth, 32)         new szFile[33]     new szText[101]     format( szFile, 32, "addons/EntMod/DF_admins.txt")     format( szText , 100 , "%s;%s;1 //%s",pAuth,Arg2,pName)     write_file(szFile, szText ,-1)     return 0 }
It returns two errors:
(21)error 032: array index out of bounds (variable "pName")
(22)error 032: array index out of bounds (variable "pAuth")

I have tried a few things, but I really have no clear idea of what I should change to fix those errors.

__________________________________________

Now, about the new idea for the plugin. Instead of having it read each line and check if the user is there already, or if the user has EntMod access enabled, and then take action based on these parameters, I propose to simplify this whole thing.
I'm afraid it would be too much coding, and too complex, for me to write the complete and working plugin that checks so many variables.

How about taking all text from "addons/EntMod/DF_admins.txt" and putting it into a MOTD screen, and I'll decide whether or not the user is already in the file, and what to do from there.

And, to match that idea, instead of "format( szText , 100 , "%s;%s;1 //%s",pAuth,Arg2,pName)", how about establishing a command so I could type "amx_entusers STEAM_0:0:1234;password;1 //whatever" and this line would be appended to the file "as-is." So I could append a line with any text I want to the file.

I'd appreciate any insight into writing this plugin.
stupok is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-05-2006 , 17:38  
Reply With Quote #10

Code:
    new Arg1[33],Arg2[33], pID , pName[33], pAuth[33]         read_argv(1, Arg1, 32)     read_argv(2, Arg2, 32)         pID = cmd_target(id, Arg1)     get_user_authid(pID, pAuth, 32)     get_user_name(pID , pName , 32)
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
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 20:16.


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