vehicle slip problem

Started by byendofday, Jan 30, 2026, 02:48 PM

Previous topic - Next topic

byendofday

i want a script  it can creat a temporary car. when car bomb it will not spawned. And pre player have create car restrict   how can i modify my scrip and suggustion   

lamkotien

Quote from: byendofday on Jan 30, 2026, 02:48 PMi want a script  it can creat a temporary car. when car bomb it will not spawned. And pre player have create car restrict  how can i modify my scrip and suggustion 
Please refer to my code; the logic works as follows:
When summoning a vehicle, if it explodes or falls into the water, the remains of it will be hidden in another world. After one second, the vehicle that exploded or fell into the river will be permanently deleted.
// --- SAMPLE COMMAND: /getcar [ModelID OR Vehicle Name] ---
// Example: /getcar 141 OR /getcar infernus
function onPlayerCommand(player, command, arguments) {
    local cmd = command.tolower();
    if (cmd == "getcar" || cmd == "gc") {
        if (!arguments) return MessagePlayer(">> Usage: /getcar [ID/Vehicle Name]", player);

        local input = arguments;
        local modelID = -1;

        // 1. Try to convert input to integer (Model ID)
        try {
            // If arguments is a raw string, we might need to split it
            local spaceIdx = input.find(" ");
            if (spaceIdx != null) input = input.slice(0, spaceIdx);

            modelID = input.tointeger();
        } catch (e) {
            modelID = -1;
        }

        // 2. If not a number, search by Name (Vehicle Names)
        if (modelID == -1) {
            local inputLower = input.tolower();
            foreach(id, name in VehicleNames) {
                if (name.tolower().find(inputLower) != null) {
                    modelID = id;
                    break; // Get the first match
                }
            }
        }

        // 3. Create vehicle if ID is valid
        if (modelID > 0) {
            // Create vehicle 3m in front of the player
            local pos = player.Pos;
            local angle = player.Angle;
            pos.X += 3.0 * sin(-angle);
            pos.Y += 3.0 * cos(-angle);
            pos.Z += 0.5;

            local v = CreateVehicle(modelID, pos, angle, -1, -1);
            if (v) {
                VehiclesToDelete.push(v.ID); // IMPORTANT: Add ID to the deletion list
                MessagePlayer(">> Created temporary vehicle: " + GetVehicleName(modelID) + " (ID: " + v.ID + ")", player);
            } else {
                MessagePlayer(">> Error: Could not create vehicle (Invalid Model).", player);
            }
        } else {
            MessagePlayer(">> No vehicle found with name/id: " + arguments, player);
        }
        return 1;
    }
    return 0;
}

// Helper: Get vehicle name from ID
function GetVehicleName(modelId) {
    if (modelId in VehicleNames) return VehicleNames[modelId];
    return "Unknown";
}

