#include #define NOME_DO_FILE "Allcars.txt"//Onde os carros são gravados e loaded. NÃO TE ESQUÇEÇAS DO .txt! public OnFilterScriptInit() { print("\n--------------------------------------"); print("Sistema de carros - Firecat"); print("--------------------------------------\n"); LoadStaticVehiclesFromFile(NOME_DO_FILE); return 1; } public OnFilterScriptExit() { return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if(strcmp(cmdtext,"/savecar",true) == 0) { if(!IsPlayerAdmin(playerid)) return 0; new Float:x,Float:y,Float:z,Float:angle,vehicleid,string[200]; vehicleid = GetPlayerVehicleID(playerid); GetVehicleZAngle(vehicleid,angle); GetVehiclePos(vehicleid,x,y,z); new File:example = fopen(NOME_DO_FILE, io_append); format(string,sizeof(string),"%i,%f,%f,%f,%f,%i,%i;\n",GetVehicleModel(vehicleid),x,y,z,angle,random(255),random(255));//As cores são gravadas randomicamente. fwrite(example,string); fclose(example); format(string,sizeof(string),"» Vehicle: %i foi gravado.",GetVehicleModel(vehicleid)); SendClientMessage(playerid,0x00CD1EFF,string); return 1; } return 0; } stock LoadStaticVehiclesFromFile(const filename[])//Retirado do Grandlarc { 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); 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); AddStaticVehicle(vehicletype,SpawnX,SpawnY,SpawnZ+2,SpawnRot,Color1,Color2); vehicles_loaded++; } fclose(file_ptr); printf("Loaded %d vehicles from: %s",vehicles_loaded,filename); return vehicles_loaded; } stock token_by_delim(const string[], return_str[], delim, start_index)//Retirado do Grandlarc { 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; }