Raised This Month: $ Target: $400
 0% 

Simple file write and read


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
-X3N- | DEFAULT
Junior Member
Join Date: Aug 2005
Location: Right Behind You
Old 08-31-2005 , 15:11   Simple file write and read
Reply With Quote #1

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 }
__________________
-X3N- | DEFAULT is offline
Send a message via AIM to -X3N- | DEFAULT Send a message via MSN to -X3N- | DEFAULT
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-31-2005 , 15:21  
Reply With Quote #2

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"); }
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
-X3N- | DEFAULT
Junior Member
Join Date: Aug 2005
Location: Right Behind You
Old 08-31-2005 , 15:25  
Reply With Quote #3

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")
__________________
-X3N- | DEFAULT is offline
Send a message via AIM to -X3N- | DEFAULT Send a message via MSN to -X3N- | DEFAULT
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-31-2005 , 15:34  
Reply With Quote #4

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 08-31-2005 , 16:58  
Reply With Quote #5

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.
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
-X3N- | DEFAULT
Junior Member
Join Date: Aug 2005
Location: Right Behind You
Old 08-31-2005 , 17:08  
Reply With Quote #6

Thank all of you =)
__________________
-X3N- | DEFAULT is offline
Send a message via AIM to -X3N- | DEFAULT Send a message via MSN to -X3N- | DEFAULT
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 14:30.


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