Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOURCE] STRTOKEN
Author Message
xwerswoodx
Journeyman
*

Posts: 80
Likes Given: 3
Likes Received: 5 in 2 posts
Joined: Jun 2012
Reputation: 0

UoMMO

Post: #1
[SOURCE] STRTOKEN
Addes STRTOKEN function to sphere;

Usage: <STRTOKEN text,n,seperator>

<STRTOKEN a.b.c.d.e,3,.> returns c
<STRTOKEN a.b.c.d.e,0,.> returns 5
<STRTOKEN a.b.c.d.e,6,.> returns null

You can also specify a range of tokens:
<STRTOKEN a.b.c.d.e,2-,.> returns 2nd token onwards = b.c.d.e
<STRTOKEN a.b.c.d.e,2-4,.> returns tokens 2 through 4 = b.c.d

Installation;
Note: Please backup your files before starting to edit.

Open File: src/common/CScriptObj.cpp

find:
Code:
        case SSC_EXPLODE:

add before:
Code:
        case SSC_StrToken:
            {
                TCHAR * ppArgs[3];
                size_t iQty = Str_ParseCmds(const_cast<TCHAR *>(pszKey), ppArgs, COUNTOF(ppArgs), ",");
                if ( iQty < 3 )
                    return false;

                if ( *ppArgs[2] == '"' )
                   ppArgs[2]++;
                
                for (TCHAR * pEnd = ppArgs[2] + strlen(ppArgs[2]) - 1; pEnd >= ppArgs[2]; pEnd--)
                {
                    if ( *pEnd == '"' )
                    {
                        *pEnd = '\0';
                        break;
                    }
                }
                TCHAR * iSep = ppArgs[2];
                for (TCHAR *iSeperator = ppArgs[2] + strlen(ppArgs[2]) - 1; iSeperator > ppArgs[2]; iSeperator--)
                    *iSeperator = '\0';

                if ( *ppArgs[0] == '"' )
                    ppArgs[0]++;
                for (TCHAR * pEnd = ppArgs[0] + strlen(ppArgs[0]) - 1; pEnd >= ppArgs[0]; pEnd--)
                {
                    if ( *pEnd == '"' )
                    {
                        *pEnd = '\0';
                        break;
                    }
                }

                sVal = "";
                TCHAR *ppCmd[255];
                size_t count = Str_ParseCmds(ppArgs[0], ppCmd, COUNTOF(ppCmd), iSep);

                TCHAR * ppArrays[2];
                size_t iArrays = Str_ParseCmds(ppArgs[1], ppArrays, COUNTOF(ppArrays), "-");
                INT64    iValue = Exp_GetVal(ppArgs[1]);
                INT64     iValueEnd = iValue;
                
                if (iArrays > 1)
                {
                    iValue = Exp_GetVal(ppArrays[0]);
                    iValueEnd = Exp_GetVal(ppArrays[1]);
                    if (iValueEnd <= 0 || iValueEnd > count)
                        iValueEnd = count;                    
                }
                
                if (iValue < 0)
                    return false;
                else if (iValue > 0)
                {
                    if (iValue > count)
                        return false;
                    else if (iValue == iValueEnd)
                        sVal = ppCmd[iValue - 1];
                    else
                    {
                        sVal.Add(ppCmd[iValue - 1]);
                        INT64 i = iValue + 1;
                        for ( ; i <= iValueEnd; i++)
                        {
                            sVal.Add(iSep);
                            sVal.Add(ppCmd[i - 1]);
                        }
                    }
                }
                else
                    sVal.FormatVal(static_cast<long>(count));
            }
            return true;

Open File: src/tables/CScriptObj_functions.tbl

find:
Code:
ADD(StrSub,            "StrSub")

add after:
Code:
ADD(StrToken,        "StrToken")
(This post was last modified: 06-01-2017 08:33 AM by xwerswoodx.)
02-16-2017 03:15 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 4 users Like xwerswoodx's post
rastrero
Journeyman
*

Posts: 245
Likes Given: 41
Likes Received: 26 in 23 posts
Joined: Jan 2016
Reputation: 3



Post: #2
RE: [SOURCE] STRTOKEN
Oh its so nice... But I cant imagine why do u need this. Can you give me an example?
03-04-2017 05:08 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes rastrero's post
xwerswoodx
Journeyman
*

Posts: 80
Likes Given: 3
Likes Received: 5 in 2 posts
Joined: Jun 2012
Reputation: 0

UoMMO

Post: #3
RE: [SOURCE] STRTOKEN
Sorry for late answer I saw your message now, basically, it lets you to seperate sentences with commas.

For example:
If you have string "1,000 2,000 3,000" and you want to get 2,000 you can use <STRTOKEN "1,000 2,000 3,000",2," ">.

For example if you have in-game forum like me, you can censor swearing words with strtoken but explode overrides commas so it's not possible if sentence has commas or if there are 6-7 commas you can use for/while to check everystring inside commas to do it.

Code:
[FUNCTION DIFF]
SERV.LOG ARGS: <ARGV[2]>
SERV.LOG STRTOKEN: <STRTOKEN "<ARGS>",3," ">
ARGS=<EXPLODE " ",<ARGS>>
SERV.LOG EXPLODE: <ARGV[2]>

23:40:'xwerswoodx' commands 'diff 1,000 2,000 5,000 100,000 9,000'=1
23:40:(insurance.scp,2)ARGS: 000 5
23:40:(insurance.scp,3)STRTOKEN: 5,000
23:40:(insurance.scp,5)EXPLODE: 2
(This post was last modified: 06-02-2017 08:17 AM by xwerswoodx.)
06-01-2017 03:07 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

This forum uses Lukasz Tkacz MyBB addons.