Team vehicles - What's wrong? -
needhack - 23.02.2013
I basically want the police team to be able to drive PD cars, the EMS to be able to drive ambulances, and if they try to enter the vehicle of another faction, they get ejected.
I haven't been able to find an error in my script, can anyone help me?
This is the script:
pawn Код:
#include <a_samp>
#define POLICE 1
#define EMS 2
#define POLICE_COLOR 0x1B4CE0AA
#define EMS_COLOR 0xFF8AF5AA
#define COLOR_RED 0xFF0000AA
enum TeamCars
{
Police,
Ems
}
new Cars[TeamCars];
new gTeam[MAX_PLAYERS];
public OnGameModeInit()
{
AddPlayerClass(282,-212.8113,979.4888,19.3295,265.9427,0,0,0,0,0,0); //POLICE
AddPlayerClass(275,-321.5634,1055.6372,19.7422,0.2632,0,0,0,0,0,0); //EMS
Cars[Police] = AddStaticVehicle(598,-210.8453,999.8466,19.3565,88.9803,0,1); // FCpolice1
Cars[Police] = AddStaticVehicle(598,-210.8381,995.6052,19.2733,88.3708,0,1); // FCpolice2
Cars[Police] = AddStaticVehicle(598,-210.9035,990.9142,19.1776,87.8309,0,1); // FCpolice3
Cars[Police] = AddStaticVehicle(598,-211.0338,986.5652,19.0902,88.7393,0,1); // FCpolice4
Cars[Police] = AddStaticVehicle(599,-228.7683,984.3557,19.7830,359.9276,0,1); // FCpolice5
Cars[Ems] = AddStaticVehicle(416,-330.7315,1063.7899,19.8899,270.1239,1,3); // FCems1
Cars[Ems] = AddStaticVehicle(416,-335.0536,1056.3861,19.8883,89.4939,1,3); // FCems2
Cars[Ems] = AddStaticVehicle(416,-304.0838,1036.2386,19.7430,269.8071,1,3); // FCems3
Cars[Ems] = AddStaticVehicle(416,-303.8831,1032.0743,19.7432,269.9365,1,3); // FCems4
Cars[Ems]= AddStaticVehicle(416,-304.0561,1028.1265,19.7430,270.0614,1,3); // FCems5
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if(GetPlayerSkin(playerid) == 282) GameTextForPlayer(playerid,"~b~Police",7500,6);
if(GetPlayerSkin(playerid) == 275) GameTextForPlayer(playerid,"~p~Emergency Services",7500,6);
SetPlayerTeamFromClass(playerid, classid);
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerToTeamColour(playerid);
return 1;
}
SetPlayerTeamFromClass(playerid, classid)
{
if(classid == 0)
{
gTeam[playerid] = POLICE;
}
{
if(classid == 1)
gTeam[playerid] = EMS;
}
}
SetPlayerToTeamColour(playerid)
{
if(gTeam[playerid] == POLICE)
{
SetPlayerColor(playerid,POLICE_COLOR); //BLUE
}
{
if(gTeam[playerid] == EMS)
SetPlayerColor(playerid,EMS_COLOR); // PINK
}
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 2)
{
new CarCheck = GetPlayerVehicleID(playerid);
if(CarCheck == Cars[Police] )
{
if(gTeam[playerid] != 1)
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
return 1;
}
}
if(CarCheck == Cars[Ems] )
{
if(gTeam[playerid] != 0)
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
return 1;
}
}
return 1;
}
return 1;
}
OnPlayerStateChange is where the magic is supposed to happen..
Need help fast, can't continue :/
Re: Team vehicles - What's wrong? -
Alternative112 - 23.02.2013
Well first it looks like you're constantly overwriting the value of Cars[Police] in your OnGameModeInit, so the only time the ejection will happen is if it's with your FCPolice5 car and your FCems5 car.
Why not do something like this?
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 2) {
if(GetPlayerVehicleID(playerid) == 598 || GetPlayerVehicleID(playerid) == 599) //Police car model
{
if(gTeam[playerid] != 1)
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
return 1;
}
}
else if(GetPlayerVehicleID(playerid) == 416) //Ambulance
{
if(gTeam[playerid] != 0)
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
return 1;
}
}
return 1;
}
return 1;
}
Doing it this way wouldn't require you to check each and every vehicleid that you make.
AW: Re: Team vehicles - What's wrong? -
Nero_3D - 23.02.2013
He probably meant to use GetVehicleModel
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate) {
if(newstate == PLAYER_STATE_DRIVER) {
new
vehicleid = GetPlayerVehicleID(playerid),
modelid = GetVehicleModel(vehicleid)
;
switch(modelid) {
case 598, 599: { // Police vehicle
if(gTeam[playerid] != POLICE) { // Use your definitions if you already got them
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
}
}
case 416: { // Ems vehicle
if(gTeam[playerid] != EMS) { // Because EMS is 2 and not 0!
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, COLOR_RED, "You don't belong to the correct faction.");
}
}
}
}
return true;
}
Although I dont know which tutorial you read but I know that their are many bad tutoirals
Re: Team vehicles - What's wrong? -
needhack - 23.02.2013
Tried both codes, Nero's helped and works.
Once again thanks!
Just asking, if you don't mind, could you explain why you changed the way of scripting like you did above? Since some of the functions are unfamiliar to me.
AW: Team vehicles - What's wrong? -
Nero_3D - 23.02.2013
I just changed the ifs into a
switch, everything else should be clear
Re: Team vehicles - What's wrong? -
needhack - 23.02.2013
Never mind, fixed.