Raised This Month: $ Target: $400
 0% 

Solved Searching in a text file


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-27-2020 , 23:04   Re: /wr Plugin (Formerly: Searching in a text file)
Reply With Quote #11

Quote:
Originally Posted by Shadows Adi View Post
I know this has been discussed and the answers were same as the above one.
Yeah but your suggestion to use static variables there is not really a good use of them. In fact, most good programmers would just tell you to change them back to "new".

Quote:
Originally Posted by WHOOHOO View Post
I just changed the post title so if anybody had the same problem they could read it and I hope that it could help them.
The original title was much better. Adding something that is only specific to your plugin is not helpful (since the question has nothing to do with the "/wr" part of your plugin).

Quote:
Originally Posted by WHOOHOO View Post
I'd appreciate if someone could check it and see if I made any mistakes.
  • This should give you errors.
    PHP Code:
    format(filename,255,"addons/amxmodx/data/demos.txt",filename
    A filepath to any file in an AMX Mod X directory should be generated dynamically. In your case, it should be something like this:
    PHP Code:
    new filename[256]

    public 
    plugin_init()
    {
        
    // <code>
        
    new szDataDir[64]
        
    get_datadir(szDataDircharsmax(szDataDir))
        
    formatex(filenamecharsmax(filename), "%s/demos.txt"szDataDir)
        
    // <more code>

  • Using set_task() to call ParseWR() has no benefit and should be called directly.
  • When you need to get the maximum string length of a variable, you should always use charsmax() (as seen above), never hard code that value.
  • Whenever your format string is "%s", you should instead use copy(). formatex() should be used when the destination string is not also used as an argument. However, in the case of WRTime, I'd recommend that you convert it immediately to a float instead of storing it as a string (since you never use it as a string anyways).
  • When formatting numbers into string, you need to use the proper format. %i is for integers but you are using floating-point numbers which would need to use %f. However, in your case, you should calculate your time differently to make it more efficient and using the appropriate format specifiers. Here is an example:


    PHP Code:
    new Float:fTimeiMinFloat:fSec
    fTime 
    str_to_float(WRTime)
    iMin floatround(fTime 60.0floatround_floor)
    fSec fTime float(iMin) * 60.0
    client_print
    (idprint_chat"Time is %i:%02.3f"iMinfSec
__________________
fysiks is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 08-29-2020 , 08:10   Re: /wr Plugin (Formerly: Searching in a text file)
Reply With Quote #12

This plugin has been made 10 times already...(also one is with auto-updating demos.txt from the site)...so whats the point of this topic? Just use search for 2mins
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
WHOOHOO
Junior Member
Join Date: Aug 2016
Old 08-30-2020 , 08:24   Re: /wr Plugin (Formerly: Searching in a text file)
Reply With Quote #13

Thank y'all for your tips. I'll change the title back to what it was.

Quote:
Originally Posted by JocAnis View Post
This plugin has been made 10 times already...(also one is with auto-updating demos.txt from the site)...so whats the point of this topic? Just use search for 2mins
Because I wanted to use the time in ProKreedz (after player finish the run) and I needed to know how it works.
WHOOHOO 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 18:30.


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