Jump to content

control doors vehicles


mr.Extreme

Recommended Posts

hello

i have problem

i cant control doors vehicle

serverside:

function openDoor(door, position) 
    local theVehicle 
    if ( getElementType(source) == "vehicle" ) then 
        theVehicle = source 
    end 
    if ( getElementType(source) == "player" ) then 
        theVehicle = getElementData ( source, "cl_ownedvehicle" ) 
    end 
    if ( theVehicle ) then 
    local theVehicle = getPedOccupiedVehicle(source) 
    if getPedOccupiedVehicleSeat(source) == 0 then 
        if door == 0 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 0, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 0, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 0, position/100, 0.5) 
            end 
        end 
        if door == 1 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 1, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 1, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 1, position/100, 0.5) 
            end 
        end 
        if door == 2 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 2, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 2, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 2, position/100, 0.5) 
            end 
        end 
        if door == 3 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 3, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 3, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 3, position/100, 0.5) 
            end 
        end 
        if door == 4 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 4, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 4, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 4, position/100, 0.5) 
            end 
        end 
        if door == 5 then 
            if position==0 then 
                setVehicleDoorOpenRatio(theVehicle, 5, 0, 0.5) 
            end 
            if position==100 then 
                setVehicleDoorOpenRatio(theVehicle, 5, 1, 0.5) 
            end 
            if position>0 and position<100 then 
                setVehicleDoorOpenRatio(theVehicle, 5, position/100, 0.5) 
            end 
        end 
    end 
end  
end  
addEvent("openDoorOrClose", true) 
addEventHandler("openDoorOrClose", getRootElement(), openDoor) 

and thx for helping.

Edited by Guest
Link to comment
  • Moderators

try this:

local allowedDoors = {[0]=true,[1]=true,[2]=true,[3]=true,[4]=true,[5]=true} 
local openDoor = function (door, position) 
    door,position = tonumber(door), tonumber(position)  
    if isElement(source) and door and position and allowedDoors[door]  then 
        if position>=0 and position<=100 then 
            setVehicleDoorOpenRatio(source, door, position/100, 1000) 
        end 
    elseif isElement(client) then 
        outputChatBox("something went wrong",client) 
    end 
end  
addEvent("openDoorOrClose", true) 
addEventHandler("openDoorOrClose", root, openDoor) 

Link to comment
try this:
local allowedDoors = {[0]=true,[1]=true,[2]=true,[3]=true,[4]=true,[5]=true} 
local openDoor = function (door, position) 
    door,position = tonumber(door), tonumber(position)  
    if isElement(source) and door and position and allowedDoors[door]  then 
        if position>=0 and position<=100 then 
            setVehicleDoorOpenRatio(source, door, position/100, 1000) 
        end 
    elseif isElement(client) then 
        outputChatBox("something went wrong",client) 
    end 
end  
addEvent("openDoorOrClose", true) 
addEventHandler("openDoorOrClose", root, openDoor) 

