Raised This Month: $51 Target: $400
 12% 

Can't overwrite line whit write_file?


Post New Thread Reply   
 
Thread Tools Display Modes
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-25-2006 , 16:54  
Reply With Quote #21

Quote:
Originally Posted by SweatyBanana
Quote:
btw i lost my new code
How?

Im sorry man
one of my friends thougt F.E.A.R would lagg less if he closed down all programs( including my un-saved work -.- )
Deviance is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 05-25-2006 , 16:57  
Reply With Quote #22

Damn friends

What are they good for?
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-25-2006 , 16:58  
Reply With Quote #23

Quote:
Originally Posted by SweatyBanana
Damn friends

What are they good for?
good question

maybe to test plugin's on?
Deviance is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 05-25-2006 , 17:02  
Reply With Quote #24

lol always
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 05-26-2006 , 03:07  
Reply With Quote #25

walking through what the script is thinking:

line = 0
Code:
while(read_file(xp_file,line++,text,90,numof))
because ++ follows the variable instead of preceding it, we are reading the current value, and then adding to it. in other words, we are reading line 0, and then setting line to 1.

line = 1
Code:
write_file(xp_file,text,line)
we are now writing to line 1 even though we read line 0.

solution? either initalize line as -1 and use ++line instead of line++, or use line-1 in your write_file.

[edit]
this is in reference to your very first script that you posted, not the "refined" one that causes a server lockup.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-26-2006 , 15:43  
Reply With Quote #26

Quote:
Originally Posted by Kraugh
walking through what the script is thinking:

line = 0
Code:
while(read_file(xp_file,line++,text,90,numof))
because ++ follows the variable instead of preceding it, we are reading the current value, and then adding to it. in other words, we are reading line 0, and then setting line to 1.

line = 1
Code:
write_file(xp_file,text,line)
we are now writing to line 1 even though we read line 0.

solution? either initalize line as -1 and use ++line instead of line++, or use line-1 in your write_file.

[edit]
this is in reference to your very first script that you posted, not the "refined" one that causes a server lockup.
not the problem, the problem is that it doesn't overwrite that line( witch is so fucking easy )

and if i use f___ native's it crashes the server -.-
Deviance is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 05-26-2006 , 17:18  
Reply With Quote #27

I am testing it locally with the old file navites, using your code. I will post back with results.

-----

not only does it work fine with no errors but the bug I pointed out right away is true, this is what the file looks like after joining and quitting twice.

Code:
//Autogenerated by Doom's XP-Mod
STEAM_0:1:19753 0 1 100
STEAM_0:1:19753 0 1 100
maybe you should check file permissions.

---

Testing the new file natives now, I think the problem is that you open the file for writing but then you also read it, so I seeing how to open it for reading and writing.

More info: http://www.cplusplus.com/ref/cstdio/fopen.html

---

the new file natives dont seem to want to overwrite existing lines. no errors, just wont work.

