AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   write to file from amx menu (https://forums.alliedmods.net/showthread.php?t=50006)

nobuddy 01-17-2007 14:06

write to file from amx menu
 
hello
i write a little plugin to check players nick and password.
nicks and pass is in file nicks.txt
i want to add new users whitout openning this file but from amx menu or from CS console.
unfortunetly i dont know how it do :\

please give me some clue.

sory for my english ;)

s p l i t 01-17-2007 15:48

Re: write to file from amx menu
 
http://www.amxmodx.org/funcwiki.php?go=func&id=88

nobuddy 01-18-2007 11:48

Re: write to file from amx menu
 
ok i explain

i know that command
write_file("addons/amxmodx/nicks.txt","nick pass",1)
add a new line at the end of file nicks.txt
but i cant use this command froma CS console

question :
what to do to use this command froma CS console ????
or
how to add a line to file nicks.txt from CS console ????

[of coz i'm an admin ;)]

PS : i know my english is poor :]

Salepate 01-18-2007 12:20

Re: write to file from amx menu
 
In your plugin you have to use :
Code:
register_clcmd();
To register a command like amx_filewrite <text>
retrieve arg with
Code:
read_argv();
in the function executed by
Code:
register_clcmd();
and you finish with
Code:
write_file("dir/file.txt",string,-1);
Where :
dir = file directory
file.txt = filename
string = variable where is set the retrieved argument
and -1 if you want to add the line to the end.

I've just given you syntax command but not how to do it, if you need some help I will be glad to help you (not to make the code)

You can check how those functions work by reading .inc files or reading other plugins or checking the doc on this website.

For example - From amxmodx.inc :
Code:
/* Registers function which will be called from client console. */ native register_clcmd(const client_cmd[],const function[],flags=-1, info[]="");

nobuddy 01-18-2007 13:05

Re: write to file from amx menu
 
ok I write somthing like that. please somebody check this form me
i'm beginner :]

public plugin_init()
{
register_clcmd("amx_adduser","newuseradd")

return PLUGIN_CONTINUE
}


public newuseradd(id)
{
if(!is_user_admin(id))
{
client_print(id,print_console,"You are not an administrator. Please refrain from using this command!")
return PLUGIN_HANDLED
}
new player[50],pass[50]
read_argv(1,player,49)
read_argv(2,pass,49)
new whattowrite[100]
format(whattowrite,99,"%s","%s",player,pass)
new target=cmd_target(id,player,9)
write_file("addons/amxmodx/nicks.txt",whattowrite,-1)
client_print(id,print_console,"User %s, password %s wrote to file.",player,pass)
return PLUGIN_HANDLED
}

[ --<-@ ] Black Rose 01-18-2007 16:00

Re: write to file from amx menu
 
Almost. Remember you can post code in [small][/small] tags.
Minor changes:
Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("plugin name", "1.00", "plugin author")     register_clcmd("amx_adduser", "newuseradd") } public newuseradd(id) {     if ( ! is_user_admin(id) ) {         client_print(id, print_console, "You are not an administrator. Please refrain from using this command!")         return PLUGIN_HANDLED     }         new whattowrite[64], player[32], pass[28]         read_argv(1, player, 31)     read_argv(2, pass, 27)         new target = cmd_target(id, player, 9)     get_user_name(target, player, 31)         format(whattowrite, 63, "^"%s^" ^"%s^"", player, pass)     write_file("addons/amxmodx/nicks.txt", whattowrite)         client_print(id, print_console, "User %s, password %s wrote to file.", player, pass)         return PLUGIN_HANDLED }


All times are GMT -4. The time now is 22:25.

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