[Release] ESX_Scrap

ESX_Scrap


Description: Lets you scrap certain cars for in-game resources that you can add yourself and use those resources in crafting later on.

Requirements:
[ESX] Base
EssentialMode base
MySQL Async Library - 3.2.0

Intended for use with [ESX] Crafting System


How to install
Download contents of [GitHub] esx_scrap and place it inside your resources folder.

Import ‘esx_scrap.sql’ to your database.

Add ‘start esx_scrap’ to your server.cfg after essentialmode and es_extended.


How to add your own items
Execute this SQL Query on PhpMyAdmin or other database clients.

INSERT INTO esx_scrap (vehicle, multiplier) VALUES ('car', '1')


How it works

vehicle = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId()), false)
model = GetEntityModel(vehicle)
playerVeh = GetDisplayNameFromVehicleModel(model)

Using the code above the client checks the vehicle name string with a set of strings (car names) inside the database.

local randomizer = math.random(0,2)
if randomizer == 0 then
    xPlayer.addInventoryItem('steel', round(mOne))
elseif randomizer == 1 then
    xPlayer.addInventoryItem('plastic', round(mOne))
elseif randomizer == 2 then
    xPlayer.addInventoryItem('electronics', round(mOne))
end

This code selects a random value and gives the player an X amount of Y item based on the randomized number.


Video

Feel free to use, share and modify this script to your willing!

7 Likes

nice script this will come useful for some things i got on my server thanks

1 Like

Love this especially with what it gives. Now we just need to make something similar with the NOpixels mechanic shop where they use these items to repair the cars. Keep up the great work.

2 Likes

I’m glad you like it, I’m working on a few more scripts that work together with this one, so keep an eye out!

1 Like

It doesn’t work for me, I’ve followed all the instructions and when I’m going to press the E button it doesn’t do anything

Do you have any messages in F8 or the console?
Could also be that you didn’t add the items to the database maybe?

The database value for the car also shouldn’t be just ‘car’, use the spawn names for cars you want to be scrapped.

Yeah I am having the same issue as well just trying to scrap even the cars that come with the database inserts. The marker shows up but nothing happens after I press E, and nothing shows up on the F8 Menu.

It also shows that I need to be in the vehicle if I go up to the marker and try to press E to scrap it while outside of it.

I am getting this error in the database

Nevermind i’m dumb and Heidi didn’t update properly

You have an exploit where passengers can use it infinitely while driver backs in and out. Here is a fix in client.lua around line 69.

if CurrentAction == 'scrap_vehicle' then
    vehicle = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId()), false)
    model = GetEntityModel(vehicle)
    playerVeh = GetDisplayNameFromVehicleModel(model)
    if playerVeh ~= 'CARNOTFOUND' and GetPedInVehicleSeat(vehicle, -1) == GetPlayerPed(GetPlayerFromServerId()) then
        TriggerServerEvent('esx_scrap:checkVeh', playerID, playerVeh)
    else
        ESX.ShowNotification('You need to be inside a vehicle!')
    end
end
1 Like

For some reason it only gives me plastic and nothing else.

Thank you for the fix, I pushed it to the git!

@freddan11Did you add all the items to the database?

1 Like

how can i make it so that it gives me all the items randomized and not just one item. now i only get 1 item random at the time but a car doasnt only give plastic it should give all the items random atleast thats what i want

The code contains a randomize script.
What you’re saying is how the script is supposed to work (give random items).
Did you add all the items to the database?

local xPlayer = ESX.GetPlayerFromId(source)
local divider = math.random(50,100)
local mOne = (100 * data.multiplier) / divider
local randomizer = math.random(0,2)
if randomizer == 0 then
    xPlayer.addInventoryItem('steel', round(mOne))
elseif randomizer == 1 then
    xPlayer.addInventoryItem('plastic', round(mOne))
elseif randomizer == 2 then
    xPlayer.addInventoryItem('electronics', round(mOne))
end

i have i dont mean it like that i get the plastic electronics etc etc but i want all of them not only plastic or only electronics right now it only rewards 1 soort of item randomized and not al of them at once random. i want it to reward scrap metal, plastic, electronics, all at once but random and maybe also a timer so they can only scrap a car once every 30 mins or so

It currently works by giving you one random item, you can go ahead and adjust the code to your liking and do the changes you want to do, the initial plan for this script is to give one random item.

Hi I have a problem: when i scrapped a vehcile,what is mine,after the scrap method,the vehicle move into impound garage,and I can use that again.Could someone tell a solution for this bug?Thank you in advance! :slight_smile:

Hi.

The script is not meant to be used with personal vehicles, if you want to disable people scrapping their personal vehicle you’d need to add the code for it depending on which addon you use.

How do you change and add cars to scrap… ive changed the cars in the esx_scrap.sql and the old original cars still work and not the ones ive added.

INSERT INTO esx_scrap (id, vehicle, multiplier) VALUES

(1, ‘Panto’, 1),

(2, ‘BfInjection’, 1),

(3, ‘DUNE’, 1),

(4, ‘Tornado3’, 2),

(5, ‘Emperor2’, 2),

(6, ‘Voodoo2’, 2),

(7, ‘RatLoader’, 3)

(8, ‘Rebel’, 3)

(9, ‘Surfer2’, 3)

(10, ‘Journey’, 4)

(11, ‘Scrap’, 4)

(12, ‘Biff’, 5);

Hello, you never insert an ID when a field has Auto Increment on it.

INSERT INTO esx_scrap (vehicle, multiplier) values (‘Panto’, 1);

This is the correct way to do it, just like it’s shown on the main post.

Edit: The initial .SQL inside the GitHub repo is a result of “exporting” a table, that’s why it has ID set there.
Having ID there will only work when initially setting up the table and values don’t actually have IDs.

Even the initial SQL that’s provided works.