Code:
#include <amxmodx> #include <amxmisc> #include <file> new plugin[] = "XP Mod" new version[] = "0.1" new author[] = "Doombringer" new xp_points[32] new xp_level[32] new xp_to_next_level[32] #define task_time 1.0 new const xp_file[] = "addons/amxmodx/configs/xpvalutfile.ini" public plugin_init() {     register_plugin(plugin,version,author)     register_event("Damage","event_damage","b")     register_concmd("amx_givexp","give_exp",ADMIN_SLAY," - <player> <#number> give's that player XP")     if(!file_exists(xp_file)) {         new file = fopen(xp_file, "wt")         fprintf(file, "%s", "//Autogenerated by Doom's XP-Mod^n")         fclose(file)     } } public give_exp(id, level, cid) {     if (!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED     new Arg1[32], Arg2[32], name[32], name2[32]     read_argv(1, Arg1, 31)     read_argv(2, Arg2, 31)     new xptogive = str_to_num(Arg2)     new player = cmd_target(id,Arg1,8)     xp_points[player] += xptogive     get_user_name(id,name,31)     get_user_name(player,name2,31)     client_print(player,print_chat,"You got %d XP by %s!",xptogive,name)     client_print(id,print_chat,"You gave %s %d XP!",name2,xptogive)     return PLUGIN_HANDLED } public event_damage(id) {     if(get_user_health(id) > 0) return     new attacker = get_user_attacker(id)     new exptogive = random(25)     if(attacker == id) return     xp_points[attacker] += exptogive     if(xp_points[attacker] >= xp_to_next_level[attacker])     {         client_print(attacker,print_chat,"[%s] You gained a level!", plugin)         xp_level[attacker]++         xp_to_next_level[attacker] = xp_to_next_level[attacker] * 2         show_level(attacker)     } } public client_putinserver(id) {     xp_level[id] = 1     xp_to_next_level[id] = 100     xp_points[id] = 0     if(isinfile(id) != 0)     set_task(3.0,"load_xp",id)     //load_xp(id)     show_level(id) } public client_disconnect(id) {     save_xp(id)     xp_level[id] = 0     xp_to_next_level[id] = 0     xp_points[id] = 0 } public show_level(id) {     set_hudmessage(212, 42, 255, 0.73, 0.88, 0, 6.0,_, 0.1, 0.2, 1)     show_hudmessage(id, "You are level %d^nYou need %d more XP to level %d!", xp_level[id], xp_to_next_level[id] - xp_points[id], xp_level[id] + 1)     if(xp_points[id] >= xp_to_next_level[id])     {         client_print(id,print_chat,"[%s] You gained a level!", plugin)         xp_level[id]++         xp_to_next_level[id] = xp_to_next_level[id] * 2     }     set_task(task_time,"show_level",id) } public isinfile(id) {     new file = fopen(xp_file,"rt")     new text[61]     new steamid[35]     get_user_authid(id,steamid,34)     if(!file) {         server_print("[%s] File error!",plugin)         return 0     }     while(!feof(file)) {         fgets(file, text, 60)         if(contain(text,steamid) == 0) {             fclose(file)             return 1         }     }     fclose(file)     return 0 } public overwrite(id,text[]) {     new file = fopen(xp_file,"rt+")     new t_text[61]     new steamid[35]     get_user_authid(id,steamid,34)     if(!file) {         server_print("[%s] File error!",plugin)         return     }     while(!feof(file)) {         fgets(file, t_text, 60)         if(contain(t_text,steamid) == 0) {             server_print(text)             fprintf(file,"%s^n",text)             break         }     }     fclose(file) } public save_xp(id) {     if(!is_user_connected(id)) return     new steamid[35], xp[125]     get_user_authid(id,steamid,34)     format(xp,124,"%s %d %d %d",steamid,xp_points[id],xp_level[id],xp_to_next_level[id])     if(!isinfile(id)) {         new file = fopen(xp_file,"at")         fprintf(file,"%s^n",xp)         fclose(file)     }     else {         overwrite(id,xp)     } } public load_xp(id) {     new file = fopen(xp_file,"rt")     new text[61]     new steamid[35]     get_user_authid(id,steamid,34)     if(!file) {         server_print("[%s] File error!",plugin)         return     }     new t_steamid[35], t_points[5], t_level[4], t_xp_to_next_level[5]     while(!feof(file))     {         fgets(file, text, 60)         if(contain(text,steamid) == 0)         {             parse(text,t_steamid,34,t_points,4,t_level,3,t_xp_to_next_level,4)             xp_level[id] = str_to_num(t_level)             xp_points[id] = str_to_num(t_points)             xp_to_next_level[id] = str_to_num(t_xp_to_next_level)             client_print(id,print_chat,"Loaded your XP status(level %d whit %d XP)", xp_level[id], xp_points[id])             break         }     }     fclose(file) }
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-27-2006 , 06:28  
Reply With Quote #28

very strange..

Well, thx for your help jtp10181, i gonna look over the code, it has to be someway to get it to work...

btw what game did you test it on?
Deviance is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 05-27-2006 , 08:54  
Reply With Quote #29

Quote:
Originally Posted by Doombringer
very strange..

Well, thx for your help jtp10181, i gonna look over the code, it has to be someway to get it to work...

btw what game did you test it on?
CS. The original code worked fine except for the one bug I mentioned with the ++. If you are getting a runtime error I would check your file permissions and also make sure you have amxx 1.71.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-27-2006 , 09:22  
Reply With Quote #30

yeah, i got full permission and i got newest amxx
btw, i haven't tested it to cs, i done this to Svencoop
Deviance is offline
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 21:46.


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