AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple file write and read (https://forums.alliedmods.net/showthread.php?t=17421)

-X3N- | DEFAULT 08-31-2005 15:11

Simple file write and read
 
All i want to do is bring one value from one map change to another. It's the score of a bot on my server. How can i do this correctly?

Code:
public storescore() {           new fileTxt[64]     format(fileTxt,63,"%i",botscore)       //write_file ( const file[], const text[], [ line ] )     write_file(g_FileLocation,fileTxt,-1)     return PLUGIN_HANDLED } public readscore() {           new read[64]     new a     //read_file ( const file[], line, text[], len, &txtLen )     read_file(g_FileLocation,1,read,63,a)     botscore = read[]     return PLUGIN_HANDLED }

XxAvalanchexX 08-31-2005 15:21

If it's only one value, this would be easiest:

Code:
public plugin_init() {    register_cvar("botscore","0"); } public storescore() {    set_cvar_num("botscore",botscore); } public readscore() {    botscore = get_cvar_num("botscore"); }

-X3N- | DEFAULT 08-31-2005 15:25

But if it contains " register_cvar("botscore","0"); " in the init, wouldnt that reset the botscore to 0 at map change?

basically, i want a score that is loaded from the previous map, and added to on the current map, then passed to the next map. A running total.

Code:
new botscore public storescore() {     set_cvar_num("botscore",botscore) } public readscore() {     botscore = get_cvar_num("botscore") } public plugin_init(){     register_cvar("botscore","0")

Hawk552 08-31-2005 15:34

Quote:

Originally Posted by -X3N- | DEFAULT
But if it contains " register_cvar("botscore","0"); " in the init, wouldnt that reset the botscore to 0 at map change?

basically, i want a score that is loaded from the previous map, and added to on the current map, then passed to the next map. A running total.

If it's not defined, then it'll default to 0. It WILL persist if it's set on one map, and then another is loaded.

Charr 08-31-2005 16:58

When the map changes, do you wnat to set the bot's score or do you want to transfer the score from the previous map to the next? If you want to transfer it, then the file script should work.

-X3N- | DEFAULT 08-31-2005 17:08

Thank all of you =)


All times are GMT -4. The time now is 14:30.

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