AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Requesting Add AMXX] Some Usefull String Functions (https://forums.alliedmods.net/showthread.php?t=2464)

AssKicR 06-06-2004 00:58

[Requesting Add AMXX] Some Usefull String Functions
 
I Think these stocks should be added in teh string.inc

Quote:

Originally Posted by Johnny got his gun
Code:
stock trim(stringtotrim[], len, charstotrim, bool:fromleft = true) {     if (charstotrim <= 0)         return     if (fromleft) {         new maxlen = strlen(stringtotrim)         if (charstotrim > maxlen)             charstotrim = maxlen         format(stringtotrim, len, "%s", stringtotrim[charstotrim])     } else {         new maxlen = strlen(stringtotrim) - charstotrim         if (maxlen < 0)             maxlen = 0         format(stringtotrim, maxlen, "%s", stringtotrim)     } }

Quote:

Originally Posted by xeroblood
Code:
stock StringMid( oldmsg[], newmsg[], start, end ) {     new len = strlen( oldmsg )     if( start < 0 ) start = 0     if( end <= start || end > len ) end = len     for( new j = 0, i = start; i < end; j++, i++ )         newmsg[j] = oldmsg[i]     return }

Quote:

Originally Posted by xeroblood
Code:
stock explode( output[][], input[], delimiter ) {         new nIdx = 0     new nLen = (1 + copyc( output[nIdx], MAX_STR_LEN-1, input, delimiter ))         while( nLen < strlen(input) )         nLen += (1 + copyc( output[++nIdx], MAX_STR_LEN-1, input[nLen], delimiter )) }


T(+)rget 06-06-2004 19:07

On about that here's a couple of optimised one's for engine_stocks.inc:
Code:

stock get_entity_distance(ent1, ent2)
{
        new Float:orig1[3], Float:orig2[3]
        entity_get_vector(ent1, EV_VEC_origin, orig1)
        entity_get_vector(ent2, EV_VEC_origin, orig2)
 
        return floatround(vector_distance(orig1, orig2))
}

stock get_speed(ent)
{
        new Float:Vel[3]
        entity_get_vector(ent, EV_VEC_velocity, Vel)

        return floatround(vector_length(Vel))
}

Also this still hasn't been fixed:
Code:

/* Byte */
enum {
        EV_BYTE_controller1 = 0,
        EV_BYTE_controller2,
        EV_BYTE_controller3,
        EV_BYTE_controller4,
        EV_BYTE_blending1,
        EV_BYTE_blending2,
}

It should be:
Code:

/* Byte */
enum {
        EV_BYTE_controller0 = 0,
        EV_BYTE_controller1,
        EV_BYTE_controller2,
        EV_BYTE_controller3,
        EV_BYTE_blending0,
        EV_BYTE_blending1,
}

I think there might be 1 more controller (EV_BYTE_controller4) for the mouth movement which would be funny, Singing Mod :D

.Prometheus. 10-30-2004 10:42

Yes....explode, EXPLODE!!!!

PM 10-30-2004 11:19

Quote:

Originally Posted by .Prometheus.
Yes....explode, EXPLODE!!!!

Congratulations for successful 7-month-bump! :D

.Prometheus. 10-31-2004 13:41

I feel ashamed :(, but it was needed...EXPLODE!!!!!!

PM 10-31-2004 14:06

I am happy that you bumped it; funcs to add to my XS library :D

xeroblood 11-01-2004 22:12

Small Changes (Mentioned/added in another post, thought I would put it here too)..

Code:
stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) {     new nIdx = 0, l = strlen(p_szInput)     new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))     while( (nLen < l) && (++nIdx < p_nMax) )         nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))     return nIdx }

Now returns the number of exploded strings returned in the p_szOutput array.. Useful for looping through results afterwards..

p_nMax & p_nSize correspond to the 2D p_szOutput Array sizes respectively..

Example:
Code:
new LongString[64] = "Some.Long.String.Seperated.by.Periods" // 10 Strings of Length 16 new ExplodedStrings[10][16] // Explode By Delimiter: '.' = Period (Dot) new Count = ExplodeString( ExplodedStrings, 10, 16, LongString, '.' ) // output of Count will be 6 // output of array: ExplodedStrings // // ExplodedStrings[0] = "Some" // ExplodedStrings[1] = "Long" // ExplodedStrings[2] = "String" // ExplodedStrings[3] = "Seperated" // ExplodedStrings[4] = "by" // ExplodedStrings[5] = "Periods"

PM 11-02-2004 06:51

This is what I changed it to in XS:
Code:
    // by xeroblood, adapted     // maxelems: maximal number of elements in output, elemsize: maximal size of one element     // tested     XS_LIBFUNC_ATTRIB xs_explode(const input[], output[][], delimiter, maxelems, elemsize)     {         new nIdx = 0;         new nLen = 0;         new copied = 0;         while(nLen < strlen(input) && nIdx < maxelems)         {             copied = copyc(output[nIdx++], elemsize, input[nLen], delimiter);             if (copied == elemsize)             {                 // maybe it got force-stopped because of maxsize                 // so check whether we have to skip something                 if (input[nLen + copied] != delimiter && input[nLen + copied] != 0)                 {                     new found = xs_strchr(input[nLen + copied], delimiter);                     if (found == -1)                         break;                     copied += found;                 }             }                         nLen += copied + 1; // +1: skip delimiter         }     }

Yeah, returning the number of results is a good idea, I will add it :D

xeroblood 11-02-2004 23:38

Nice :D Good Job!! Is that library for a Module or Plugin?? (Maybe for SourceMod??)

DS 11-03-2004 00:09

Quote:

Originally Posted by xeroblood
Nice :D Good Job!! Is that library for a Module or Plugin?? (Maybe for SourceMod??)

AFAIK, it's a stock library. PM probably doesn't want you to know this but you can take a look at it here. :-P

BTW, PM this whole XS Library looks very interesting and useful. :)


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

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