Raised This Month: $32 Target: $400
 8% 

[Requesting Add AMXX] Some Usefull String Functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AssKicR
Veteran Member
Join Date: Mar 2004
Location: Norway-Europe(GTM+1)
Old 06-06-2004 , 00:58   [Requesting Add AMXX] Some Usefull String Functions
Reply With Quote #1

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 )) }
__________________
My Plugins

Got ??
AssKicR is offline
T(+)rget
Senior Member
Join Date: Mar 2004
Old 06-06-2004 , 19:07  
Reply With Quote #2

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
T(+)rget is offline
.Prometheus.
Member
Join Date: Sep 2004
Old 10-30-2004 , 10:42  
Reply With Quote #3

Yes....explode, EXPLODE!!!!
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 10-30-2004 , 11:19  
Reply With Quote #4

Quote:
Originally Posted by .Prometheus.
Yes....explode, EXPLODE!!!!
Congratulations for successful 7-month-bump!
__________________
hello, i am pm
PM is offline
.Prometheus.
Member
Join Date: Sep 2004
Old 10-31-2004 , 13:41  
Reply With Quote #5

I feel ashamed , but it was needed...EXPLODE!!!!!!
.Prometheus. is offline
Send a message via AIM to .Prometheus. Send a message via MSN to .Prometheus.
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 10-31-2004 , 14:06  
Reply With Quote #6

I am happy that you bumped it; funcs to add to my XS library
__________________
hello, i am pm
PM is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 11-01-2004 , 22:12  
Reply With Quote #7

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"
xeroblood is offline
Send a message via MSN to xeroblood
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 11-02-2004 , 06:51  
Reply With Quote #8

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
__________________
hello, i am pm
PM is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 11-02-2004 , 23:38  
Reply With Quote #9

Nice Good Job!! Is that library for a Module or Plugin?? (Maybe for SourceMod??)
xeroblood is offline
Send a message via MSN to xeroblood
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 11-03-2004 , 00:09  
Reply With Quote #10

Quote:
Originally Posted by xeroblood
Nice 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.
__________________
エル・プサイ・コングルゥ
DS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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