example plugin using file cstrike\test.txt (writes hostname every 10 sec and displays contents with log_amx):
Spoiler
PHP Code:
#include <amxmodx>
public plugin_init() {
register_plugin("test", "1.0", "Sylwester");
set_task(10.0, "read")
}
public read(){
new fh = fopen("test.txt", "rt")
if(!fh){
set_task(0.1, "read")
return
}
log_amx("######## reading file test.txt")
new tmp[64]
while(!feof(fh)){
fgets(fh, tmp, sizeof(tmp))
trim(tmp)
log_amx(tmp)
}
fclose(fh)
log_amx("######## finished")
set_task(0.1, "write")
}
public write(){
static a
new fh = fopen("test.txt", "at")
if(!fh){
set_task(0.1, "write")
return
}
new tmp[64]
get_user_name(0, tmp, sizeof(tmp))
format(tmp, sizeof(tmp), "%s: %d^n", tmp, a++)
fputs(fh, tmp)
fclose(fh)
set_task(10.0, "read")
}
2 servers running this plugin:
Code:
H:\HLDS\hlds.exe
H:\HLDS2\hlds.exe
Create file that will be used as target for links:
Code:
H:\hlds_data\data.txt
Execute in cmd.exe:
Code:
mklink H:\HLDS\cstrike\test.txt H:\hlds_data\data.txt
mklink H:\HLDS2\cstrike\test.txt H:\hlds_data\data.txt
Now start both servers and see that plugin on both servers will write and read from H:\hlds_data\data.txt
__________________