SA-MP Forums Archive
Team vehicles help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Team vehicles help (/showthread.php?tid=630917)



Team vehicles help - Zmith - 20.03.2017

https://sampforum.blast.hk/showthread.php?tid=160810

I tried this, added it to my gamemode and compiled without any errors. However when I tried to test the script ingame, it simply didn't work. I tried all different methods but the find any errors to begin a bug fix.


Any idea why?

Код:
#define GANG_CIV 0
#define GANG_US 1
#define GANG_T 2
#define GANG_PMC 3
#define GANG_UK 4

enum TeamVehs
{
USveh,
UKveh,
Taliveh,
PMCveh
}

new gTeam[MAX_PLAYERS];
new Veh[TeamVehs];





public OnGameModeInit()
{
	 AddStaticVehicle(543,-741.3320,2750.9011,47.0458,181.2065,255,255); // Sadler (CIV)		
	 Veh[Taliveh] = AddStaticVehicle(455,-1453.3641,2624.9502,56.2726,270.7139,255,255); // Flatbed (Tali)
	 Veh[PMCveh] = AddStaticVehicle(487,-655.3591,949.7514,12.2784,93.0401,33,33); // Maverick (PMC)	 	
	 Veh[USveh] = AddStaticVehicle(548,328.1077,1850.7454,19.1915,90.0070,81,81); // Cargobob (US)
	 Veh[UKveh] = AddStaticVehicle(520,-1457.0353,501.5562,18.9917,269.4383,0,0); // Hydra (UK)	
		
	 return 1;
}