no Work :( and no there problem in debugscript 3 :(

Link to comment
  • Moderators
    local allowedDoors = {[0]=true,[1]=true,[2]=true,[3]=true,[4]=true,[5]=true} 
    local openDoor = function (door, position) 
  
    outputChatBox(tostring(door) .. " " .. tostring(position)) -- debugging........ 
  
        door,position = tonumber(door), tonumber(position) 
        if isElement(source) and door and position and allowedDoors[door]  then 
            if position>=0 and position<=100 then 
                setVehicleDoorOpenRatio(source, door, position/100, 1000) 
            end 
        elseif isElement(client) then 
            outputChatBox("something went wrong",client) 
        end 
    end 
    addEvent("openDoorOrClose", true) 
    addEventHandler("openDoorOrClose", root, openDoor) 

How did you call it?

If this doesn't output anything, then you are calling it wrong, if it does then you know what you are doing wrong with delivering the data.

It should look like this:

triggerServerEvent ("openDoorOrClose",vehicle,door, position) 

Also see line 4, that is the best way how you can debug your script. Use the tostring() function to prevent errors during the debugging. Know what kind of data is flowing through your system with: type() function.

Strings, booleans, nils, number, tables, userdata's(vehicles/players/peds/objects), functions etc.....
  
variable = true 
  
outputChatBox(tostring(variable)) -- true 
outputChatBox(type(variable))-- boolean (true or false) 
  

and pls no sad looking smilies, you can't expect code starts working at ones.

Link to comment

you can fix it

i dont understand you

client:

setElementData(GUIEditor.scrollbar[1], "Type", 0) 
setElementData(GUIEditor.scrollbar[2], "Type", 2) 
setElementData(GUIEditor.scrollbar[3], "Type", 3) 
setElementData(GUIEditor.scrollbar[4], "Type", 4) 
setElementData(GUIEditor.scrollbar[5], "Type", 5) 
setElementData(GUIEditor.scrollbar[6], "Type", 1) 
  
function updateRatio(Scrolled) 
    local position = guiScrollBarGetScrollPosition(Scrolled) 
    local door = getElementData(Scrolled, "Type") 
    triggerServerEvent ("openDoorOrClose",vehicle,door, position) 
end 
addEventHandler("onClientGUIScroll", getRootElement(), updateRatio) 

server:

   local allowedDoors = {[0]=true,[1]=true,[2]=true,[3]=true,[4]=true,[5]=true} 
    local openDoor = function (door, position) 
  
    outputChatBox(tostring(door) .. " " .. tostring(position)) -- debugging........ 
  
        door,position = tonumber(door), tonumber(position) 
        if isElement(source) and door and position and allowedDoors[door]  then 
            if position>=0 and position<=100 then 
                setVehicleDoorOpenRatio(source, door, position/100, 1000) 
            end 
        elseif isElement(client) then 
            outputChatBox("something went wrong",client) 
        end 
    end 
    addEvent("openDoorOrClose", true) 
    addEventHandler("openDoorOrClose", root, openDoor) 

Link to comment
  • Moderators
local updateRatio = function (Scrolled) 
    local position = guiScrollBarGetScrollPosition(Scrolled) 
    local door = getElementData(Scrolled, "Type") 
    local vehicle = getPedOccupiedVehicle ( localPlayer )-- get it's vehicle 
    if vehicle and door and position then -- check if all the data is there. 
        triggerServerEvent ("openDoorOrClose",vehicle,door, position) -- start sending. 
    end 
end 
addEventHandler("onClientGUIScroll", root, updateRatio) 

Link to comment

You can actually control the doors while you're away from the vehicle, simply by using element data (not recommended), or a database like: sql, mysql, xml (recommended). You will need to use a timer or something to check the data then change on the vehicle.

Link to comment

As I said:

You can actually control the doors while you're away from the vehicle, simply by using element data (not recommended), or a database like: sql, mysql, xml (recommended). You will need to use a timer or something to check the data then change on the vehicle.

If you don't understand, I am sorry, but it is not my problem, I just gave an example how to make it work while not in the vehicle.

Link to comment
  • Moderators

@manve1

or why don't call the lua variables(tables) instead... instead of those memory eaters.

Loading every time a xml list of 1000+ players....

Sql and mysql for permanent saving. Tables for temporary.

The rest have differed functionary's.

XML:

Saving settings for scripts serverside, saving cookies clientside.

Elementdata:

Usefull for sharing score with other players and server.

Link to comment
You can actually control the doors while you're away from the vehicle, simply by using element data (not recommended), or a database like: sql, mysql, xml (recommended). You will need to use a timer or something to check the data then change on the vehicle.

Now I understand what you mean :D:D:D

but how i can use SQL

Link to comment
@manve1

or why don't call the lua variables(tables) instead... instead of those memory eaters.

Loading every time a xml list of 1000+ players....

Sql and mysql for permanent saving. Tables for temporary.

The rest have differed functionary's.

XML:

Saving settings for scripts serverside, saving cookies clientside.

Elementdata:

Usefull for sharing score with other players and server.

I've proven a point that it can be made and to prove that it can be made, I gave a descriptive explanation on how it could be used, anything else from that point is what the person thinks is best for him.

Link to comment
  • Moderators

As far I know we talked about something that will be important after the remote control.

No need to start a new topic when the subject skipped some steps. Just start with the remote control.

AFAIK I was the one that was helping you in the first place, when he started talking about saving things permanently.

So when you enter a vehicle, you can leave the vehicle and you still want to control it right?

Link to comment
As far I know we talked about something that will be important after the remote control.

No need to start a new topic when the subject skipped some steps. Just start with the remote control.

AFAIK I was the one that was helping you in the first place, when he started talking about saving things permanently.

So when you enter a vehicle, you can leave the vehicle and you still want to control it right?

yeah

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...