Need help with team vehicle system
#1

So i trying to make a team restricted system but the issue is how can i check if the player enters the vehicle without have to checking each team car because most the tutorials i see they want you to check every single vehicle hence leading to me doing unecessary work.. Now how can i check is the player enter a scar they will be kicked if thats not there team without have to keep on repeating codes

PHP код:
new scar[20];
//the vehicles
    
scar[0] = CreateVehicle(4702159.5352, -2279.865513.1922222.9741141141100);
    
scar[1] = CreateVehicle(4702166.4790, -2273.044913.1922224.5838141141100);
     
scar[2] = CreateVehicle(4702174.0854, -2265.693613.1922224.5838141141100);
    
scar[3] = CreateVehicle(4702237.4893, -2247.791713.297845.3764141141100);
    
scar[4] = CreateVehicle(4702229.9790, -2255.578413.297845.3764141141100);
    
scar[5] = CreateVehicle(4702222.5234, -2263.200213.297845.3764141141100);
    
scar[6] = CreateVehicle(4702215.3928, -2270.164313.297845.3764141141100);
    
scar[7] = CreateVehicle(4702207.9883, -2277.562713.297845.3764141141100);
    
scar[8] = CreateVehicle(4902196.7639, -2291.212913.661615.1807141141100);
    
scar[9] = CreateVehicle(4902193.0151, -2295.070813.661615.1807141141100);
    
scar[10] = CreateVehicle(4472176.6189, -2317.964413.6553316.7903141141100);
    
scar[11] = CreateVehicle(4472161.3711, -2322.825413.6553316.7903141141100);
    
scar[12] = CreateVehicle(4902189.3809, -2298.630113.661615.1807141141100);
    
scar[13] = CreateVehicle(4272209.8640, -2214.168713.5594222.1982141141100);
    
scar[14] = CreateVehicle(4272203.3384, -2220.550013.5594222.7510141141100);
    
scar[15] = CreateVehicle(4972173.8083, -2331.870413.7229316.2585,141,141100); // solmav 1
    
scar[16] = CreateVehicle(4972245.7532, -2235.898213.723746.3665,141,141100); // solmav 2
    
scar[17] = CreateVehicle(5992185.7170, -2302.830813.737914.6924,141,141100); // solran 1
    
scar[18] = CreateVehicle(5992182.4343, -2306.825213.73968.7646,141,141100); // solran 2
    
scar[19] = CreateVehicle(5992193.9944, -2310.353514.3117133.8432,141,141100); // solran 3
    
scar[20] = CreateVehicle(5992153.3682, -2289.016113.5583222.1449,141,141100); // solran 4 
Reply
#2

You can use SetVehicleParamsForPlayer for all forbidden vehicles when the player chooses team to lock the vehicle, instead of everytime the player tries to enter a vehicle.

Other than that, to my knowledge; the only way to really do this without checking all of the vehicles is to distinguish unique features that the team vehicles have. This will really depend on how your gamemode is running.

For instance, if only team one can use vehicle model ID 400, then you could use GetVehicleModel to detect whether they are entering a forbidden vehicle and eject them.

Alternatively, you could also possibly use SetVehicleParamsEx to assign a unique feature then use GetVehicleParamsEx to check what team the vehicle belongs to. [For example, the alarm parameter could be used for team one, whislt the objective parameter could be used for team two] I wouldn't really recommend this though as it could cause conflict if you are using these functions for other purposes.
Reply
#3

There are two simple ways on that

OnPlayerEnterVehicle

and OnPlayerStateChange

I only can give OnPlayerEnterVehicle example
i.e

now since you have already have that scar[MAX_SCAR] if that's how that variable is made, I'll go with my idea of how it's made

first you make this piece of function
PHP код:
stock IsScar(carid//check if the car is a scar vehicle
{
    for(new 
0sizeof(Scar); v++) {
        if(
carid == Scar[v]) return 1;
    }
    return 
0;
}

public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(!
ispassenger//check if the player is not a passenger
    
{
        
SetPlayerArmedWeapon(playerid0);

           if(
IsScar(vehicleid)) 
           {
               if(
Player[playerid][ScarOwner] != vehicleid//this would just be example for removing the player 
               
{
                
RemovePlayerFromVehicle(playerid);
                new 
Float:slxFloat:slyFloat:slz;
                
GetPlayerPos(playeridslxslyslz);
                
SetPlayerPos(playeridslxslyslz);
                
NOPCheck(playerid);
                
SendClientMessage(playeridCOLOR_GRAD2"You can't right this car");
            } 
//this way the player would be removed if he does not owned that scar vehicle
        
}// you can make it if the player is not the leader of the group the scar is supposed to be used they get ejected
    
}

this can be improved with much more security if you want so that not even a hacker can move this cars
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)