Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined GetParams_Include_V_1
- ****************************************************************************
- * GetParams Include version 2.0 *
- * Copyright © 2011-2013 "Lenin Ruiz" (Daniel-92) /(=Maxell=) *
- * This file is provided as is (no warranties). *
- ****************************************************************************
- -FAKE NATIVES ------------------------------------------------------------------
- native GetParamsStr(const string[],space, dest[], bool:end_string = false, demiliter = ' ', length = sizeof(dest),bool:useindex=false);
- native GetParams(const string[], space, bool:end_string = false, demiliter = ' ',bool:use_index);
- native GetParamsInt(const string[], space, &dest, demiliter = ' ',bool:use_index);
- native GetParamsFloat(const string[], space, &Float:dest, demiliter = ' ',bool:use_index);
- native GetParamsIndex(const string[], space, demiliter = ' ');
- native CountParams(const string[],demiliter=' ');
- native IsNumeric(const string[]);
- --------------------------------------------------------------------------------
- #endif
- #if defined _getparams_included
- #endinput
- #endif
- #if !defined _samp_included
- #include a_samp
- #endif
- #define _getparams_included
- #if !defined MAX_RESULT_LEN
- #define MAX_RESULT_LEN 128 //Max len of result in GetParams, GetParamsInt and GetParamsFloat
- #endif
- #if !defined isnull
- #define isnull(%1) \
- ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
- #endif
- #pragma tabsize 4
- new gp_data_result[MAX_RESULT_LEN];
- //--------------------------------------------------------------------------
- stock GetParams(const string[], space, bool:end_string = false, demiliter = ' ',bool:use_index=false) {
- GetParamsStr(string,space,gp_data_result,end_string,demiliter,MAX_RESULT_LEN,use_index);
- return gp_data_result;
- }
- //------------------------------------------------------------------------------
- stock GetParamsInt(const params[], space, &value, demiliter = ' ',bool:use_index=false) {
- if(GetParamsStr(params,space,gp_data_result,false,demiliter,_,use_index)) {
- if(IsNumeric(gp_data_result)) {
- value = strval(gp_data_result);
- return true;
- }
- }
- return false;
- }
- //------------------------------------------------------------------------------
- stock GetParamsFloat(const params[], space, &Float:value, demiliter = ' ',bool:use_index=false) {
- if(GetParamsStr(params,space,gp_data_result,false,demiliter,_,use_index)) {
- if(IsNumeric(gp_data_result)) {
- value = floatstr(gp_data_result);
- return true;
- }
- }
- return false;
- }
- //------------------------------------------------------------------------------
- stock CountParams(const string[], demiliter = ' ') {
- new
- len = strlen(string),
- spaces = 1;
- if(len == 0) {
- return 0;
- }
- for(new i=0; i < len; i++) if(string[i] == demiliter) {
- for(new s_c=i+1;s_c<len;s_c++,i++) {
- if(string[s_c]!=' ') {
- break;
- }
- }
- spaces++;
- }
- return spaces;
- }
- //------------------------------------------------------------------------------
- stock GetParamsIndex(const string[], space, demiliter = ' ') {
- new
- len = strlen(string),
- spaces;
- if(len == 0) return -1;
- for(new i=0; i < len; i++) if(string[i] == demiliter) {
- for(new s_c=i+1;s_c<len;s_c++,i++)if(string[s_c]!=' ') {
- break;
- }
- spaces++;
- if(spaces >= space) return i;
- }
- return -1;
- }
- //------------------------------------------------------------------------------
- stock IsNumeric(const string[]) {
- new
- len = strlen(string),
- bool:d_f = false;
- if(len == 0) return false;
- for(new i=0; i < len; i++) {
- switch(string[i]) {
- case '0'..'9': continue;
- case '-','+' : if(i) return false;
- case '.': if(d_f || i == (len-1)) return false; else d_f = true;
- default: return false;
- }
- }
- return true;
- }
- //------------------------------------------------------------------------------
- #undef MAX_RESULT_LEN
- //------------------------------------------------------------------------------
- #if defined GET_PARAMS_USE_PLUGIN
- #pragma library params
- native GetParamsStr(const string[],space,dest[],bool:end_string=false,demiliter = ' ',length=sizeof dest,bool:use_index=false);
- native GetParamsUseIndex(toggle=true);
- #endinput
- #endif
- new
- bool:get_params_use_index = false,
- get_params_last_index = 0,
- get_params_last_space = 0;
- stock GetParamsStr(const string[],space,dest[],bool:end_string=false,demiliter = ' ',length=sizeof dest,bool:use_index=false) {
- if(space<=0) {
- printf("** GetParams: Se esperaba obtener un parámetro mayor a 0 pero se encontró un %d",space);
- return 0;
- }
- if(!string[0] || string[0]=='\1' || length<=0) {
- return 0;
- }
- static
- len, space_,
- i, s_c,
- l_char, l_space,
- index;
- if(use_index || get_params_use_index) {
- if(space > get_params_last_space) {
- space_=get_params_last_space;
- i=get_params_last_index;
- }
- else {
- space_=i=0;
- //len = strlen(string);
- }
- }
- else {
- space_=i=0,
- len = strlen(string);
- }
- for(;i<len;i++) if(string[i]!=' ') {
- break;
- }
- l_space = i;
- get_params_last_space = space;
- for(;i<len;i++) {
- if(string[i]==demiliter) {
- l_char=i;
- for(s_c=i+1;s_c<len;s_c++,i++)if(string[s_c]!=' ') {
- break;
- }
- space_++;
- if(space_>=space) {
- s_c=0, get_params_last_index = i+1;
- if(!end_string){
- if(length<(l_char-l_space)) l_char=(l_space+length)-1;
- for(index=l_space;index<l_char;dest[s_c++]=string[index++]) {
- //continue
- }
- dest[s_c]='\0';
- return l_space+1;
- }
- if(length<(len-l_space)) len =(l_space+length)-1;
- for(index=l_space;index<len;dest[s_c++]=string[index++]) {
- //continue
- }
- dest[s_c]='\0';
- return l_space+1;
- }
- l_space=i+1;
- }
- }
- if(space_==space-1 && len>l_space && string[l_space]!=demiliter) {
- s_c=0, get_params_last_index = i+1;
- if(length<(len-l_space))len=(l_space+length)-1;
- for(index=l_space;index<len; dest[s_c++]=string[index++]){
- //continue;
- }
- dest[s_c]='\0';
- return l_space+1;
- }
- return 0;
- }
- //--------------------------------------------------------------------------
- stock GetParamsUseIndex(bool:toggle = true) {
- get_params_use_index = toggle;
- get_params_last_index = 0;
- get_params_last_space = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment