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

Can't overwrite line whit write_file?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-24-2006 , 18:59   Can't overwrite line whit write_file?
Reply With Quote #1

Code:
#include <amxmodx> #include <amxmisc> 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 #define 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))     write_file(xp_file,"//Autogenerated by Doom's XP-Mod",0) } public give_exp(id, level, cid) {      if (!cmd_access(id, level, cid, 2))      return PLUGIN_HANDLED            new Arg1[32], Arg2[32], name[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)            client_print(player,print_chat,"You got %d XP by %s!",xptogive,name)            get_user_name(player,name,31)            client_print(id,print_chat,"You gave %s %d XP!",name,xptogive)            return PLUGIN_HANDLED }       public event_damage(id) {     if(get_user_health(id) > 0)     return PLUGIN_CONTINUE         new attacker = get_user_attacker(id)     new exptogive = random(25)         if(attacker == id)     return PLUGIN_CONTINUE         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)     }         return PLUGIN_CONTINUE } 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)         return PLUGIN_CONTINUE } 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)         return PLUGIN_CONTINUE } public isinfile(id) {     new line = 0, text[91], numof         new steamid[35]     get_user_authid(id,steamid,34)         while(read_file(xp_file,line++,text,90,numof))     {                  if(contain(text,steamid) != -1)         return 1        }         return 0 } public overwrite(id, text[]) {     new line = 0, text[91], numof         new steamid[35]     get_user_authid(id,steamid,34)         while(read_file(xp_file,line++,text,90,numof))     {                     if(contain(text,steamid) != -1)         {             write_file(xp_file,text,line)                break         }           }         return PLUGIN_CONTINUE }     public save_xp(id) {     if(!is_user_connected(id))     return PLUGIN_CONTINUE         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])            new isuserinfile = isinfile(id)         if(isuserinfile == 0)     write_file(xp_file,xp,-1)     else     overwrite(id,xp)         return PLUGIN_CONTINUE } public load_xp(id) {     new line = 0, text[91], numof         new t_steamid[35], t_points[5], t_level[4], t_xp_to_next_level[5]         new steamid[35]     get_user_authid(id,steamid,34)         while(read_file(xp_file,line++,text,90,numof))     {         if(contain(text,steamid) != -1)         {             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         }        }         return PLUGIN_CONTINUE }

This code works fine, but when it gonna overwrite a line, the server get's this error
Code:
L 05/25/2006 - 00:56:14: [AMXX] Run time error 10: native error (native "write_file")
L 05/25/2006 - 00:56:14: [AMXX]    [0] textz52WXq.sma::overwrite (line 146)
L 05/25/2006 - 00:56:14: [AMXX]    [1] textz52WXq.sma::save_xp (line 169)
L 05/25/2006 - 00:56:14: [AMXX]    [2] textz52WXq.sma::client_disconnect (line 93)
it's really weird, can it be a bug?
Deviance is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 05-24-2006 , 19:04  
Reply With Quote #2

Why don't you just use Vault? Or if you really have to use your own file system, at least use the new f____ natives.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 05-24-2006 , 19:05  
Reply With Quote #3

Code:
while(read_file(xp_file,line++,text,90,numof))
you are ++ ing the line AFTER you read it, so the line read is not the line you are trying to modify. possibly trying to write on a line thats not there?

and Hawk has a good point, or you could use nVault.
__________________
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-24-2006 , 19:06  
Reply With Quote #4

Quote:
Originally Posted by Hawk552
Why don't you just use Vault? Or if you really have to use your own file system, at least use the new f____ natives.
gonna add support to Valut, SQL later, atm this is more important
Deviance is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 05-24-2006 , 19:06  
Reply With Quote #5

Quote:
Originally Posted by jtp10181
Code:
while(read_file(xp_file,line++,text,90,numof))
you are ++ ing the line AFTER you read it, so the line read is not the line you are trying to modify. possibly trying to write on a line thats not there?
That shouldn't be a problem, it's not like it won't make the new line.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-24-2006 , 19:07  
Reply With Quote #6

Quote:
Originally Posted by jtp10181
Code:
while(read_file(xp_file,line++,text,90,numof))
you are ++ ing the line AFTER you read it, so the line read is not the line you are trying to modify. possibly trying to write on a line thats not there?
should work, it does in the load function
Deviance is offline
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-24-2006 , 19:08  
Reply With Quote #7

isn't this a bug, i dont get it
Deviance is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 05-24-2006 , 19:09  
Reply With Quote #8

Quote:
Originally Posted by Doombringer
isn't this a bug, i dont get it
No, it's definitely your code somewhere. I don't see it personally, but you shouldn't be using the old file natives anyway.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 05-24-2006 , 19:10  
Reply With Quote #9

Quote:
Originally Posted by Hawk552
Quote:
Originally Posted by Doombringer
isn't this a bug, i dont get it
No, it's definitely your code somewhere. I don't see it personally, but you shouldn't be using the old file natives anyway.
but it should still work..
Deviance is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 05-24-2006 , 19:11  
Reply With Quote #10

Quote:
Originally Posted by Doombringer
Quote:
Originally Posted by Hawk552
Quote:
Originally Posted by Doombringer
isn't this a bug, i dont get it
No, it's definitely your code somewhere. I don't see it personally, but you shouldn't be using the old file natives anyway.
dont know how to use -.-

but it should still work..
Anal sex works, but it isn't necissarily good.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 12:11.


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