Raised This Month: $ Target: $400
 0% 

Solved Buttons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-03-2017 , 16:41   Re: Buttons
Reply With Quote #1

Quote:
Originally Posted by maqi View Post
..., but i cant seem to figure out how to replace a line in a file with a new string.
This is a bad part of working with files... You have to loop over all lines and write them to new temporary file while checking if the current line matched line you want to edit, if yes then write the new string to the temporary file instead of the current line and when you ready delete the old file, rename the temporary file to the original one.

Last edited by KiLLeR.; 12-03-2017 at 16:44.
KiLLeR. is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 12-03-2017 , 16:49   Re: Buttons
Reply With Quote #2

Ill try, brb.

Also, I cant seem to remove an entity
Tried:

PHP Code:
if ( find_ent_by_classentsClassname ) )
 
set_pev(entpev_flagsFL_KILLME); 
and

PHP Code:
if ( find_ent_by_classentsClassname ) )
 
remove_entityent ); 
Nothing happens

Last edited by maqi; 12-03-2017 at 16:57.
maqi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-03-2017 , 17:19   Re: Buttons
Reply With Quote #3

Entities are not solid for their owner, that's why it worked when you removed it.
__________________
HamletEagle is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 12-03-2017 , 17:22   Re: Buttons
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
Entities are not solid for their owner, that's why it worked when you removed it.
Yes it makes sense.
maqi is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 12-03-2017 , 17:58   Re: Buttons
Reply With Quote #5

After almost loosing my mind with "the new file stuff", I just used
write_file( file, data, line );

Why wouldnt I use this?? It perfectly overwrites and does what i need, and its just one line of code, opposing to like 10+ lines of confusing stuff.

Last edited by maqi; 12-03-2017 at 17:59.
maqi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-04-2017 , 02:08   Re: Buttons
Reply With Quote #6

write_file is inneficient. Do not use it if you write more than once at a time.
__________________

Last edited by HamletEagle; 12-04-2017 at 02:10.
HamletEagle is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-04-2017 , 10:52   Re: Buttons
Reply With Quote #7

https://www.amxmodx.org/api/file/write_file
Also It gonna add those text string to the end of line instead of replacing according to the wiki.

P.S. I never have used the old file commands.

Last edited by KiLLeR.; 12-04-2017 at 10:54.
KiLLeR. is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 12-04-2017 , 11:32   Re: Buttons
Reply With Quote #8

No, it replaces an existing line ( if not -1 ).

I dont know how inefficient it is, but my files only have 2 lines of text ( origins ), and basically the write_file is used only once per map ( When making a timer ). So i think i wont loose any efficiency there especially with all the headache i've gotten with the other method

And of course if somewhere along the way i figure out how to do it the other way, i will just change it up. But this works perfect for now.

Last edited by maqi; 12-04-2017 at 12:17.
maqi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-04-2017 , 14:03   Re: Buttons
Reply With Quote #9

Quote:
Originally Posted by maqi View Post
No, it replaces an existing line ( if not -1 ).

I dont know how inefficient it is, but my files only have 2 lines of text ( origins ), and basically the write_file is used only once per map ( When making a timer ). So i think i wont loose any efficiency there especially with all the headache i've gotten with the other method

And of course if somewhere along the way i figure out how to do it the other way, i will just change it up. But this works perfect for now.
If you just write 1/2 lines and once per map then write_file is good enough. The issue is when you have multiple write_file one after another(or when used in a loop).
__________________
HamletEagle is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 12-04-2017 , 16:20   Re: Buttons
Reply With Quote #10

Well its only 2 lines of code, but i do use them in a loop ( small loop tho )
maqi 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 00:51.


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