|
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
|
08-27-2020
, 23:04
Re: /wr Plugin (Formerly: Searching in a text file)
|
#11
|
Quote:
Originally Posted by Shadows Adi
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
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
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(szDataDir, charsmax(szDataDir))
formatex(filename, charsmax(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:fTime, iMin, Float:fSec
fTime = str_to_float(WRTime)
iMin = floatround(fTime / 60.0, floatround_floor)
fSec = fTime - float(iMin) * 60.0
client_print(id, print_chat, "Time is %i:%02.3f", iMin, fSec)
__________________
|
|
|
|