AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [resolved] Custom Parse Function Problem (https://forums.alliedmods.net/showthread.php?t=49198)

stupok 12-29-2006 17:05

[resolved] Custom Parse Function Problem
 
I have been perfectly happy using the old ones, but I thought it would be nice to update one of my plugins to the new natives. Is it really worth it to use the new ones?

Anyway, the plugin I wrote does not do what I would expect it to.
Code:
#include <amxmodx> #include <amxmisc> new file[64] public plugin_init() {     register_plugin("Users List", "1.0", "stupok69")         register_concmd("readline", "read_function")         get_basedir(file, 63)     format(file, 63, "%s/users_list.txt", file) } public read_function() {     new text[65], index[5], steamid[18], name[33], logs[5]         new fp = fopen(file, "rt")         if(fp)     {         fgets(fp, text, 64)             fclose(fp)             stupok_parse(text, 0, 4, index, 4)         stupok_parse(text, 6, 23, steamid, 17)         stupok_parse(text, 25, 57, name, 32)         stupok_parse(text, 59, 63, logs, 4)             server_print("text: %s", text)         server_print("INDEX:%s^nSTEAMID:%s^nNAME:%s^nLOGS:%s", index, steamid, name, logs)     }     else     {         server_print("File could not be opened.")     } } stock stupok_parse(text[], start, end, destination[], destlen) {     new i         while(start + i <= end)     {         if(i > destlen)         {             break         }                 destination[i] = text[start+i]                 i++     } }

Result:
http://xs310.xs.to/xs310/06525/pluginhelp.PNG

Desired Result:
Code:

INDEX:    1
STEAMID: STEAM_0:1:1234567
NAME: ROFFL                           
LOGS:    1

users_list.txt
Code:

    1        STEAM_0:1:1234567        ROFFL                                        1
Some attachments :wink:

Alka 12-29-2006 18:07

Re: New File Natives
 
this plugin store players in a data base?? [users_list.txt] :-?

stupok 12-29-2006 19:23

Re: New File Natives
 
No.

MaximusBrood 12-29-2006 19:29

Re: New File Natives
 
stupok69: I'll post back in a few minutes. Adding debug.

MaximusBrood 12-29-2006 19:50

Re: New File Natives
 
Code:
#include <amxmodx> #include <amxmisc> new file[64] public plugin_init() {     register_plugin("Users List", "1.0", "stupok69")         register_concmd("readline", "read_function")         get_basedir(file, 63)     format(file, 63, "%s/users_list.txt", file) } public read_function() {     //Learn that strings are null-terminated!     new text[65], index[6], steamid[19], name[33], logs[5]         new fp = fopen(file, "rt")         if(fp)     {         fgets(fp, text, 64)             fclose(fp)             //The begin and ends were wrong!         //Learn that strings are null-terminated!         maximus_parse(text, 0, 5, index, 5)         maximus_parse(text, 6, 18, steamid, 18)         maximus_parse(text, 25, 32, name, 32)         maximus_parse(text, 63, 4, logs, 4)             server_print("text: %s", text)         server_print("INDEX:%s^nSTEAMID:%s^nNAME:%s^nLOGS:%s", index, steamid, name, logs)     }     else     {         server_print("File could not be opened.")     } } stock maximus_parse(text[], start, lenght, destination[], destlen) {     //Use errorchecking here, I'll not add it now     for(new a = 0; (a < lenght) && (a < destlen); ++a)         destination[a] = text[start + a]; }

stupok 12-29-2006 21:11

Re: New File Natives
 
Thanks MaximusBrood, it turns out I didn't determine the length properly, 5 should have been 6, 18 -> 19, 33 -> 34, etc.

Thanks for the short parse function, too. I love to see short, useful bits of code like that :wink:.

Everything works just like I wanted it to now.


All times are GMT -4. The time now is 22:22.

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