13.01.2012, 15:02
hy..
Afther Rester i need to buy again the car why??
Afther Rester i need to buy again the car why??
pawn Код:
//===========================Section: Includes==================================
#include <a_samp>
#include <utils>
//===========================Section: Definations===============================
#define COLOR_GRAD1 0xB4B5B7FF
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_GRAD3 0xCBCCCEFF
#define COLOR_GRAD4 0xD8D8D8FF
#define COLOR_GRAD5 0xE3E3E3FF
#define COLOR_GRAD6 0xF0F0F0FF
#define COLOR_GREEN 0x33AA33AA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_BLUE 0x2641FEAA
#pragma tabsize 0
//===========================Section: Forwards==================================
forward split(const strsrc[], strdest[][], delimiter);
forward LoadCar();
forward SaveCarCoords();
forward OnPropUpdate();
forward IsAnOwnableCar(vehicleid);
forward CarKeys(playerid);
forward SavePlayerData(playerid);
forward ini_GetKey( line[] );
forward ini_GetValue( line[] );
forward OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
new carsonserver = 293;
new vehName[][] = {
"Landstalker",
"Bravura",
"Buffalo",
"Linerunner",
"Perrenial",
"Sentinel",
"Dumper",
"Firetruck",
"Trashmaster",
"Stretch",
"Manana",
"Infernus",
"Voodoo",
"Pony",
"Mule",
"Cheetah",
"Ambulance",
"Leviathan",
"Moonbeam",
"Esperanto",
"Taxi",
"Washington",
"Bobcat",
"Whoopee",
"BF Injection",
"Hunter",
"Premier",
"Enforcer",
"Securicar",
"Banshee",
"Predator",
"Bus",
"Rhino",
"Barracks",
"Hotknife",
"Trailer",
"Previon",
"Coach",
"Cabbie",
"Stallion",
"Rumpo",
"RC Bandit",
"Romero",
"Packer",
"Monster",
"Admiral",
"Squalo",
"Seasparrow",
"Pizzaboy",
"Tram",
"Trailer",
"Turismo",
"Speeder",
"Reefer",
"Tropic",
"Flatbed",
"Yankee",
"Caddy",
"Solair",
"Berkley's RC Van",
"Skimmer",
"PCJ-600",
"Faggio",
"Freeway",
"RC Baron",
"RC Raider",
"Glendale",
"Oceanic",
"Sanchez",
"Sparrow",
"Patriot",
"ATV",
"Coastguard",
"Dinghy",
"Hermes",
"Sabre",
"Rustler",
"ZR-350",
"Walton",
"Regina",
"Comet",
"BMX",
"Burrito",
"Camper",
"Marquis",
"Baggage",
"Dozer",
"Maverick",
"News Chopper",
"Rancher",
"FBI Rancher",
"Virgo",
"Greenwood",
"Jetmax",
"Hotring",
"Sandking",
"Blista Compact",
"Police Maverick",
"Boxvillde",
"Benson",
"Mesa",
"RC Goblin",
"Hotring Racer A",
"Hotring Racer B",
"Bloodring Banger",
"Rancher",
"Super GT",
"Elegant",
"Journey",
"Bike",
"Mountain Bike",
"Beagle",
"Cropduster",
"Stunt",
"Tanker",
"Roadtrain",
"Nebula",
"Majestic",
"Buccaneer",
"Shamal",
"Hydra",
"FCR-900",
"NRG-500",
"HPV1000",
"Cement Truck",
"Tow Truck",
"Fortune",
"Cadrona",
"FBI Truck",
"Willard",
"Forklift",
"Tractor",
"Combine",
"Feltzer",
"Remington",
"Slamvan",
"Blade",
"Freight",
"Streak",
"Vortex",
"Vincent",
"Bullet",
"Clover",
"Sadler",
"Firetruck",
"Hustler",
"Intruder",
"Primo",
"Cargobob",
"Tampa",
"Sunrise",
"Merit",
"Utility",
"Nevada",
"Jeep",
"Windsor",
"Monster",
"Monster",
"Uranus",
"Jester",
"Sultan",
"Stratum",
"Elegy",
"Raindance",
"RC Tiger",
"Flash",
"Tahoma",
"Savanna",
"Bandito",
"Freight Flat",
"Streak Carriage",
"Kart",
"Mower",
"Dune",
"Sweeper",
"Broadway",
"Tornado",
"AT-400",
"DFT-30",
"Huntley",
"Stafford",
"BF-400",
"News Van",
"Tug",
"Trailer",
"Emperor",
"Wayfarer",
"Euros",
"Hotdog",
"Club",
"Freight Box",
"Trailer",
"Andromada",
"Dodo",
"RC Cam",
"Launch",
"Police Car LSPD",
"Police Car SFPD",
"Police Car LVPD",
"Police Ranger",
"Picador",
"S.W.A.T",
"Alpha",
"Phoenix",
"Glendale",
"Sadler",
"Luggage",
"Luggage",
"Stairs",
"Boxville",
"Tiller",
"Utility Trailer"
};
//===========================Section: Variables=================================
enum pInfo
{
pPcarkey,
pPcarkey2,
pPcarkey3,
}
new PlayerInfo[256][pInfo];
enum cInfo
{
cModel,
Float:cLocationx,
Float:cLocationy,
Float:cLocationz,
Float:cAngle,
cColorOne,
cColorTwo,
cOwner[MAX_PLAYER_NAME],
cDescription[12],
cLicense[14],
cRegistration,
cOwned,
cLock,
};
new CarInfo[1000][cInfo];
//===========================Section: strtok & split============================
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;
}
public split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
//===========================Section: Callbacks & Functions=====================
public OnFilterScriptInit()
{
printf("Filterscript carownership.amx Initiated\n");
LoadCar();
for(new h = carsonserver; h < sizeof(CarInfo); h++)
{
AddStaticVehicleEx(CarInfo[h][cModel],CarInfo[h][cLocationx],CarInfo[h][cLocationy],CarInfo[h][cLocationz]+1.0,CarInfo[h][cAngle],CarInfo[h][cColorOne],CarInfo[h][cColorTwo],60000);
}
return 1;
}
public OnFilterScriptExit() { return 1; }
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new carid = GetPlayerVehicleID(playerid);
if ((newkeys & KEY_SECONDARY_ATTACK))
{
if(IsAnOwnableCar(carid) && CarInfo[carid][cOwned] == 0)
{
TogglePlayerControllable(playerid, 1);
RemovePlayerFromVehicle(playerid);
}
}
return 1;
}
public SavePlayerData(playerid)
{
if(IsPlayerConnected(playerid))
{
new string3[32];
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), "carkeys/%s.ini", playername3);
new File: hFile = fopen(string3, io_write);
if (hFile)
{
new var[32];
format(var, 32, "CarKey=%d\n",PlayerInfo[playerid][pPcarkey]);fwrite(hFile, var);
format(var, 32, "CarKey2=%d\n",PlayerInfo[playerid][pPcarkey2]);fwrite(hFile, var);
format(var, 32, "CarKey3=%d\n",PlayerInfo[playerid][pPcarkey3]);fwrite(hFile, var);
fclose(hFile);
}
}
return 1;
}
public CarKeys(playerid)
{
new string2[64];
new playername2[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string2, sizeof(string2), "carkeys/%s.ini", playername2);
new File: UserFile = fopen(string2, io_read);
if ( UserFile )
{
new key[ 256 ] , val[ 256 ];
new Data[ 256 ];
while ( fread( UserFile , Data , sizeof( Data ) ) )
{
key = ini_GetKey( Data );
if( strcmp( key , "CarKey" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pPcarkey] = strval( val ); }
if( strcmp( key , "CarKey2" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pPcarkey2] = strval( val ); }
if( strcmp( key , "CarKey3" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][pPcarkey3] = strval( val ); }
}
fclose(UserFile);
SendClientMessage(playerid, COLOR_WHITE,"Car Keys Loaded!!!");
}
return 1;
}
public OnPropUpdate()
{
new idx;
new File: file2;
idx = carsonserver;
while (idx < sizeof(CarInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%s,%d,%d\n",
CarInfo[idx][cModel],
CarInfo[idx][cLocationx],
CarInfo[idx][cLocationy],
CarInfo[idx][cLocationz],
CarInfo[idx][cAngle],
CarInfo[idx][cColorOne],
CarInfo[idx][cColorTwo],
CarInfo[idx][cOwner],
CarInfo[idx][cDescription],
CarInfo[idx][cLicense],
CarInfo[idx][cOwned],
CarInfo[idx][cLock]);
if(idx == carsonserver)
{
file2 = fopen("cars.cfg", io_write);
}
else
{
file2 = fopen("cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
public IsAnOwnableCar(vehicleid)
{
if(vehicleid >= carsonserver && vehicleid <= 1000) { return 1; }
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(IsAnOwnableCar(vehicleid) && CarInfo[vehicleid][cLock] == 1 && CarInfo[vehicleid][cOwned] == 1)
{
if(IsPlayerAdmin(playerid)) { }
else
{
new Float:cx, Float:cy, Float:cz;
GetPlayerPos(playerid, cx, cy, cz);
SetPlayerPos(playerid, cx, cy, cz);
}
}
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
CarKeys(playerid);
return 1;
}
public OnPlayerConnect(playerid)
{
PlayerInfo[playerid][pPcarkey] = -1;
PlayerInfo[playerid][pPcarkey2] = -1;
PlayerInfo[playerid][pPcarkey3] = -1;
for(new h = carsonserver; h < sizeof(CarInfo); h++)
{
SetVehicleParamsForPlayer(h,playerid,0,CarInfo[h][cLock]);
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new string[256];
new cmd[256];
new tmp[256];
new sendername[MAX_PLAYER_NAME];
new playername[MAX_PLAYER_NAME];
new giveplayerid;
new idcar = GetPlayerVehicleID(playerid);
cmd = strtok(cmdtext, idx);
new vehid;
vehid = GetPlayerVehicleID(playerid);
if (strcmp(cmd, "/mycars", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new carkey = PlayerInfo[playerid][pPcarkey];
new carkey2 = PlayerInfo[playerid][pPcarkey2];
new carkey3 = PlayerInfo[playerid][pPcarkey3];
if (PlayerInfo[playerid][pPcarkey] != -1)
{
format(string, sizeof(string), "1| VehModel:[%s] VehValue:[%d] VehColor1:[%d] VehColor2:[%d] VehLocked:[%d]", CarInfo[carkey][cDescription], CarInfo[carkey][cColorOne], CarInfo[carkey][cColorTwo], CarInfo[carkey][cLock]);
SendClientMessage(playerid, COLOR_GRAD5,string);
}
if (PlayerInfo[playerid][pPcarkey2] != -1)
{
format(string, sizeof(string), "2| VehModel:[%s] VehValue:[%d] VehColor1:[%d] VehColor2:[%d] VehLocked:[%d]", CarInfo[carkey2][cDescription], CarInfo[carkey2][cColorOne], CarInfo[carkey2][cColorTwo], CarInfo[carkey2][cLock]);
SendClientMessage(playerid, COLOR_GRAD5,string);
}
if (PlayerInfo[playerid][pPcarkey3] != -1)
{
format(string, sizeof(string), "3| VehModel:[%s] VehValue:[%d] VehColor1:[%d] VehColor2:[%d] VehLocked:[%d]", CarInfo[carkey3][cDescription], CarInfo[carkey3][cColorOne], CarInfo[carkey3][cColorTwo], CarInfo[carkey3][cLock]);
SendClientMessage(playerid, COLOR_GRAD5,string);
}
}
return 1;
}
if(strcmp(cmd, "/apark", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new Float:x,Float:y,Float:z;
new Float:a;
new carid;
carid = GetPlayerVehicleID(playerid);
GetPlayerName(playerid, playername, sizeof(playername));
GetVehiclePos(carid, x, y, z);
GetVehicleZAngle(carid, a);
if(IsPlayerAdmin(playerid))
{
CarInfo[carid][cLocationx] = x;
CarInfo[carid][cLocationy] = y;
CarInfo[carid][cLocationz] = z;
CarInfo[carid][cAngle] = a;
format(string, sizeof(string), "~n~ You have parked your car in this location. ~n~");
GameTextForPlayer(playerid, "You have parked this car in this position. It will respawn here.", 10000, 3);
OnPropUpdate(); SavePlayerData(playerid);
DestroyVehicle(carid);
CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],60000);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not authorized to use that command !");
return 1;
}
}
return 1;
}
if(strcmp(cmd, "/adeletecar", true) == 0)
{
if(IsPlayerAdmin(playerid))
{
CarInfo[idcar][cOwned] = 0; CarInfo[idcar][cModel] = 0; CarInfo[idcar][cColorOne] = 0; CarInfo[idcar][cColorTwo] = 0;
CarInfo[idcar][cLocationx] = 0; CarInfo[idcar][cLocationy] = 0; CarInfo[idcar][cLocationz] = 0; CarInfo[idcar][cAngle] = 0;
CarInfo[idcar][cLock] = 0;
strmid(CarInfo[idcar][cOwner], "Dealership", 0, strlen("Dealership"), 999);
format(CarInfo[idcar][cDescription], 32, "0");
DestroyVehicle(idcar);
OnPropUpdate(); SavePlayerData(playerid);
}
}
if(strcmp(cmd, "/acreateveh", true) == 0)
{
if(IsPlayerAdmin(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "FOLOSESTE: /acreateveh [carid] [color1] [color2]");
return 1;
}
new car;
car = strval(tmp);
if(car < 400 || car > 611) { SendClientMessage(playerid, COLOR_WHITE, " Id vehiculului nu poate sa fie mai mic de 400 si mai mare de 611 !"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "FOLOSESTE: /acreateveh [carid] [color1] [color2]");
return 1;
}
new color1;
color1 = strval(tmp);
if(color1 < 0 || color1 > 252) { SendClientMessage(playerid, COLOR_WHITE, " Id culori este de la 0 la 252 !"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "FOLOSESTE: /acreateveh [carid] [color1] [color2]");
return 1;
}
new color2;
color2 = strval(tmp);
if(color2 < 0 || color2 > 126) { SendClientMessage(playerid, COLOR_WHITE, " Id culori este de la 0 la 252 !"); return 1; }
new Float:X,Float:Y,Float:Z; GetPlayerPos(playerid, X,Y,Z);
new thiscar = CreateVehicle(car,X,Y,Z,1,color1,color2,99999999);
CarInfo[thiscar][cOwned] = 0; CarInfo[thiscar][cModel] = car; CarInfo[thiscar][cColorOne] = color1; CarInfo[thiscar][cColorTwo] = color2;
CarInfo[thiscar][cLocationx] = X; CarInfo[thiscar][cLocationy] = Y; CarInfo[thiscar][cLocationz] = Z; CarInfo[thiscar][cAngle] = 1;
CarInfo[thiscar][cLock] = 0;
PutPlayerInVehicle(playerid,thiscar,0);
strmid(CarInfo[vehid][cOwner], "Dealership", 0, strlen("Dealership"), 999);
format(CarInfo[thiscar][cDescription], 32, "%s",vehName[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
format(string, sizeof(string), " Masina %d a fost creata cu succes!.", thiscar);
SendClientMessage(playerid, COLOR_BLUE, string);
}
else
{
SendClientMessage(playerid, COLOR_GRAD1, " Nu esti autorizat sa folosesti aceasta comanda!!!");
return 1;
}
}
if(!strcmp(cmdtext, "/asellcar", true))
{
if(IsPlayerConnected(playerid))
{
if(IsPlayerAdmin(playerid))
{
new Float:x,Float:y,Float:z;
new Float:a;
CarInfo[vehid][cOwned] = 0;
strmid(CarInfo[vehid][cOwner], "Dealership", 0, strlen("Dealership"), 999);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
GameTextForPlayer(playerid, "~w~You have admin sold the vehicle", 10000, 3);
GetVehiclePos(vehid, x, y, z);
GetVehicleZAngle(vehid, a);
CarInfo[vehid][cLocationx] = x;
CarInfo[vehid][cLocationy] = y;
CarInfo[vehid][cLocationz] = z;
CarInfo[vehid][cAngle] = a;
RemovePlayerFromVehicle(playerid);
TogglePlayerControllable(playerid, 1);
OnPropUpdate(); SavePlayerData(playerid);
DestroyVehicle(vehid);
CreateVehicle(CarInfo[vehid][cModel],CarInfo[vehid][cLocationx],CarInfo[vehid][cLocationy],CarInfo[vehid][cLocationz]+1.0,CarInfo[vehid][cAngle],CarInfo[vehid][cColorOne],CarInfo[vehid][cColorTwo],60000);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You're not authorized to use that command !");
return 1;
}
}
return 1;
}
if(strcmp(cmd, "/asetkey", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /asetkey [playerid/PartOfName] [carkey] [amount]");
SendClientMessage(playerid, COLOR_GRAD4, "|1 CarKey |2 CarKey2 |3 CarKey3");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(IsPlayerAdmin(playerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /asetkey [playerid/PartOfName] [carkey] [amount]");
SendClientMessage(playerid, COLOR_GRAD4, "|1 CarKey |2 CarKey2 |3 CarKey3");
return 1;
}
new stat;
stat = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /asetkey [playerid/PartOfName] [carkey] [amount]");
SendClientMessage(playerid, COLOR_GRAD4, "|1 CarKey |2 CarKey2 |3 CarKey3");
return 1;
}
new amount;
amount = strval(tmp);
switch (stat)
{
case 1:
{
PlayerInfo[giveplayerid][pPcarkey] = amount;
format(string, sizeof(string), " The Player Car Key Was Set To %d", amount);
SavePlayerData(playerid);
}
case 2:
{
PlayerInfo[giveplayerid][pPcarkey2] = amount;
format(string, sizeof(string), " The Player Car Key 2 Was Set To %d", amount);
SavePlayerData(playerid);
}
case 3:
{
PlayerInfo[giveplayerid][pPcarkey3] = amount;
format(string, sizeof(string), " The Player Car Key 3 Was Set To %d", amount);
SavePlayerData(playerid);
}
default:
{
format(string, sizeof(string), " Invalid Car Key Code", amount);
}
}
SendClientMessage(playerid, COLOR_GRAD1, string);
}
}
else
{
SendClientMessage(playerid, COLOR_GRAD1, " Doar adminii pot folosi aceasta comanda!");
return 1;
}
}
return 1;
}
if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new x_nr[64];
x_nr = strtok(cmdtext, idx);
if(!strlen(x_nr))
{
SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
SendClientMessage(playerid, COLOR_WHITE, "Available names: park, lock(1-3), model, color, locate(1-3), tow(1-3)");
return 1;
}
if(strcmp(x_nr,"park",true) == 0)
{
new Float:x,Float:y,Float:z;
new Float:a;
new carid;
new getcarid;
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { carid = PlayerInfo[playerid][pPcarkey]; }
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { carid = PlayerInfo[playerid][pPcarkey2]; }
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { carid = PlayerInfo[playerid][pPcarkey3]; }
else { return 1; }
getcarid = GetPlayerVehicleID(playerid);
GetPlayerName(playerid, playername, sizeof(playername));
GetVehiclePos(carid, x, y, z);
GetVehicleZAngle(carid, a);
if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1)
{
if(PlayerInfo[playerid][pPcarkey] == -1 && PlayerInfo[playerid][pPcarkey2] == -1 && PlayerInfo[playerid][pPcarkey3] == -1)
{
SendClientMessage(playerid, COLOR_GREY, "You don't own a car.");
return 1;
}
if(getcarid == carid)
{
new Float:CarHP, Float:OldCarHP; new panels,doors,lights,tires;
CarInfo[carid][cLocationx] = x;
CarInfo[carid][cLocationy] = y;
CarInfo[carid][cLocationz] = z;
CarInfo[carid][cAngle] = a;
GetVehicleDamageStatus(carid,panels,doors,lights,tires);
GetVehicleHealth(carid, CarHP); OldCarHP = CarHP;
format(string, sizeof(string), "~n~ You have parked your vehicle in this location. ~n~");
GameTextForPlayer(playerid, "You have parked your vehicle in this position. It will respawn here.", 10000, 3);
OnPropUpdate(); SavePlayerData(playerid); DestroyVehicle(carid);
CreateVehicle(CarInfo[carid][cModel],CarInfo[carid][cLocationx],CarInfo[carid][cLocationy],CarInfo[carid][cLocationz]+1.0,CarInfo[carid][cAngle],CarInfo[carid][cColorOne],CarInfo[carid][cColorTwo],60000);
PutPlayerInVehicle(playerid,carid,0); SetVehicleHealth(carid, OldCarHP);
UpdateVehicleDamageStatus(carid,panels,doors,lights,tires);
TogglePlayerControllable(playerid, 1);
return 1;
}
}
}
else if(strcmp(x_nr,"buy",true) == 0)
{
if(IsAnOwnableCar(idcar))
{
if(PlayerInfo[playerid][pPcarkey] == -1) { }
else if(PlayerInfo[playerid][pPcarkey2] == -1) { }
else if(PlayerInfo[playerid][pPcarkey3] == -1) { }
else { SendClientMessage(playerid, COLOR_GREY, " Ai deja 3 masini!!"); return 1; }
if(CarInfo[idcar][cOwned]==1)
{
SendClientMessage(playerid, COLOR_GREY, "Someone already owns this car");
return 1;
}
if(GetPlayerMoney(playerid))
{
if(PlayerInfo[playerid][pPcarkey] == -1) { PlayerInfo[playerid][pPcarkey] = idcar; }
else if(PlayerInfo[playerid][pPcarkey2] == -1) { PlayerInfo[playerid][pPcarkey2] = idcar; }
else if(PlayerInfo[playerid][pPcarkey3] == -1) { PlayerInfo[playerid][pPcarkey3] = idcar; }
else { return 1; }
CarInfo[idcar][cOwned] = 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(CarInfo[idcar][cOwner], sendername, 0, strlen(sendername), 999);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
GameTextForPlayer(playerid, "~w~Felicitari~n~Nu uita sa o parchezi cu /v park!", 5000, 3);
SendClientMessage(playerid, COLOR_GRAD2, "Felicitari ti-ai cumparat o masina noua!");
TogglePlayerControllable(playerid, 1);
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have enough cash with you ! ");
return 1;
}
}
}
else if(strcmp(x_nr,"model",true) == 0)
{
new carid;
new getcarid;
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { carid = PlayerInfo[playerid][pPcarkey]; }
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { carid = PlayerInfo[playerid][pPcarkey2]; }
else { return 1; }
getcarid = GetPlayerVehicleID(playerid);
GetPlayerName(playerid, playername, sizeof(playername));
if(IsPlayerInVehicle(playerid,carid) && CarInfo[carid][cOwned] == 1)
{
if(PlayerInfo[playerid][pPcarkey] == -1 && PlayerInfo[playerid][pPcarkey2] == -1)
{
SendClientMessage(playerid, COLOR_GREY, " You don't have a personal car.");
return 1;
}
if(getcarid == carid)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /v model [vehicleid]");
return 1;
}
new model;
model = strval(tmp);
if(model < 400 && model > 611)
{
SendClientMessage(playerid, COLOR_GREY, " Wrong model id!");
return 1;
}
CarInfo[carid][cModel] = model;
format(CarInfo[carid][cDescription], 32, "%s",vehName[model-400]);
format(string, sizeof(string), " [Veh Info]: {3D9AD4}New vehicle model saved.");
SendClientMessage(playerid, COLOR_YELLOW, string);
OnPropUpdate(); SavePlayerData(playerid);
TogglePlayerControllable(playerid, 1);
return 1;
}
}
else SendClientMessage(playerid, COLOR_GREY, " You are not in personal car");
}
else if(strcmp(x_nr,"lock1",true) == 0)
{
new keycar = PlayerInfo[playerid][pPcarkey];
if(keycar != -1)
{
new locked[256];
locked = strtok(cmdtext, idx);
if(CarInfo[keycar][cLock] == 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,0);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 0;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
else if(CarInfo[keycar][cLock] == 0)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,1);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 1;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have a vehicle at slot 1");
return 1;
}
}
else if(strcmp(x_nr,"lock2",true) == 0)
{
new keycar = PlayerInfo[playerid][pPcarkey2];
if(keycar != -1)
{
new locked[256];
locked = strtok(cmdtext, idx);
if(CarInfo[keycar][cLock] == 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,0);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 0;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
else if(CarInfo[keycar][cLock] == 0)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,1);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 1;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have a vehicle at slot 2");
return 1;
}
}
else if(strcmp(x_nr,"lock3",true) == 0)
{
new keycar = PlayerInfo[playerid][pPcarkey3];
if(keycar != -1)
{
new locked[256];
locked = strtok(cmdtext, idx);
if(CarInfo[keycar][cLock] == 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,0);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~g~Unlocked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 0;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
else if(CarInfo[keycar][cLock] == 0)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(keycar,i,0,1);
}
}
format(string, sizeof(string), "~w~Vehicle~n~~r~Locked");
GameTextForPlayer(playerid, string, 4000, 3);
CarInfo[keycar][cLock] = 1;
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have a vehicle at slot 3");
return 1;
}
}
else if(strcmp(x_nr,"color",true) == 0)
{
if(PlayerInfo[playerid][pPcarkey] == -1 && PlayerInfo[playerid][pPcarkey2] == -1 && PlayerInfo[playerid][pPcarkey3] == -1)
{
SendClientMessage(playerid, COLOR_GREY," You don't have a vehicle to respray.");
return 1;
}
if(GetPlayerMoney(playerid) < 1000)
{
SendClientMessage(playerid, COLOR_GREY," You don't have enough money for vehicle respray.");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /v color [ColorOneID] [ColorTwoID]");
return 1;
}
new color1;
color1 = strval(tmp);
if(color1 < 0 && color1 > 252)
{
SendClientMessage(playerid, COLOR_GREY, " Wrong color id!");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /v color [ColorOneID] [ColorTwoID]");
return 1;
}
new color2;
color2 = strval(tmp);
if(color2 < 0 && color2 > 252)
{
SendClientMessage(playerid, COLOR_GREY, " Wrong color id!");
return 1;
}
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { vehid = PlayerInfo[playerid][pPcarkey]; }
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { vehid = PlayerInfo[playerid][pPcarkey2]; }
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { vehid = PlayerInfo[playerid][pPcarkey3]; }
else { return 1; }
if(IsPlayerInVehicle(playerid, vehid))
{
CarInfo[vehid][cColorOne] = color1;
CarInfo[vehid][cColorTwo] = color2;
GivePlayerMoney(playerid, -1000);
GameTextForPlayer(playerid, "~w~Bill for a Paint Respray~n~~r~-$1000", 5000, 1);
ChangeVehicleColor(vehid, color1, color2);
OnPropUpdate(); SavePlayerData(playerid);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY," You are not in your vehicle.");
return 1;
}
}
else if(strcmp(x_nr,"locate1",true) == 0)
{
if(!IsPlayerConnected(playerid)) { return 1; }
new Float:x,Float:y,Float:z;
new car = PlayerInfo[playerid][pPcarkey];
if(PlayerInfo[playerid][pPcarkey]==-1) { GameTextForPlayer(playerid, "~w~Nu ai o masina pentru a putea fi localizata", 2500, 3); return 1; }
SendClientMessage(playerid,COLOR_WHITE,"Locatia masinii a fost gasita.");
GetVehiclePos(car, x, y, z);
SetPlayerCheckpoint(playerid, x, y, z, 6);
return 1;
}
else if(strcmp(x_nr,"locate2",true) == 0)
{
if(!IsPlayerConnected(playerid)) { return 1; }
new Float:x,Float:y,Float:z;
new car = PlayerInfo[playerid][pPcarkey2];
if(PlayerInfo[playerid][pPcarkey]==-1) { GameTextForPlayer(playerid, "~w~Nu ai o masina pentru a putea fi localizata", 2500, 3); return 1; }
SendClientMessage(playerid,COLOR_WHITE,"Locatia masinii a fost gasita.");
GetVehiclePos(car, x, y, z);
SetPlayerCheckpoint(playerid, x, y, z, 6);
return 1;
}
else if(strcmp(x_nr,"locate3",true) == 0)
{
if(!IsPlayerConnected(playerid)) { return 1; }
new Float:x,Float:y,Float:z;
new car = PlayerInfo[playerid][pPcarkey3];
if(PlayerInfo[playerid][pPcarkey]==-1) { GameTextForPlayer(playerid, "~w~Nu ai o masina pentru a putea fi localizata", 2500, 3); return 1; }
SendClientMessage(playerid,COLOR_WHITE,"Locatia masinii a fost gasita.");
GetVehiclePos(car, x, y, z);
SetPlayerCheckpoint(playerid, x, y, z, 6);
return 1;
}
else if(strcmp(x_nr,"tow1",true) == 0)
{
if(IsPlayerConnected(playerid))
{
new car = PlayerInfo[playerid][pPcarkey];
GetPlayerName(playerid, playername, sizeof(playername));
if (car != -1 && strcmp(playername, CarInfo[PlayerInfo[playerid][pPcarkey]][cOwner], true) == 0)
{
GameTextForPlayer(playerid, "~w~Masina a fost~n~~g~Tractata cu succes~n~~r~$-1500", 5000, 1);
GivePlayerMoney(playerid,-1500);
SetVehicleToRespawn(car);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
else
{
GameTextForPlayer(playerid, "~w~Nu detii o masina personala.", 5000, 1);
}
}
}
else if(strcmp(x_nr,"tow2",true) == 0)
{
if(IsPlayerConnected(playerid))
{
new car = PlayerInfo[playerid][pPcarkey2];
GetPlayerName(playerid, playername, sizeof(playername));
if (car != -1 && strcmp(playername, CarInfo[PlayerInfo[playerid][pPcarkey2]][cOwner], true) == 0)
{
GameTextForPlayer(playerid, "~w~Masina a fost~n~~g~Tractata cu succes~n~~r~$-1500", 5000, 1);
GivePlayerMoney(playerid,-1500);
SetVehicleToRespawn(car);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
else
{
GameTextForPlayer(playerid, "~w~Nu detii o masina personala.", 5000, 1);
}
}
}
else if(strcmp(x_nr,"tow3",true) == 0)
{
if(IsPlayerConnected(playerid))
{
new car = PlayerInfo[playerid][pPcarkey3];
GetPlayerName(playerid, playername, sizeof(playername));
if (car != -1 && strcmp(playername, CarInfo[PlayerInfo[playerid][pPcarkey3]][cOwner], true) == 0)
{
GameTextForPlayer(playerid, "~w~Masina a fost~n~~g~Tractata cu succes~n~~r~$-1500", 5000, 1);
GivePlayerMoney(playerid,-1500);
SetVehicleToRespawn(car);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
else
{
GameTextForPlayer(playerid, "~w~Nu detii o masina personala.", 5000, 1);
}
}
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
SendClientMessage(playerid, COLOR_WHITE, "Available names: park, lock(1-3), model, color locate(1-3), tow(1-3)");
return 1;
}
}
return 1;
}
return 0;
}
public OnPlayerEnterCheckpoint(playerid)
{
DisablePlayerCheckpoint(playerid);
return 1;
}
/*----------Car Save Functions----------*/
public LoadCar()
{
new arrCoords[31][64];
new strFromFile2[256];
new File: file = fopen("cars.cfg", io_read);
if (file)
{
new idx = carsonserver;
while (idx < sizeof(CarInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
CarInfo[idx][cModel] = strval(arrCoords[0]);
CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
CarInfo[idx][cColorOne] = strval(arrCoords[5]);
CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
strmid(CarInfo[idx][cLicense], arrCoords[10], 0, strlen(arrCoords[10]), 255);
CarInfo[idx][cOwned] = strval(arrCoords[11]);
CarInfo[idx][cLock] = strval(arrCoords[12]);
idx++;
}
}
return 1;
}
public SaveCarCoords()
{
new idx;
new File: file2;
while (idx < sizeof(CarInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d\n",
CarInfo[idx][cModel],
CarInfo[idx][cLocationx],
CarInfo[idx][cLocationy],
CarInfo[idx][cLocationz],
CarInfo[idx][cAngle],
CarInfo[idx][cColorOne],
CarInfo[idx][cColorTwo]);
if(idx == carsonserver)
{
file2 = fopen("cars.cfg", io_write);
}
else
{
file2 = fopen("cars.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new string[128];
new vehicle = GetPlayerVehicleID(playerid);
new newcar = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER)
{
if(IsAnOwnableCar(newcar))
{
if(CarInfo[newcar][cOwned]==0)
{
TogglePlayerControllable(playerid, 0);
format(string,sizeof(string),"/v buy to buy this vehicle",CarInfo[newcar][cDescription]);
SendClientMessage(playerid, COLOR_BLUE, string);
SendClientMessage(playerid, COLOR_BLUE, "or press Enter to exit this vehicle");
}
if(CarInfo[newcar][cOwned]==1)
{
format(string,sizeof(string),"Vehicle registered to %s",CarInfo[newcar][cOwner]);
SendClientMessage(playerid, COLOR_BLUE, string);
if(PlayerInfo[playerid][pPcarkey] == vehicle) { }
else if(PlayerInfo[playerid][pPcarkey2] == vehicle) { }
else if(PlayerInfo[playerid][pPcarkey3] == vehicle) { }
else
{
if(IsPlayerAdmin(playerid))
{
SendClientMessage(playerid, COLOR_GREY, " You can drive this car because you are admin");
}
else
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_GREY, "You don't have a key of this vehicle");
}
}
}
}
}
return 1;
}
stock ini_GetKey( line[] )
{
new keyRes[256];
keyRes[0] = 0;
if ( strfind( line , "=" , true ) == -1 ) return keyRes;
strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
return keyRes;
}
stock ini_GetValue( line[] )
{
new valRes[256];
valRes[0]=0;
if ( strfind( line , "=" , true ) == -1 ) return valRes;
strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
return valRes;
}