02.03.2011, 22:03
pawn Код:
#include <a_samp>
#include <dini>
#include <dudb>
#include <zcmd>
#include <sscanf2>
#pragma unused ret_memcpy
#define ACCOUNTS_FILE "Accounts/%s.ini"
#define HOUSES_FILE "Houses/%d.ini"
#define VEHICLES_FILE "Vehicles/%d.ini"
#define SystemMSG 0xFFFF00FF
#define MAX_HOUSES 201
forward UpdateHouseInfo();
new Vehicles[MAX_VEHICLES];
enum VInfo
{
VehicleID,
vModel,
Float:vX,
Float:vY,
Float:vZ,
Float:vA,
vColor1,
vColor2,
bool:vOwned,
vOwner[MAX_PLAYER_NAME],
vPrice,
vRentable,
vRent,
}
enum HInfo
{
Float:hEnterX,
Float:hEnterY,
Float:hEnterZ,
Float:hExitX,
Float:hExitY,
Float:hExitZ,
hInsideInt,
hInsideVir,
hOutsideInt,
hOutsideVir,
bool:hOwned,
hOwner[MAX_PLAYER_NAME],
hPrice,
hPickup,
hIcon,
}
new VehicleInfo[MAX_VEHICLES][VInfo];
new HouseInfo[MAX_HOUSES][HInfo];
public OnGameModeInit()
{
SetTimer("UpdateHouseInfo", 1000, true);
}
stock LoadVehicles(vehicleid)
{
new string[10];
format(string, 10, VEHICLES_FILE, vehicleid);
if(!dini_Exists(string)) return 0;
VehicleInfo[vehicleid][VehicleID] = dini_Int(string, "ID");
VehicleInfo[vehicleid][vModel] = dini_Int(string, "Model");
VehicleInfo[vehicleid][vX] = dini_Float(string, "LastX");
VehicleInfo[vehicleid][vY] = dini_Float(string, "LastY");
VehicleInfo[vehicleid][vZ] = dini_Float(string, "LastZ");
VehicleInfo[vehicleid][vA] = dini_Float(string, "LastA");
VehicleInfo[vehicleid][vColor1] = dini_Int(string, "Color1");
VehicleInfo[vehicleid][vColor2] = dini_Int(string, "Color2");
VehicleInfo[vehicleid][vOwned] = dini_Bool(string, "Owned") ? true : false;
strmid(VehicleInfo[vehicleid][vOwner], dini_Get(string, "Owner"), 0, false, strlen(dini_Get("Owner")));
VehicleInfo[vehicleid][vPrice] = dini_Int(string, "Price");
VehicleInfo[vehicleid][vRentable] = dini_Int(string, "Rentable");
VehicleInfo[vehicleid][vRent] = dini_Int(string, "RentPrice");
}
stock LoadHouse(houseid)
{
new string[10];
format(string, 10, HOUSES_FILE, houseid);
if(!dini_Exists(string)) return 0;
HouseInfo[houseid][hEnterX] = dini_Float(string, "EnterX");
HouseInfo[houseid][hEnterY] = dini_Float(string, "EnterY");
HouseInfo[houseid][hEnterZ] = dini_Float(string, "EnterZ");
HouseInfo[houseid][hExitX] = dini_Float(string, "ExitX");
HouseInfo[houseid][hExitY] = dini_Float(string, "ExitY");
HouseInfo[houseid][hExitZ] = dini_Float(string, "ExitZ");
HouseInfo[houseid][hInsideInt] = dini_Int(string, "InsideInterior");
HouseInfo[houseid][hInsideVir] = dini_Int(string, "InsideWorld");
HouseInfo[houseid][hOutsideInt] = dini_Int(string, "OutsideInterior");
HouseInfo[houseid][hOUtsideVir] = dini_Int(string, "OutsideWorld");
HouseInfo[houseid][hOwned] = dini_Bool(string, "Owned") ? true : false;
strmid(HouseInfo[houseid][hOwner], dini_Get(string, "Owner"), 0, false, strlen(dini_Get("Owner")));
HouseInfo[houseid][hPrice] = dini_Int(string, "Price");
return 1;
}
stock ReloadVehicles(vehicleid, bool:reload = false)
{
if(reload)
{
DestroyVehicle(VehicleInfo[VehicleID]);
if(IsValidVehicleModel(VehicleInfo[vehicleid][VehicleID]))
Vehicles[vehicleid] = CreateVehicle(VehicleInfo[vehicleid][vModel], VehicleInfo[vehicleid][vX], VehicleInfo[vehicleid][vY], VehicleInfo[vehicleid][vZ], VehicleInfo[vehicleid][vA], VehicleInfo[vehicleid][vColor1], VehicleInfo[vehicleid][vColor2], -1);
}
}
stock ReloadHouses(houseid, bool:reload = false)
{
if(reload)
{
DestroyDynamicMapIcon(HouseInfo[houseid][hIcon]);
DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
if(!HouseInfo[houseid][hOwned])
{
HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
}
else
{
HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
}
}
}
stock SaveVehicle(vehicleid)
{
new string[10];
format(string, 10, VEHICLES_FILE, vehicleid);
dini_IntSet(string, "ID", VehicleInfo[vehicleid][VehicleID]);
dini_IntSet(string, "Model", VehicleInfo[vehicleid][vModel]);
dini_FloatSet(string, "LastX", VehicleInfo[vehicleid][vX]);
dini_FloatSet(string, "LastY", VehicleInfo[vehicleid][vY]);
dini_FloatSet(string, "LastZ", VehicleInfo[vehicleid][vZ]);
dini_FloatSet(string, "LastA", VehicleInfo[vehicleid][vA]);
dini_IntSet(string, "Color1", VehicleInfo[vehicleid][vColor1]);
dini_IntSet(string, "Color2", VehicleInfo[vehicleid][vColor2]);
dini_BoolSet(string, "Owned", VehicleInfo[vehicleid][vOwned]);
dini_Set(string, "Owner", VehicleInfo[vehicleid][vOwner]);
dini_IntSet(string, "Price", VehicleInfo[vehicleid][vPrice]);
dini_IntSet(string, "Rentable", VehicleInfo[vehicleid][vRentable]);
dini_IntSet(string, "RentPrice", VehicleInfo[vehicleid][vRent]);
}
stock SaveHouse(houseid)
{
new string[10];
format(string, 10, HOUSES_FILE, houseid);
dini_FloatSet(string, "EnterX", HouseInfo[houseid][hEnterX]);
dini_FloatSet(string, "EnterY", HouseInfo[houseid][hEnterY]);
dini_FloatSet(string, "EnterZ", HouseInfo[houseid][hEnterZ]);
dini_FloatSet(string, "ExitX", HouseInfo[houseid][hExitX]);
dini_FloatSet(string, "ExitY", HouseInfo[houseid][hExitY]);
dini_FloatSet(string, "ExitZ", HouseInfo[houseid][hExitZ]);
dini_IntSet(string, "InsideInterior", HouseInfo[houseid][hInsideInt]);
dini_IntSet(string, "InsideWorld", HouseInfo[houseid][hInsideVir]);
dini_IntSet(string, "OutsideInterior", HouseInfo[houseid][hOutsideInt]);
dini_IntSet(string, "OutsideWorld", HouseInfo[houseid][hOutsideVir]);
dini_BoolSet(string, "Owned", HouseInfo[houseid][hOwned]);
dini_Set(string, "Owner", HouseInfo[houseid][hOwner]);
dini_IntSet(string, "Price", HouseInfo[houseid][hPrice]);
}
stock IsValidVehicleModel(vehiclemodel)
{
if(vehiclemodel >= 400 && vehiclemodel <= 611)
return true;
return false;
}
public UpdateHouseInfo()
{
new str[100];
for(new i = 0; i < MAX_PLAYERS; i++)
{
for(new j = 0; j < MAX_HOUSES; j++)
{
if(IsPlayerInRangeOfPoint(i, 1.5, HouseInfo[j][hEnterX], HouseInfo[j][hEnterY], HouseInfo[j][hEnterZ]) && GetPlayerInterior(i) == HouseInfo[j][hOutsideInt] && GetPlayerVirtualWorld(i) == HouseInfo[j][hOutsideVir])
{
if(HouseInfo[j][hOwned])
{
format(str, 100, "~w~House owned by ~r~%s", HouseInfo[j][hOwner]);
}
else
{
format(str, 100, "~w~House for sale!~n~Price: ~g~$%d,-", HouseInfo[j][hPrice]);
}
GameTextForPlayer(i, str, 3000, 3);
}
}
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid))
{
for(new i = 0; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir]) //Is player near house entrance, and if player is in interior of that house + virtual world
{
SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
SetPlayerInterior(playerid, HouseInfo[i][hInsideInt]);
SetPlayerVirtualWorld(playerid, HouseInfo[i][hInsideVir]);
}
else if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hInsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hInsideVir]) //Same as the previous IsPlayerInRangeOfPoint, but now if the player is near the house exit+int+vir
{
SetPlayerPos(playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]);
SetPlayerInterior(playerid, HouseInfo[i][hOutsideInt]);
SetPlayerVirtualWorld(playerid, HouseInfo[i][hOutsideVir]);
}
}
}
return 1;
}
COMMAND:spawncar(playerid, params[])
{
new vModelID;
if(sscanf(params, "d", vModelID)) return SendClientMessage(playerid, SystemMSG, "[VEHICLE]: /spawncar [vehicleid]");
{
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), ACCOUNTS_FILE, name);
if(dini_Int(file, "AdminLevel") >= 1)
{
if(vModelID < 400 || vModelID > 611)
{
SendClientMessage(playerid, SystemMSG, "[VEHICLE]: Valid car IDs start from 400 and end at 611.");
return 1;
}
else
{
new string[128], Float:VX, Float:VY, Float:VZ, Float:VA, AdminSpawnedCar;
GetPlayerPos(playerid, VX, VY, VZ);
GetPlayerFacingAngle(playerid, VA);
AdminSpawnedCar = CreateVehicle(vModelID, VX, VY, VZ+3, VA, -1, -1, -1);
PutPlayerInVehicle(playerid, AdminSpawnedCar, 0);
LinkVehicleToInterior(AdminSpawnedCar, GetPlayerInterior(playerid));
SetVehicleVirtualWorld(AdminSpawnedCar, GetPlayerVirtualWorld(playerid));
format(string, sizeof(string), "You have spawned model ID %d.", vModelID);
SendClientMessage(playerid, SystemMSG, string);
}
}
}
return 1;
}
COMMAND:savecar(playerid, params[])
{
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), ACCOUNTS_FILE, name);
if(dini_Int(file, "AdminLevel") >= 1)
{
if(!IsPlayerInAnyVehicle(playerid))
{
SendClientMessage(playerid, SystemMSG, "[VEHICLE]: You're not in a vehicle, use /spawncar [400-611].");
return 1;
}
else
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
new string[10];
format(string, 10, VEHICLES_FILE, i);
new AdminSpawnedCar, Float:VX, Float:VY, Float:VZ, Float:VA, vModelID;
AdminSpawnedCar = GetPlayerVehicleID(playerid);
GetVehiclePos(AdminSpawnedCar,VX,VY,VZ);
GetVehicleZAngle(AdminSpawnedCar,VA);
vModelID = GetVehicleModel(AdminSpawnedCar);
RepairVehicle(AdminSpawnedCar);
dini_IntSet(string, "ID", i);
dini_IntSet(string, "Model", vModelID);
dini_FloatSet(string, "LastX", VX);
dini_FloatSet(string, "LastY", VY);
dini_FloatSet(string, "LastZ", VZ);
dini_FloatSet(string, "LastA", VA);
dini_IntSet(string, "Color1", -1);
dini_IntSet(string, "Color2", -1);
dini_BoolSet(string, "Owned", false);
dini_Set(string, "Owner", "Nobody");
dini_IntSet(string, "Price", 0);
dini_IntSet(string, "Rentable", 0);
dini_IntSet(string, "RentPrice", 0);
SendClientMessage(playerid, SystemMSG, "[VEHICLE]: This vehicle has been saved!");
}
}
}
return 1;
}
COMMAND:buyhouse(playerid, params[])
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
{
if(HouseInfo[i][hOwned]) return SendClientMessage(playerid, SystemMSG, "This house is already owned!");
if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, SystemMSG, "[HOUSE]: You don't have enough money for this!");
HouseInfo[i][hOwned] = true;
strmid(HouseInfo[i][hOwner], pName, 0, false, strlen(pName));
GivePlayerMoney(playerid, -HouseInfo[i][hPrice]);
SendClientMessage(playerid, SystemMSG, "[HOUSE]: House bought!");
SaveHouse(i);
ReloadHouses(i, true);
return 1;
}
}
return 1;
}
COMMAND:sellhouse(playerid, params[])
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
for(new i = 0; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
{
if(!strcmp(HouseInfo[i][hOwner], pName, false))
{
strmid(HouseInfo[i][hOwner], "For Sale", 0, false, 8);
HouseInfo[i][hOwned] = false;
GivePlayerMoney(playerid, HouseInfo[i][hPrice]/2);
SendClientMessage(playerid, SystemMSG, "House sold!");
SaveHouse(i);
ReloadHouses(i, true);
return 1;
}
}
}
return 1;
}
Now, this doesn't work, if I go in-game I can spawn the cars /spawncar, but when I type /savecar, it spams the shit outta me with the message. Then when I exit the game, restart the server, then log back in to see if it works... There are no cars where I saved them... So I looked in the script files to see if it saved the car, it didn't. So I tried manually adding the car in the script files and still when I reload the server and log in the cars arn't there... please help me.