Hello, i’m wanting to find out the easiest and/or best way to have an item when used execute a chat command e.g. i’m using b1g plate remover which uses a chat command to remove the plate but i would like to have it linked to an item. Had a decent search around and couldnt find anything very helpful.
thanks in advance
i didn’t get your request very well.
you want some script to remove the plate instead of type it on chat? thats right?
yeah so basically the script uses a chat command but i want to have it use an item instead
1 Like
I dont know if you are still looking for this or found you answer, but i will post here how to do.
make an item in your database in items.
and put this code in your server script if dont have any make one
ESX.RegisterUsableItem('item_name', function(source)
TriggerClientEvent('smt:remove_plate', source)
end)
change ‘item_name’ to which item you want to have as usable and
in client script
RegisterCommand("removeplate", function()
end)
change this to
RegisterNetEvent('smt:remove_plate')
AddEventHandler('smt:remove_plate', function ()
-- Check if the player has plates stored
if not LicencePlate.Index and not LicencePlate.Number then
-- Client's ped
local PlayerPed = PlayerPedId()
-- Client's coords
local Coords = GetEntityCoords(PlayerPed)
-- Closest vehicle
local Vehicle = GetClosestVehicle(Coords.x, Coords.y, Coords.z, 3.5, 0, 70)
-- Client's coords
local VehicleCoords = GetEntityCoords(Vehicle)
-- Distance between client's ped and closest vehicle
local Distance = Vdist(VehicleCoords.x, VehicleCoords.y, VehicleCoords.z, Coords.x, Coords.y, Coords.z)
-- If within range and Ped is in a vehicle
if Distance < 3.5 and not IsPedInAnyVehicle(PlayerPed, false) then
--Saves the last vehicle
LastVehicle = Vehicle
-- Notification and animation
Animation()
SendNUIMessage({type = "ui",display = true,time = 6000,text = "Removing Plate..."}) --PROGRESSBAR
StopAnimTask(PlayerPedId(), "mini@repair", "fixing_a_player", 1.0)
-- Wait 6 seconds
Citizen.Wait(6000)
-- Store plate index
LicencePlate.Index = GetVehicleNumberPlateTextIndex(Vehicle)
-- Store plate number
LicencePlate.Number = GetVehicleNumberPlateText(Vehicle)
-- Set the plate to nothing
SetVehicleNumberPlateText(Vehicle, " ")
else
-- Notification
-- exports["mythic_notify"]:SendAlert("error", "No vehicle nearby.") Mythic_Notification
TriggerEvent('esx:showNotification', '~r~ No vehicle nearby.')
end
else
-- Notification
-- exports["mythic_notify"]:SendAlert("error", "You already have a licence plate on you.") Mythic_Notification
TriggerEvent('esx:showNotification', '~r~ You do not have a licence plate on you.')
end
end)
1 Like
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.