07.02.2009, 15:33
Hey guys,
first excuse my english, i'm from germany
Now to my problem:
Player A owns a car with VehicleID 25 and Player B owns a car wiht VehicleID 26.
Each player has a right to lock/unlock his personal vehicle, but not the vehicle belonging to the other player. Also the vehicles get spawned at gamemodeinit at their position wich is saved in a file (one file for each vehicle).
The problem is, that when i delete for example the car with VehicleID 25 and restart the server (wich is neccesary from time to time), all cars get mixed up....
After the restart, car 26 becomes car 25 and so on. I understand WHY this happens (the ID of the deleted car is now avaiable for the the next car being spawned), but i just don't know how to fix it.
As you already know, each player has specific rights for his vehicles, but if all the IDs get mixed up, the system won't work properly.
These are the function affecting the cars/vehicles:
Please help me, i just don't know how to solve this problem and i can't let my users play properly if this stuff isn't working.
Thanks, modmk
first excuse my english, i'm from germany
Now to my problem:
Player A owns a car with VehicleID 25 and Player B owns a car wiht VehicleID 26.
Each player has a right to lock/unlock his personal vehicle, but not the vehicle belonging to the other player. Also the vehicles get spawned at gamemodeinit at their position wich is saved in a file (one file for each vehicle).
The problem is, that when i delete for example the car with VehicleID 25 and restart the server (wich is neccesary from time to time), all cars get mixed up....
After the restart, car 26 becomes car 25 and so on. I understand WHY this happens (the ID of the deleted car is now avaiable for the the next car being spawned), but i just don't know how to fix it.
As you already know, each player has specific rights for his vehicles, but if all the IDs get mixed up, the system won't work properly.
These are the function affecting the cars/vehicles:
Код:
//Under OnGameModeInit: new string[128]; for(new count=1;count<MAX_OWN_CARS;count++) { format(string, sizeof(string),"cars/car%d.ini",count); if(dini_Exists(string)) { new model; new vehid; new locked; new Float:xt; new Float:yt; new Float:zt; new Float:at; new color1; new color2; new fuel; new plate[256]; model = dini_Int(string,"auto_model"); locked = dini_Int(string,"auto_locked"); xt = dini_Float(string,"auto_x"); yt = dini_Float(string,"auto_y"); zt = dini_Float(string,"auto_z"); at = dini_Float(string,"auto_a"); color1 = dini_Int(string,"auto_farbe1"); color2 = dini_Int(string,"auto_farbe2"); fuel = dini_Int(string, "Benzin"); plate = dini_Get(string, "nummernschild"); vehid = CreateVehicle(model,xt,yt,zt,at,color1,color2,-1); model = GetVehicleModel(vehid); SetVehicleNumberPlate(vehid,plate); cInfo[vehid][cLocked] = locked; Gas[vehid] = fuel; Meters[vehid] = 0; SaveCoords(vehid); } }
Код:
//Under OnGameModeExit: for(new v;v<MAX_VEHICLES;v++) { DestroyVehicle(v); }
Код:
//Under OnPlayerCommandText: if(strcmp(cmdtext, "/savecarspawn", true) == 0) //Fahrzeugkoords speichern { if(IsPlayerConnected(playerid)) { if(!IsPlayerInAnyVehicle(playerid)) { SendClientMessage(playerid,COLOR_GREY,"Du bist in keinem Fahrzeug!"); return 1; } new name[MAX_PLAYER_NAME]; new currentveh; new Float:spawnx; new Float:spawny; new Float:spawnz; new Float:spawna; new Float:health; new gas; currentveh = GetPlayerVehicleID(playerid); GetVehicleHealth(currentveh, health); gas = Gas[currentveh]; GetPlayerName(playerid, name, sizeof(name)); new VID = GetPlayerVehicleID(playerid); currentveh = GetPlayerVehicleID(playerid); GetVehiclePos(currentveh, spawnx, spawny, spawnz); GetVehicleZAngle(currentveh, spawna); format(string, sizeof(string),"cars/car%d.ini",VID); if(dini_Exists(string)) { dini_Create(string); dini_FloatSet(string,"auto_x",spawnx); dini_FloatSet(string,"auto_y",spawny); dini_FloatSet(string,"auto_z",spawnz); dini_FloatSet(string,"auto_a",spawna); dini_FloatSet(string,"Health",health); dini_IntSet(string,"Benzin",gas); dini_IntSet(string,"auto_locked",0); SendClientMessage(playerid,COLOR_DMV,"Fahrzeugposition gespeichert!"); return 1; } } return 1; } if(strcmp(cmd, "/createcar", true) == 0) //Fahrzeug Spawnen { if(IsPlayerAdmin(playerid) || (pInfo[playerid][pAdmin] >= 2)) { new var1; new tmp1[128]; tmp1 = strtok(cmdtext, idx); if(!strlen(tmp1)) return SendClientMessage(playerid, COLOR_WHITE, "HILFE: /createcar [ModelID]"); var1 = strval(tmp1); if((var1 == 407 || var1 == 432 || var1 == 441 || var1 == 447 || var1 == 449 || var1 == 464 || var1 == 465 || var1 == 501 || var1 == 520 || var1 == 532 || var1 == 537 || var1 == 538 || var1 == 539 || var1 == 544 || var1 == 564 || var1 == 569 || var1 == 570 || var1 == 571 || var1 == 577 || var1 == 590 || var1 == 592 || var1 == 594 || var1 == 608 || var1 == 610) || var1 < 400 || var1 > 611) { SendClientMessage(playerid, COLOR_RED, "Model ID ungьltig bzw. nicht erlaubt"); return 1; } else { new Float:x, Float:y, Float:z, Float:a; GetPlayerFacingAngle(playerid, a); GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, AngleVEH); GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, AngleVEH); GetPlayerPos(playerid, x, y, z); new v = CreateVehicle(var1, x+2, y+2, z, AngleVEH+90, -1, -1, -1); Gas[v] = 100; new fuel = Gas[v]; new model = GetVehicleModel(v); new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); new nummer; nummer = pInfo[playerid][pNumber]; GetVehiclePos(v, x, y, z); GetPlayerFacingAngle(playerid, a); new Float:health; GetVehicleHealth(v, health); format(string, sizeof(string),"cars/car%d.ini",v); if(!dini_Exists(string)) { dini_Create(string); dini_IntSet(string, "auto_model",model); dini_IntSet(string,"auto_veh",v); dini_FloatSet(string,"auto_x",x); dini_FloatSet(string,"auto_y",y); dini_FloatSet(string,"auto_z",z); dini_FloatSet(string,"auto_a",a); dini_IntSet(string,"auto_farbe1",-1); dini_IntSet(string,"auto_farbe2",-1); dini_FloatSet(string,"Health",health); dini_IntSet(string,"Benzin",fuel); dini_IntSet(string,"besitzer_nummer",nummer); dini_IntSet(string,"nutzer_nummer",0); dini_Set(string,"auto_besitzer",name); dini_Set(string,"auto_nutzer","nobody"); dini_IntSet(string,"auto_locked",0); dini_Set(string,"nummernschild","None"); } format(string, sizeof(string), "Fahrzeug %d wurde gespawned", var1); SendClientMessage(playerid, COLOR_WHITE, string); GetPlayerName(playerid, pName, sizeof(pName)); format(fm,sizeof(fm), "%s nutzt CMD: /createcar und spawned die VehicleID %d (Typ %d)",pName, v, var1); SaveCMD(fm); return 1; } } else { SendClientMessage(playerid, COLOR_GREY, "Dazu hast du nicht genug Rechte!"); return 1; } } if(strcmp(cmdtext, "/delcar", true) == 0) //Fahrzeug zerstцren (ADMINCMD) { if(IsPlayerAdmin(playerid) || (pInfo[playerid][pAdmin] >= 2)) { new currentveh; currentveh = GetPlayerVehicleID(playerid); RemovePlayerFromVehicle(playerid); DestroyVehicle(currentveh); format(string, sizeof(string),"tuning/%d.mod",currentveh); if(dini_Exists(string)) { dini_Remove(string); } GetPlayerName(playerid, pName, sizeof(pName)); format(fm,sizeof(fm), "%s nutzt CMD: /delcar und lцscht die VehicleID %d",pName, currentveh); SaveCMD(fm); return 1; } else { SendClientMessage(playerid, COLOR_RED, "Dazu hast du nicht genьgend Rechte!"); return 1; } } if(strcmp(cmd, "/setcarowner", true) == 0) { new vehid = GetPlayerVehicleID(playerid); new number; format(string, sizeof(string), "cars/car%d.ini", vehid); if(dini_Exists(string)) { number = dini_Int(string, "besitzer_nummer"); } if(IsPlayerAdmin(playerid) || (pInfo[playerid][pSupporter] == 1) || (pInfo[playerid][pAdmin] >= 1) || pInfo[playerid][pNumber] == number) { if(IsPlayerConnected(playerid)) { tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_WHITE,"FEHLER: SpielerID ungьltig!"); return 1; } gPlayer = strval(tmp); new vid; vid = GetPlayerVehicleID(playerid); if(!IsPlayerConnected(gPlayer)) { SendClientMessage(playerid, COLOR_GREY, "Spieler ist nicht online!"); return 1; } if(gPlayer != INVALID_PLAYER_ID) { cInfo[vid][cOwner] = gPlayer; new Float:spawnx, Float:spawny, Float:spawnz, Float:spawnangle; new ownername[40]; new playername[128]; new besitzer = pInfo[gPlayer][pNumber]; new carowner[MAX_PLAYER_NAME]; GetPlayerName(gPlayer, carowner, sizeof(carowner)); new model; new Float:health; GetPlayerName(playerid, ownername, sizeof(ownername)); GetPlayerPos(playerid,spawnx,spawny,spawnz); GetPlayerFacingAngle(playerid,spawnangle); GetPlayerName(gPlayer, playername, sizeof(playername)); new fuel = Gas[vid]; model = GetVehicleModel(vid); GetVehicleHealth(vid, health); new string4[128]; format(string4, sizeof(string4),"cars/car%d.ini",vid); if(!dini_Exists(string4)) { dini_Create(string4); dini_IntSet(string4, "auto_model",model); dini_IntSet(string4,"auto_veh",vid); dini_FloatSet(string4,"auto_x",spawnx); dini_FloatSet(string4,"auto_y",spawny); dini_FloatSet(string4,"auto_z",spawnz); dini_FloatSet(string4,"auto_a",spawnangle); dini_IntSet(string4,"auto_farbe1",-1); dini_IntSet(string4,"auto_farbe2",-1); dini_FloatSet(string4,"Health",health); dini_IntSet(string4,"Benzin",fuel); dini_IntSet(string4,"besitzer_nummer",besitzer); dini_IntSet(string4,"nutzer_nummer",0); dini_Set(string4,"auto_besitzer",carowner); dini_Set(string4,"auto_nutzer","nobody"); dini_IntSet(string4,"auto_locked",0); dini_Set(string4,"nummernschild","None"); } else if(dini_Exists(string4)) { dini_IntSet(string4,"besitzer_nummer",besitzer); dini_Set(string4,"auto_besitzer",carowner); dini_Set(string4,"auto_nutzer","nobody"); dini_IntSet(string4,"auto_locked",0); } format(fm,sizeof(fm),"Du hast %s als Besitzer fьr dieses Fahrzeug eingetragen!", playername); SendClientMessage(playerid, COLOR_BLUE, fm); SendClientMessage(gPlayer, COLOR_BLUE, "Du wurdest als Besitzer fьr dieses Fahrzeug eingetragen!"); GetPlayerName(playerid, pName, sizeof(pName)); GetPlayerName(gPlayer, gName, sizeof(gName)); format(fm,sizeof(fm), "%s nutzt CMD: /setcarowner und ьbertrдgt %s das Fahrzeug %d",pName, gName, vid); SaveCMD(fm); return 1; } return 1; } else { SendClientMessage(playerid, COLOR_GREY, "Dazu hast du nicht genьgend Rechte!"); return 1; } } return 1; }
Thanks, modmk