Jump to content

Need help with engine system


Cronoss

Recommended Posts

It's me again. I was testing my edited vehicle script  and found a error, when the player enters in the vehicle, It's doesnt matter the chair, they can turn on the engine even if they sit down behind the driver position. I was wondering, there is a recourse that could prevent this? I mean, only execute the comand "turn on the vehicle" when player is sitting in the driver's chair

Link to comment

Here is the code I'm using

 

--------------

addCommandHandler("motor", function(player,cmd)
    local acc = player:getAccount()
    local owner = acc:getName()
    local vehicle = Ped.getOccupiedVehicle(player)
    if vehicle then
        if (vehicle:getData("vehicles:owner") == owner) then
            setPlayerVehicleEngine(player, vehicle)
        else
            player:outputChat("No tienes las llaves de este vehículo.", 255, 0, 0)
        end
    else
        player:outputChat("Debes estar en un vehículo para ejecutar este comando.", 255, 0, 0)
    end
end)

function setPlayerVehicleEngine(player, vehicle)
    if (vehicle:getData("vehicles:engine") == 1) then
        vehicle:setData("vehicles:engine", 0)
        vehicle:setEngineState(false)
        player:outputChat("Apagaste el motor.", 214, 37, 37)
        connection:exec("UPDATE vehicles SET engine=? WHERE id=? AND owner=?", 0, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))
    elseif (vehicle:getData("vehicles:engine") == 0) then
        vehicle:setData("vehicles:engine", 1)
        vehicle:setEngineState(true)
        player:outputChat("Encendiste el motor.", 141, 229, 22)
        connection:exec("UPDATE vehicles SET engine=? WHERE id=? AND owner=?", 1, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))    
    end
end

I want to change the "Ped.getOccupiedVehicle(player)" for "Ped.getPedOccupiedVehicleSeat" and add a condition but when I try, the resource doesn't work 

Link to comment
addCommandHandler("motor", function(player,cmd)
    local acc = player:getAccount()
    local owner = acc:getName()
    local vehicle = getPedOccupiedVehicle(player)
    if vehicle then
        if(getPedOccupiedVehicleSeat(player) ~= 0) then
           return
        end 
        if (vehicle:getData("vehicles:owner") == owner) then
            setPlayerVehicleEngine(player, vehicle)
        else
            player:outputChat("No tienes las llaves de este vehículo.", 255, 0, 0)
        end
    else
        player:outputChat("Debes estar en un vehículo para ejecutar este comando.", 255, 0, 0)
    end
end)

can you try this

  • Like 1
Link to comment

Hello @CronossI prepared a code for you according to the text you sent.
Español : buen día señor

getPedOccupiedVehicle

addCommandHandler("motor", function(player,cmd)
    local acc = player:getAccount()
    local owner = acc:getName()
    local vehicle = getPedOccupiedVehicle(player) --typo,i changed this
    if vehicle then
        if(getPedOccupiedVehicleSeat(player) ~= 0) then
           return
        end 
        if (vehicle:getData("vehicles:owner") == owner) then
            setPlayerVehicleEngine(player, vehicle)
        else
            player:outputChat("No tienes las llaves de este vehículo.", 255, 0, 0)
        end
    else
        player:outputChat("Debes estar en un vehículo para ejecutar este comando.", 255, 0, 0)
    end
end)

function setPlayerVehicleEngine(player, vehicle)
    if (vehicle:getData("vehicles:engine") == 1) then
        vehicle:setData("vehicles:engine", 0)
        vehicle:setEngineState(false)
        player:outputChat("Apagaste el motor.", 214, 37, 37)
        connection:exec("UPDATE vehicles SET engine=? WHERE id=? AND owner=?", 0, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))
    elseif (vehicle:getData("vehicles:engine") == 0) then
        vehicle:setData("vehicles:engine", 1)
        vehicle:setEngineState(true)
        player:outputChat("Encendiste el motor.", 141, 229, 22)
        connection:exec("UPDATE vehicles SET engine=? WHERE id=? AND owner=?", 1, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))    
    end
end

 

I prefer you to look at my picture I posted here, by clicking the circle button you can place your codes in your comment in Lua assembly

Edited by eoL|Shady
  • Like 1
Link to comment
  • 3 months later...
On 27/01/2022 at 12:26, Reyomin said:

You can check which seat the player occupies using getPedOccupiedVehicleSeat function. Other functions involving vehicle seats are getVehicleOccupant and getVehicleOccupants.

I know it's not the subject of this topic but I need to talk to you!
 I really admire your work on the drawtag mod. if you can send me an email beacuse i can't send you messages on forum -> [email protected]
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...