Advertisement
Guest User

gl_common

a guest
Feb 16th, 2012
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. //----------------------------------------------------------
  2. //
  3. // GRAND LARCENY common functions include.
  4. //
  5. //----------------------------------------------------------
  6.  
  7. stock LoadStaticVehiclesFromFile(const filename[])
  8. {
  9. new File:file_ptr;
  10. new line[256];
  11. new var_from_line[64];
  12. new vehicletype;
  13. new Float:SpawnX;
  14. new Float:SpawnY;
  15. new Float:SpawnZ;
  16. new Float:SpawnRot;
  17. new Color1, Color2;
  18. new index;
  19. new vehicles_loaded;
  20.  
  21. file_ptr = fopen(filename,filemode:io_read);
  22. if(!file_ptr) return 0;
  23.  
  24. vehicles_loaded = 0;
  25.  
  26. while(fread(file_ptr,line,256) > 0)
  27. {
  28. index = 0;
  29.  
  30. // Read type
  31. index = token_by_delim(line,var_from_line,',',index);
  32. if(index == (-1)) continue;
  33. vehicletype = strval(var_from_line);
  34. if(vehicletype < 400 || vehicletype > 611) continue;
  35.  
  36. // Read X, Y, Z, Rotation
  37. index = token_by_delim(line,var_from_line,',',index+1);
  38. if(index == (-1)) continue;
  39. SpawnX = floatstr(var_from_line);
  40.  
  41. index = token_by_delim(line,var_from_line,',',index+1);
  42. if(index == (-1)) continue;
  43. SpawnY = floatstr(var_from_line);
  44.  
  45. index = token_by_delim(line,var_from_line,',',index+1);
  46. if(index == (-1)) continue;
  47. SpawnZ = floatstr(var_from_line);
  48.  
  49. index = token_by_delim(line,var_from_line,',',index+1);
  50. if(index == (-1)) continue;
  51. SpawnRot = floatstr(var_from_line);
  52.  
  53. // Read Color1, Color2
  54. index = token_by_delim(line,var_from_line,',',index+1);
  55. if(index == (-1)) continue;
  56. Color1 = strval(var_from_line);
  57.  
  58. index = token_by_delim(line,var_from_line,';',index+1);
  59. Color2 = strval(var_from_line);
  60.  
  61. //printf("%d,%.2f,%.2f,%.2f,%.4f,%d,%d",vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2);
  62.  
  63. AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(30*60)); // respawn 30 minutes
  64.  
  65. /*new numplate_test[32+1];
  66. format(numplate_test,32,"GRLC{44AA33}%d",vid);
  67. SetVehicleNumberPlate(vid, numplate_test);*/
  68.  
  69. vehicles_loaded++;
  70. }
  71.  
  72. fclose(file_ptr);
  73. printf("Loaded %d vehicles from: %s",vehicles_loaded,filename);
  74. return vehicles_loaded;
  75. }
  76.  
  77. //----------------------------------------------------------
  78.  
  79. stock strtok(const string[], &index)
  80. {
  81. new length = strlen(string);
  82. while ((index < length) && (string[index] <= ' '))
  83. {
  84. index++;
  85. }
  86.  
  87. new offset = index;
  88. new result[20];
  89. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  90. {
  91. result[index - offset] = string[index];
  92. index++;
  93. }
  94. result[index - offset] = EOS;
  95. return result;
  96. }
  97.  
  98. //------------------------------------------------
  99.  
  100. stock strrest(const string[], &index)
  101. {
  102. new length = strlen(string);
  103. while ((index < length) && (string[index] <= ' '))
  104. {
  105. index++;
  106. }
  107. new offset = index;
  108. new result[128];
  109. while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
  110. {
  111. result[index - offset] = string[index];
  112. index++;
  113. }
  114. result[index - offset] = EOS;
  115. return result;
  116. }
  117.  
  118. //----------------------------------------------------------
  119. // Tokenise by a delimiter
  120. // Return string and index of the end determined by the
  121. // provided delimiter in delim
  122.  
  123. stock token_by_delim(const string[], return_str[], delim, start_index)
  124. {
  125. new x=0;
  126. while(string[start_index] != EOS && string[start_index] != delim) {
  127. return_str[x] = string[start_index];
  128. x++;
  129. start_index++;
  130. }
  131. return_str[x] = EOS;
  132. if(string[start_index] == EOS) start_index = (-1);
  133. return start_index;
  134. }
  135.  
  136. //----------------------------------------------------------
  137.  
  138. stock isNumeric(const string[])
  139. {
  140. new length=strlen(string);
  141. if (length==0) return false;
  142. for (new i = 0; i < length; i++)
  143. {
  144. if (
  145. (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
  146. || (string[i]=='-' && i!=0) // A '-' but not at first.
  147. || (string[i]=='+' && i!=0) // A '+' but not at first.
  148. ) return false;
  149. }
  150. if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  151. return true;
  152. }
  153.  
  154. //----------------------------------------------------------
  155.  
  156. stock IsKeyJustDown(key, newkeys, oldkeys)
  157. {
  158. if((newkeys & key) && !(oldkeys & key)) return 1;
  159. return 0;
  160. }
  161.  
  162. //----------------------------------------------------------
  163.  
  164. stock PlaySoundForAll(soundid, Float:x, Float:y, Float:z)
  165. {
  166. for(new i=0; i<MAX_PLAYERS; i++)
  167. {
  168. if(IsPlayerConnected(i))
  169. {
  170. PlayerPlaySound(i, soundid, x, y, z);
  171. }
  172. }
  173. }
  174.  
  175. //----------------------------------------------------------
  176.  
  177. stock PlaySoundForPlayersInRange(soundid, Float:range, Float:x, Float:y, Float:z)
  178. {
  179. for(new i=0; i<MAX_PLAYERS; i++)
  180. {
  181. if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i,range,x,y,z))
  182. {
  183. PlayerPlaySound(i, soundid, x, y, z);
  184. }
  185. }
  186. }
  187.  
  188. //----------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement