| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //----------------------------------------------------------
- //
- // GRAND LARCENY common functions include.
- //
- //----------------------------------------------------------
- stock LoadStaticVehiclesFromFile(const filename[])
- {
- new File:file_ptr;
- new line[256];
- new var_from_line[64];
- new vehicletype;
- new Float:SpawnX;
- new Float:SpawnY;
- new Float:SpawnZ;
- new Float:SpawnRot;
- new Color1, Color2;
- new index;
- new vehicles_loaded;
- file_ptr = fopen(filename,filemode:io_read);
- if(!file_ptr) return 0;
- vehicles_loaded = 0;
- while(fread(file_ptr,line,256) > 0)
- {
- index = 0;
- // Read type
- index = token_by_delim(line,var_from_line,',',index);
- if(index == (-1)) continue;
- vehicletype = strval(var_from_line);
- if(vehicletype < 400 || vehicletype > 611) continue;
- // Read X, Y, Z, Rotation
- index = token_by_delim(line,var_from_line,',',index+1);
- if(index == (-1)) continue;
- SpawnX = floatstr(var_from_line);
- index = token_by_delim(line,var_from_line,',',index+1);
- if(index == (-1)) continue;
- SpawnY = floatstr(var_from_line);
- index = token_by_delim(line,var_from_line,',',index+1);
- if(index == (-1)) continue;
- SpawnZ = floatstr(var_from_line);
- index = token_by_delim(line,var_from_line,',',index+1);
- if(index == (-1)) continue;
- SpawnRot = floatstr(var_from_line);
- // Read Color1, Color2
- index = token_by_delim(line,var_from_line,',',index+1);
- if(index == (-1)) continue;
- Color1 = strval(var_from_line);
- index = token_by_delim(line,var_from_line,';',index+1);
- Color2 = strval(var_from_line);
- //printf("%d,%d,%f,%f,%f,%f,%d,%d",total_vehicles_from_files+vehicles_loaded+1,vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2);
- AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(30*60)); // respawn 30 minutes
- vehicles_loaded++;
- }
- fclose(file_ptr);
- printf("Loaded %d vehicles from: %s",vehicles_loaded,filename);
- return vehicles_loaded;
- }
- //----------------------------------------------------------
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- //------------------------------------------------
- stock strrest(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[128];
- while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- //----------------------------------------------------------
- // Tokenise by a delimiter
- // Return string and index of the end determined by the
- // provided delimiter in delim
- stock token_by_delim(const string[], return_str[], delim, start_index)
- {
- new x=0;
- while(string[start_index] != EOS && string[start_index] != delim) {
- return_str[x] = string[start_index];
- x++;
- start_index++;
- }
- return_str[x] = EOS;
- if(string[start_index] == EOS) start_index = (-1);
- return start_index;
- }
- //----------------------------------------------------------
- stock isNumeric(const string[])
- {
- new length=strlen(string);
- if (length==0) return false;
- for (new i = 0; i < length; i++)
- {
- if (
- (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
- || (string[i]=='-' && i!=0) // A '-' but not at first.
- || (string[i]=='+' && i!=0) // A '+' but not at first.
- ) return false;
- }
- if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
- return true;
- }
- //----------------------------------------------------------
- stock IsKeyJustDown(key, newkeys, oldkeys)
- {
- if((newkeys & key) && !(oldkeys & key)) return 1;
- return 0;
- }
- //----------------------------------------------------------
|