public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
      	new VehCheck = GetPlayerVehicleID(playerid);
    	if(VehCheck == Veh[USveh] )
        {
        	if(gTeam[playerid] == GANG_US)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
    	if(VehCheck == Veh[Taliveh] )
        {
        	if(gTeam[playerid] == GANG_T)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
    	if(VehCheck == Veh[PMCveh] )
        {
        	if(gTeam[playerid] == GANG_PMC)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
		if(VehCheck == Veh[UKveh] )
        {
			if(gTeam[playerid] == GANG_UK)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }
       	return 1;
    }
    return 1;
}



Re: Team vehicles help - Zmith - 20.03.2017

Update;

Okay, I found the error but I am still not sure how to fix it.

If I join "GANG_US" I cannot enter the last vehicle (I removed most vehicles so the above wasn't cluttered) added to "OnGameModeInit" defined "Veh[USveh]".

Example;
Код:
public OnGameModeInit()
{

	AddStaticVehicle(404,-240.3871,2609.1855,62.4385,178.8446,109,100); // ALL_CAN_ENTER
	AddStaticVehicle(408,-276.2446,2655.8201,63.1989,270.1121,26,26); // ALL_CAN_ENTER
	AddStaticVehicle(424,-215.7718,2777.6672,62.2502,269.3476,2,2); // ALL_CAN_ENTER
		

	Veh[Taliveh] = AddStaticVehicle(568,-1565.5852,2638.3340,55.6556,89.3129,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(470,-1563.2689,2694.5530,55.7585,179.6360,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(469,-1276.0333,2490.6409,86.9348,151.4670,1,1); // TALI_CANNOT_ENTER

	Veh[PMCveh] = AddStaticVehicle(473,-660.8072,875.4515,-0.2219,226.3900,33,33); // ALL_CAN_ENTER
	Veh[PMCveh] = AddStaticVehicle(468,-686.3440,973.6500,11.8031,29.6308,33,33); // ALL_CAN_ENTER
	Veh[PMCveh] = AddStaticVehicle(554,-681.0616,967.7052,12.2172,90.8313,33,33); //PMC_CANNOT_ENTER
		
	Veh[USveh] = AddStaticVehicle(523,146.8226,1930.8507,18.7541,90.4055,81,81); // ALL_CAN_ENTER
	Veh[USveh] = AddStaticVehicle(500,181.7266,1925.9727,18.0581,179.9284,81,81); // ALL_CAN_ENTER
	Veh[USveh] = AddStaticVehicle(470,176.9072,1925.9727,18.0926,179.9285,81,81); // US_CANNOT_ENTER


	Veh[UKveh] = AddStaticVehicle(445,-1561.7638,387.1261,7.0625,90.1433,0,0); // ALL_CAN_ENTER
	Veh[UKveh] = AddStaticVehicle(425,-1608.2104,286.0438,7.7102,180.6974,1,1); // ALL_CAN_ENTER
	Veh[UKveh] = AddStaticVehicle(430,-1653.0719,253.9239,-0.0595,91.4524,0,0); // UK_CANNOT_ENTER

		
	return 1;
}
Could you help me out?


Re: Team vehicles help - azzerking - 20.03.2017

Quote:
Originally Posted by Zmith
Посмотреть сообщение
Update;

Okay, I found the error but I am still not sure how to fix it.

If I join "GANG_US" I cannot enter the last vehicle (I removed most vehicles so the above wasn't cluttered) added to "OnGameModeInit" defined "Veh[USveh]".

Example;
Код:
public OnGameModeInit()
{

	AddStaticVehicle(404,-240.3871,2609.1855,62.4385,178.8446,109,100); // ALL_CAN_ENTER
	AddStaticVehicle(408,-276.2446,2655.8201,63.1989,270.1121,26,26); // ALL_CAN_ENTER
	AddStaticVehicle(424,-215.7718,2777.6672,62.2502,269.3476,2,2); // ALL_CAN_ENTER
		

	Veh[Taliveh] = AddStaticVehicle(568,-1565.5852,2638.3340,55.6556,89.3129,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(470,-1563.2689,2694.5530,55.7585,179.6360,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(469,-1276.0333,2490.6409,86.9348,151.4670,1,1); // TALI_CANNOT_ENTER

	Veh[PMCveh] = AddStaticVehicle(473,-660.8072,875.4515,-0.2219,226.3900,33,33); // ALL_CAN_ENTER
	Veh[PMCveh] = AddStaticVehicle(468,-686.3440,973.6500,11.8031,29.6308,33,33); // ALL_CAN_ENTER
	Veh[PMCveh] = AddStaticVehicle(554,-681.0616,967.7052,12.2172,90.8313,33,33); //PMC_CANNOT_ENTER
		
	Veh[USveh] = AddStaticVehicle(523,146.8226,1930.8507,18.7541,90.4055,81,81); // ALL_CAN_ENTER
	Veh[USveh] = AddStaticVehicle(500,181.7266,1925.9727,18.0581,179.9284,81,81); // ALL_CAN_ENTER
	Veh[USveh] = AddStaticVehicle(470,176.9072,1925.9727,18.0926,179.9285,81,81); // US_CANNOT_ENTER


	Veh[UKveh] = AddStaticVehicle(445,-1561.7638,387.1261,7.0625,90.1433,0,0); // ALL_CAN_ENTER
	Veh[UKveh] = AddStaticVehicle(425,-1608.2104,286.0438,7.7102,180.6974,1,1); // ALL_CAN_ENTER
	Veh[UKveh] = AddStaticVehicle(430,-1653.0719,253.9239,-0.0595,91.4524,0,0); // UK_CANNOT_ENTER

		
	return 1;
}
Could you help me out?
This is because your checking if the player is in the correct team and if they are in the correct team you are kicking them from vehicle. So your actually doing the reverse of what you want.

OnPlayerStateChange
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        new VehCheck = GetPlayerVehicleID(playerid);
        if(VehCheck == Veh[USveh] )
        {
            if(gTeam[playerid] != GANG_US)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }

        if(VehCheck == Veh[Taliveh] )
        {
            if(gTeam[playerid] != GANG_T)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }

        if(VehCheck == Veh[PMCveh] )
        {
            if(gTeam[playerid] != GANG_PMC)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }

        if(VehCheck == Veh[UKveh] )
        {
            if(gTeam[playerid] != GANG_UK)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }
    }

    return 1;
}
What did I do? All I did was add a exclamation mark instead of two equals signs, in programming this mean the oppersite of equals so to do '!=' I am saying if 'blah' is not 'blah' then execute.


Re: Team vehicles help - Zmith - 20.03.2017

Alright, thank you. I'm still having trouble with the script though because there are more than one vehicle per team. I tried this, I had no errors, yet the script still doesn't work :/

You are allowed to enter all vehicles regardless of which team you are, it doesn't make sense, to me anyway.


Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 4)
    {
      	new VehCheck = GetPlayerVehicleID(playerid);
    	if(VehCheck == Veh[USveh1] || VehCheck == Veh[USveh2] || VehCheck == Veh[USveh3] || VehCheck == Veh[USveh4] || VehCheck == Veh[USveh5] || VehCheck == Veh[USveh6] || VehCheck == Veh[USveh7] || VehCheck == Veh[USveh8] || VehCheck == Veh[USveh9] || VehCheck == Veh[USveh10] || VehCheck == Veh[USveh11] || VehCheck == Veh[USveh12] || VehCheck == Veh[USveh13] || VehCheck == Veh[USveh14] || VehCheck == Veh[USveh15] )
        {
        	if(gTeam[playerid] != GANG_US)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
    	if(VehCheck == Veh[Taliveh1] || VehCheck == Veh[Taliveh2] || VehCheck == Veh[Taliveh3] || VehCheck == Veh[Taliveh4] || VehCheck == Veh[Taliveh5] || VehCheck == Veh[Taliveh6] || VehCheck == Veh[Taliveh7] || VehCheck == Veh[Taliveh8] || VehCheck == Veh[Taliveh9] || VehCheck == Veh[Taliveh10])
        {
        	if(gTeam[playerid] != GANG_T)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
    	if(VehCheck == Veh[PMCveh1] || VehCheck == Veh[PMCveh2] || VehCheck == Veh[PMCveh3] || VehCheck == Veh[PMCveh4]|| VehCheck == Veh[PMCveh5] || VehCheck == Veh[PMCveh6] || VehCheck == Veh[PMCveh7] || VehCheck == Veh[PMCveh8] || VehCheck == Veh[PMCveh9] )
        {
        	if(gTeam[playerid] != GANG_PMC)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
            	return 1;
			}
		}
		if(VehCheck == Veh[UKveh1] || VehCheck == Veh[UKveh2] || VehCheck == Veh[UKveh3] || VehCheck == Veh[UKveh4] || VehCheck == Veh[UKveh5] || VehCheck == Veh[UKveh6] || VehCheck == Veh[UKveh7] || VehCheck == Veh[UKveh8] || VehCheck == Veh[UKveh9] || VehCheck == Veh[UKveh10] || VehCheck == Veh[UKveh11] || VehCheck == Veh[UKveh12] || VehCheck == Veh[UKveh13] || VehCheck == Veh[UKveh14] || VehCheck == Veh[UKveh15] || VehCheck == Veh[UKveh16] || VehCheck == Veh[UKveh17])
        {
			if(gTeam[playerid] != GANG_UK)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: You don't have access to this vehicle!");
                return 1;
            }
        }
       	return 1;
    }
    return 1;
}



Re: Team vehicles help - Sew_Sumi - 20.03.2017

Rather than hardcoding state 4, you could use DRIVER. You may want to check if they are PASSENGER as well. Otherwise an enemy team member could get into the vehicle as passenger.

As for the team per vehicle issue, you should use an array/enum to track what team that vehicle is assigned to, so when you check, you're not having to check what vehicle they are in, you simply check it's team versus the players team.

The reason this was doing what it was doing is...

Код:
	Veh[Taliveh] = AddStaticVehicle(568,-1565.5852,2638.3340,55.6556,89.3129,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(470,-1563.2689,2694.5530,55.7585,179.6360,1,1); // ALL_CAN_ENTER
	Veh[Taliveh] = AddStaticVehicle(469,-1276.0333,2490.6409,86.9348,151.4670,1,1); // TALI_CANNOT_ENTER
You're reassigning Veh[Taliveh] each time you are doing this... They don't stack, it is one variable.

So the first 2 weren't being Veh[Taliveh] by the time the third one had it assigned.