15.01.2011, 22:08
I'm trying to create a car ownership system. I want to when a player spawns and he owns a car to get the car spawned and to get the vehicleid of that car and to assign it to only one player (so when other player who is not an owner of that car gets kicked out from the car). I tried to make it but when an owner of the car enters in his own car he doesn't get a message saying "Welcome to your car
" and when other player who is not an owner of that car he doesn't get kicked out. I think it's something wrong with my variable (or whatever the name of it is).
Here's the code:
This is just a test script, there's only one car file named "2.json". I want to figure it out before making a real script. Thanks in advance.
" and when other player who is not an owner of that car he doesn't get kicked out. I think it's something wrong with my variable (or whatever the name of it is).Here's the code:
pawn Код:
#include <a_samp>
#include <zcmd>
#include <djson>
#define OWNED_CARS_COUNT 5
#define PLAYER_PATH "users/%s.json"
new OWNED_CARS = 1;
new pPlayerCarOwned[MAX_PLAYERS] = 0;
new playercar[MAX_PLAYERS];
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
djson_GameModeInit();
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
djson_GameModeExit();
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
new playername[MAX_PLAYERS], file[50], file2[50];
GetPlayerName(playerid, playername, sizeof(playername));
format(file, sizeof(file), "vehicles/%d.json", 2);
format(file2, sizeof(file2), "users/%s.json", playername);
if(djInt(file2, "vehicle/ID") == 2)
{
playercar[playerid] = CreateVehicle(451, djFloat(file, "vehicle/x"), djFloat(file, "vehicle/y"), djFloat(file, "vehicle/z"),90,5,7,5000);
}
}
public OnPlayerDisconnect(playerid, reason)
{
playercar[playerid] = 12345;
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetPlayerVehicleID(playerid) == playercar[playerid])
{
SendClientMessage(playerid, 0xffffff, "Welcome to your CAR :D");
}
else
{
RemovePlayerFromVehicle(playerid);
}
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
pPlayerCarOwned[playerid] = 0;
return 1;
}


