Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* SA-MP Include Arrays
- *
- * (c) by Kaliber, 2014
- *
- */
- #if !defined _samp_included
- #include <a_samp>
- #endif
- #if defined _samp_arrays
- #endinput
- #endif
- #define _samp_arrays
- #define _m_Data 0xF
- #define _s_Data 0x40
- #define _r_Data 0x80
- #define _b_Data 0x100
- #define INVALID -1
- #define GetArray(%0)<%1> __@(%0,%1)
- #define GetArrayInt(%0)<%1> __@Int(%0,%1)
- #define GetArrayFloat(%0)<%1> __@Float(%0,%1)
- #define SaveArray(%0,%1) __@Save(%0,%1)
- #define SaveArrayEx(%0+%1+%2,%3) __@Save(__@com(%0,%1,%2),%3)
- #define LoadArray(%0) __@Load(%0)
- #define Push(%0,%1) %0[0]='\0',strcat(%0,%1,0x80)
- #define CountIndexArray(%0) __@count(%0)
- #define SortIndexArray(%0) __@Sort(%0)
- #define GetIndexArray(%0)<%1> __@index(%0,%1)
- #define return->Array(%0); {new __tmp[_b_Data]; return format(__tmp,_b_Data,%0),__tmp;}
- #define LoadArrayEx(%0+%1+%2) __@Load(__@com(%0,%1,%2))
- stock static const null[_s_Data] = "<null>",rNull[_r_Data] = "<null>",bNull[_b_Data] = "<null>";
- stock __@com(const s1[], const s2[], const s3[]) {
- new tmp[_s_Data];
- return strcat(tmp,s1,_s_Data),strcat(tmp,s2,_s_Data),strcat(tmp,s3,_s_Data),tmp;
- }
- stock __@count(const arr[]) {
- if(!arr[0]) return 0;
- if(arr[0] != 'i' || arr[1] != 'd' || arr[2] != 'x' || arr[3] != ':') return 0;
- for(new i, pos; i<_s_Data; i++) {
- pos = strfind(arr,",",false,pos+1);
- if(pos == -1) return (i+1);
- }
- return 0;
- }
- stock __@index(const arr[], idx) {
- if(!arr[0] || idx < 0) return INVALID;
- if(arr[0] != 'i' || arr[1] != 'd' || arr[2] != 'x' || arr[3] != ':') return INVALID;
- new _tmp[_m_Data];
- for(new i, pos, oldpos = strfind(arr,":")+1; i<_s_Data; i++) {
- pos = strfind(arr,",",false,oldpos);
- if(i == idx) return strmid(_tmp,arr,oldpos,(pos!=-1)?pos:strlen(arr),_m_Data),strval(_tmp);
- oldpos = pos+1;
- if(pos == -1 && i < idx) return INVALID;
- }
- return INVALID;
- }
- stock __@Sort(const arr[]) {
- if(!arr[0]) return rNull;
- if(arr[0] != 'i' || arr[1] != 'd' || arr[2] != 'x' || arr[3] != ':') return rNull;
- new array[_s_Data],l=CountIndexArray(arr);
- for(new i; i<l; i++) array[i] = GetIndexArray(arr)<i>;
- __quickSort(array, 0, l - 1);
- new tmp[_r_Data];
- format(tmp,_r_Data,"idx: %d",array[0]);
- for(new x=1; x<l; x++) format(tmp,_r_Data,"%s, %d",tmp,array[x]);
- return tmp;
- }
- stock __quickSort(array[], left, right) //(c) by Ryder
- {
- new tempLeft = left,tempRight = right,pivot = array[(left + right) / 2],tempVar;
- while(tempLeft <= tempRight) {
- while(array[tempLeft] < pivot) tempLeft++;
- while(array[tempRight] > pivot) tempRight--;
- if(tempLeft <= tempRight) {
- tempVar = array[tempLeft], array[tempLeft] = array[tempRight], array[tempRight] = tempVar;
- tempLeft++, tempRight--;
- }
- }
- if(left < tempRight) __quickSort(array, left, tempRight);
- if(tempLeft < right) __quickSort(array, tempLeft, right);
- }
- stock __@Save(const path[], const data[]) {
- new File:_f=fopen(path,io_write);
- return fwrite(_f,data),fclose(_f);
- }
- stock __@Load(const path[]) {
- if(!fexist(path)) return bNull;
- new File:_f=fopen(path,io_read),_buf[_b_Data];
- return fread(_f,_buf),fclose(_f),_buf;
- }
- stock __@(const string[], const sub[]) {
- new tmp[_s_Data],l=strlen(sub)+1;
- if(l > (_s_Data-1)) return null;
- strcat(tmp,sub,sizeof tmp),strcat(tmp,":",sizeof tmp);
- new pos = strfind(string,sub),pos1 = strfind(string,";",false,pos);
- if(pos == -1 || pos1 == -1) return null;
- return strmid(tmp,string,pos+(l+1),pos1,sizeof tmp),tmp;
- }
- stock Float:__@Float(const string[], const sub[]) {
- new tmp[_s_Data],l=strlen(sub)+1;
- if(l > (_s_Data-1)) return 0.0;
- strcat(tmp,sub,sizeof tmp),strcat(tmp,":",sizeof tmp);
- new pos = strfind(string,sub),pos1 = strfind(string,";",false,pos);
- if(pos == -1 || pos1 == -1) return 0.0;
- return strmid(tmp,string,pos+(l+1),pos1,sizeof tmp),floatstr(tmp);
- }
- stock __@Int(const string[], const sub[]) {
- new tmp[_s_Data],l=strlen(sub)+1;
- if(l > (_s_Data-1)) return 0;
- strcat(tmp,sub,sizeof tmp),strcat(tmp,":",sizeof tmp);
- new pos = strfind(string,sub),pos1 = strfind(string,";",false,pos);
- if(pos == -1 || pos1 == -1) return 0;
- return strmid(tmp,string,pos+(l+1),pos1,sizeof tmp),strval(tmp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement