[Tutorial] Locking military vehicles on the server + AC! [simple]
#1

This will lock vehicles depending on their model ID's and also check, if the player is driving locked vehicle (hax). Alright, I'll explain each line on the line! Note: I'll be using YSI's command processor.

pawn Code:
new mLocked; //creating a variable to see, when vehicles are locked
new Text3D:vLock[MAX_VEHICLES]; //creating 3DText variable, so we can attach 3DText to vehicles and then delete it

CMD:lockm(playerid, params[]) //there will be just one cmd to lock and unlock the vehicles, acting as a toggle
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You're not an admin."); //checks if the player is (RCON) admin, if not returns with the message and stops the code from going further. Replace it with your own admin-check, if you're using admin system
    if(mlocked == 0) //checks if the 'mlocked' var is set to 0, if so...
    {
        for(new i = 0; i < MAX_VEHICLES; i++) //loops through all the vehicles
        {
            if(GetVehicleModel(i) == 425 || GetVehicleModel(i) == 520 || GetVehicleModel(i) == 432) //checks vehicle models and if its one of the three (hunter, rhino, hydra), then...
            {
                VehicleLock[i] = Create3DTextLabel("Vehicle is currently locked.", COLOR_RED, 0.0, 0.0, 0.0, 20.0, -1, 0); //creates 3DTextLabel for each of the specified vehicles
                Attach3DTextLabelToVehicle(VehicleLock[i], i, 0.0, 0.0, 0.4); //attaches the label to specified vehicles to let the player know that the vehicle is locked
                SetVehicleToRespawn(i); //respawns specified vehicles to avoid AC triggering for legit players
                for(new p = 0; p < MAX_PLAYERS; p++) //loops through all the players
                {
                    if(IsPlayerConnected(p)) //so it only checks connected slots!
                    {
                        SetVehicleParamsForPlayer(i, p, 0, 1); //set the specified vehicle params for all the connected players. '1' at the end is responsible for locking vehicles
                    }
                }
            }
        }
        mlocked = 1; //set the var to 1!
        SendClientMessage(playerid, COLOR_RED, "Military vehicles locked."); //sends you a message
        GameTextForAll("~r~Military vehicles locked", 5000, 3); //shows a game text for all players, so they know that vehicles are locked now!
    }
    else if(mlocked == 1) //now if type this command again, the 'mlocked' var will be set to 1, so... It does the same as above, but now unlocks the vehicles, deletes the 3D label, lets the players know the vehicles are now unlocked and sets 'mlocked' var back to 0, so next time to type this command, it will lock the vehicles!
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            if(GetVehicleModel(i) == 425 || GetVehicleModel(i) == 520 || GetVehicleModel(i) == 432)
            {
                Delete3DTextLabel(Text3D:VehicleLock[i]);
                for(new p = 0; p < MAX_PLAYERS; p++)
                {
                    if(IsPlayerConnected(p))
                    {
                        SetVehicleParamsForPlayer(i, p, 0, 0);
                    }
                }
            }
        }
        mlocked = 0;
        SendClientMessage(playerid, COLOR_GREEN, "Military vehicles unlocked.");
        GameTextForAll("~g~Military vehicles unlocked", 5000, 3);
    }
    return 1;
}
Now, as the locked param is getting reset OnVehicleStreamIn, you need to set it back:
pawn Code:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(mlocked == 1) //everytime a vehicle is stream in for the player it checks if the 'mlocked' var is set to '1' and if so, locks the specified vehicles.
    {
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            if(GetVehicleModel(i) == 425 || GetVehicleModel(i) == 520 || GetVehicleModel(i) == 432)
            {
                SetVehicleParamsForPlayer(i, forplayerid, 0, 1);
            }
        }
    }
    return 1;
}
Now on the anticheat part, under OnPlayerUpdate callback, or you can make a repeative timer, if you wish:

pawn Code:
new time = gettime();
if(lastUpdate[playerid] < time)
{
    lastUpdate[playerid] = time; //this and the lines above are so it doesn't check more often than every 1 second
    vehID = GetPlayerVehicleID(playerid); //this gets vehicle ID player is currently driving or sitting in as a passenger from his ID
    if(mlocked == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //checks if the 'mlocked' var is set to '1' (that means vehicles are locked currently), and if the player is driving a vehicle...
        {
            if(GetVehicleModel(vehID) == 425 || GetVehicleModel(vehID) == 520 || GetVehicleModel(vehID) == 432) //checks if he's driving any of the locked vehicles
            {
                BanEx(playerid, "Vehicle unlock hacks."); / /bans the cheator!
            }
        }
}
That's it!
Reply
#2

Interesting,but explain more next time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)