// DATA: Vehicle Names List
VehicleNames <- {
    [130] = "Landstalker",
    [131] = "Idaho",
    [132] = "Stinger",
    [133] = "Linerunner",
    [134] = "Perennial",
    [135] = "Sentinel",
    [136] = "Rio",
    [137] = "Firetruck",
    [138] = "Trashmaster",
    [139] = "Stretch",
    [140] = "Manana",
    [141] = "Infernus",
    [142] = "Voodoo",
    [143] = "Pony",
    [144] = "Mule",
    [145] = "Cheetah",
    [146] = "Ambulance",
    [147] = "FBI Washington",
    [148] = "Moonbeam",
    [149] = "Esperanto",
    [150] = "Taxi",
    [151] = "Washington",
    [152] = "Bobcat",
    [153] = "Mr. Whoopee",
    [154] = "BF Injection",
    [155] = "Hunter",
    [156] = "Police",
    [157] = "Enforcer",
    [158] = "Securicar",
    [159] = "Banshee",
    [160] = "Predator",
    [161] = "Bus",
    [162] = "Rhino",
    [163] = "Barracks OL",
    [164] = "Cuban Hermes",
    [165] = "Helicopter",
    [166] = "Angel",
    [167] = "Coach",
    [168] = "Cabbie",
    [169] = "Stallion",
    [170] = "Rumpo",
    [171] = "RC Bandit",
    [172] = "Romero's Hearse",
    [173] = "Packer",
    [174] = "Sentinel XS",
    [175] = "Admiral",
    [176] = "Squalo",
    [177] = "Sea Sparrow",
    [178] = "Pizzaboy",
    [179] = "Gang Burrito",
    [180] = "Airtrain",
    [181] = "Deadeye",
    [182] = "Speeder",
    [183] = "Reefer",
    [184] = "Tropic",
    [185] = "Flatbed",
    [186] = "Yankee",
    [187] = "Caddy",
    [188] = "Zebra Cab",
    [189] = "Top Fun",
    [190] = "Skimmer",
    [191] = "PCJ-600",
    [192] = "Faggio",
    [193] = "Freeway",
    [194] = "RC Baron",
    [195] = "RC Raider",
    [196] = "Glendale",
    [197] = "Oceanic",
    [198] = "Sanchez",
    [199] = "Sparrow",
    [200] = "Patriot",
    [201] = "Love Fist",
    [202] = "Coast Guard",
    [203] = "Dinghy",
    [204] = "Hermes",
    [205] = "Sabre",
    [206] = "Sabre Turbo",
    [207] = "Phoenix",
    [208] = "Walton",
    [209] = "Regina",
    [210] = "Comet",
    [211] = "Deluxo",
    [212] = "Burrito",
    [213] = "Spand Express",
    [214] = "Marquis",
    [215] = "Baggage Handler",
    [216] = "Kaufman Cab",
    [217] = "Maverick",
    [218] = "VCN Maverick",
    [219] = "Rancher",
    [220] = "FBI Rancher",
    [221] = "Virgo",
    [222] = "Greenwood",
    [223] = "Jetmax",
    [224] = "Hotring Racer",
    [225] = "Sandking",
    [226] = "Blista Compact",
    [227] = "Police Maverick",
    [228] = "Boxville",
    [229] = "Benson",
    [230] = "Mesa Grande",
    [231] = "RC Goblin",
    [232] = "Hotring Racer A",
    [233] = "Hotring Racer B",
    [234] = "Bloodring Banger A",
    [235] = "Bloodring Banger B",
    [236] = "Vice C. Cheeta"
};

// List of vehicles to delete on explode/respawn
VehiclesToDelete <- [];
VehiclesToHide <- {}; // ID -> timestamp (Time to hide vehicle after explosion - Optional)

// --- EVENT: VEHICLE EXPLODE ---
function onVehicleExplode(vehicle) {
    if (!vehicle) return;
    local id = vehicle.ID;

    // Check if vehicle is in the deletion list
    // (Or you can check by World ID, e.g., mission vehicles always have World > 1000)
    local isTemporaryVehicle = false;

    // Method 1: Check in array
    foreach(vID in VehiclesToDelete) {
        if (vID == id) {
            isTemporaryVehicle = true;
            break;
        }
    }

    // Method 2: Check World ID (If you define temporary vehicles having World > 1000)
    if (vehicle.World > 1000) isTemporaryVehicle = true;

    if (isTemporaryVehicle) {
        // Remove vehicle immediately
        vehicle.Remove();

        // Remove from management list
        for (local i = 0; i < VehiclesToDelete.len(); i++) {
            if (VehiclesToDelete[i] == id) {
                VehiclesToDelete.remove(i);
                break;
            }
        }

        print("[Vehicle Logic] Temporary vehicle (ID: " + id + ") removed due to explosion.");
    }
}

// --- EVENT: VEHICLE RESPAWN ---
// This event triggers when a vehicle falls into water or Idles for too long
function onVehicleRespawn(vehicle) {
    if (!vehicle) return;
    local id = vehicle.ID;

    // Similar logic to explode
    local isTemporaryVehicle = false;

    foreach(vID in VehiclesToDelete) {
        if (vID == id) {
            isTemporaryVehicle = true;
            break;
        }
    }
    if (vehicle.World > 1000) isTemporaryVehicle = true;

    if (isTemporaryVehicle) {
        // For Respawn, the vehicle might not be removed immediately if using Remove() directly in Event
        // So we use the "Hide -> Delete Later" process

        // 1. Hide the vehicle (Move to a far away virtual World)
        vehicle.World = id + 5000;

        // 2. Remove from VehiclesToDelete list to avoid re-processing
        for (local i = 0; i < VehiclesToDelete.len(); i++) {
            if (VehiclesToDelete[i] == id) {
                VehiclesToDelete.remove(i);
                break;
            }
        }

        // 3. Schedule delete after 1 second (via Timer or onFrame)
        // Here we use a simple Timer (simulated)
        NewTimer("ForceRemoveVehicle", 1000, 1, id);

        print("[Vehicle Logic] Temporary vehicle (ID: " + id + ") removed due to Respawn (Water/Idle).");
    }
}

// Function to force remove vehicle (Called by Timer)
function ForceRemoveVehicle(vID) {
    local v = FindVehicle(vID);
    if (v) v.Remove();
}