[Include] BTXT - Fast and Easy Text Processor
#1

This time I want to introduce you an include, where you can use normal text inputs as commands which will be performed faster than using strcmp checks in OnPlayerText.

I've created this include because my heart bleeds if some peoples starts to script text string checks in OnPlayerText by using strcmp checks.
Example: http://pastebin.com/3sMRVaMY

Anyways this include is very easy to use, is not case sensitive, is very fast and can detect strings for params array.

How to use this include?
It's quite easy to use. (Idea from ZCMD)
You can use

pawn Код:
TXT:hello(playerid, params[])
or
pawn Код:
TEXT:hello(playerid, params[])
or (not recommend)
pawn Код:
forward txt_hello(playerid, params[]);
public txt_hello(playerid, params[])
//...
Код:
TXT:hello(playerid, params[])
Callback start:
Код:
TXT:
Text string:
Код:
hello
Player ID
Код:
playerid
Params string:
Код:
params[]
Example:
pawn Код:
TXT:test(playerid, params[])
{
    new str[128];
    format(str, 128, "You have wrote 'test' with following params: '%s'", params);
    SendClientMessage(playerid, 0xFF0000FF, str);
    return 0;
}
Even you can use the sscanf include/plugin (from ******) to parse strings to variables from params array.
https://sampforum.blast.hk/showthread.php?tid=120356


About returning values in txt_
If the callback exists, so returning 0 will deny executing TXT_OnPlayerText (muting) otherwise TXT_OnPlayerText will be also called!


Benchmark Tests
Results (Looping 10000 times through):

Код:
BTXT without params: 60-65 ms
BTXT with params (large params string): 252-263 ms

strcmp methode without params: 19037 ms
strcmp methode with params (same large params string as in BTXT check): 108984 ms
As we can see that my include is still faster than using strcmp checks in OnPlayerText.

Benchmark scripts:

http://solidfiles.com/d/8fc89eca14/

IF you find any another text processors, so please reply on this topic!

Credits:
  • Idea from ZCMD include (ZeeX)
  • Hooking methode by ******
  • Myself for creating this include
Downloads:

Download btxt.inc from Solidfiles
Download btxt.inc from Pastebin

Regards: BigETI
Reply


Messages In This Thread
BTXT - Fast and Easy Text Processor - by BigETI - 21.11.2011, 16:43
Re: BTXT - Fast and Easy Text Processor - by Speed - 21.11.2011, 16:44
Re: BTXT - Fast and Easy Text Processor - by fiki574 - 21.11.2011, 16:45
Re: BTXT - Fast and Easy Text Processor - by FireCat - 21.11.2011, 16:51
AW: Re: BTXT - Fast and Easy Text Processor - by BigETI - 21.11.2011, 16:52
Re: BTXT - Fast and Easy Text Processor - by System64 - 21.11.2011, 16:59
AW: BTXT - Fast and Easy Text Processor - by BigETI - 21.11.2011, 17:07
Re: BTXT - Fast and Easy Text Processor - by Finn - 21.11.2011, 17:20
AW: Re: BTXT - Fast and Easy Text Processor - by BigETI - 21.11.2011, 17:24
Re: AW: Re: BTXT - Fast and Easy Text Processor - by FireCat - 21.11.2011, 17:29
Re: AW: Re: BTXT - Fast and Easy Text Processor - by Finn - 22.11.2011, 15:00
Re: AW: Re: BTXT - Fast and Easy Text Processor - by KoczkaHUN - 22.11.2011, 15:35
Re: BTXT - Fast and Easy Text Processor - by TheArcher - 22.11.2011, 15:44
Re: BTXT - Fast and Easy Text Processor - by marwan - 22.11.2011, 15:52
Re: AW: Re: BTXT - Fast and Easy Text Processor - by Finn - 23.11.2011, 08:12
Re: BTXT - Fast and Easy Text Processor - by Biesmen - 23.11.2011, 09:37
Re: BTXT - Fast and Easy Text Processor - by System64 - 23.11.2011, 11:57
Re: AW: Re: BTXT - Fast and Easy Text Processor - by wups - 23.11.2011, 12:24
AW: Re: BTXT - Fast and Easy Text Processor - by BigETI - 23.11.2011, 12:40
Re: AW: Re: BTXT - Fast and Easy Text Processor - by Finn - 23.11.2011, 13:08
Re: BTXT - Fast and Easy Text Processor - by AndreT - 23.11.2011, 13:15
Re: BTXT - Fast and Easy Text Processor - by Finn - 23.11.2011, 13:27
Re: BTXT - Fast and Easy Text Processor - by Biesmen - 23.11.2011, 16:50

Forum Jump:


Users browsing this thread: 1 Guest(s)