Jump to content

Export Help


mint3d

Recommended Posts

Ok so I am trying to do this but its not working I get no errors in debugscript 3

Door Script

-- Special doors script by Puma 
-- Free to use and free to edit, but please aks me for approval if you want to release a significantly altered version of this script 
  
-- YOU CAN EDIT THIS: 
  
local doorTypeRotation = { 
    ["scissor"] = {72, 0, 0}, 
    ["butterfly"] = {0, -60, 60} 
} 
    -- add doortypes 
  
----------------------- 
-- HOW TO USE THIS for douchebags 
----------------------- 
  
--         Just put this somewhere in your script and fill in a vehicle and a doortype (see above for available doortypes) 
--         setVehicleDoorType ( v, type ) 
  
--         If you want to reset the doortype, just use setVehicleDoorType ( v ) without filling in a type 
  
-------------------------------- 
-- Now comes the part you shouldn't mess with 
-------------------------------- 
  
-- Defining som :~ ----------- 
  
local p = getLocalPlayer() 
local doorAnimTime = 350 
local doorIDComponentTable = { 
    [2] = "door_lf_dummy", 
    [3] = "door_rf_dummy", 
    [4] = "door_lr_dummy", 
    [5] = "door_rr_dummy" 
                        } 
local doorTypes = {} 
local oldDoorRatios = {} 
local doorStatus = {} 
local doorTimers = {} 
  
for doorType, doorTable in pairs ( doorTypeRotation ) do 
    table.insert ( doorTypes, doorType ) 
end 
  
local vDoorType = {} 
for i, v in pairs ( getElementsByType("vehicle")) do 
    local doorType = getElementData ( v, "vDoorType" ) 
    if doorType then 
        vDoorType[v] = doorType 
    end 
end 
  
local function vRemoveDoorTypeFromTable ( v ) 
    if isVehicle(v) then 
        vDoorType[v] = nil 
        oldDoorRatios[v] = nil 
        doorStatus[v] = nil 
        doorTimers[v] = nil 
    end 
end 
function vehicleDestroyed () 
    vRemoveDoorTypeFromTable(source) 
end 
addEventHandler ( "onClientElementDestroy", root, vehicleDestroyed ) 
addEventHandler ( "onClientVehicleExplode", root ,vehicleDestroyed ) 
  
-- MAIN ----------------------------------------------------------------------- 
  
function setVehicleDoorType ( v, type ) 
    if v and isElement(v) and getElementType(v) == "vehicle" then 
        if type and tostring(type) and isDoorType(type) then 
            setElementData ( v, "vDoorType", type ) 
        else 
            setElementData ( v, "vDoorType", nil ) 
            vRemoveDoorTypeFromTable ( v ) 
        end 
    end 
end 
  
local function elementDataChange ( key, oldValue ) 
    if key == "vDoorType" and isVehicle(source) then 
        vDoorType[source] = getElementData ( source, "vDoorType" ) 
    end 
end 
addEventHandler ( "onClientElementDataChange", root, elementDataChange ) 
  
local function preRender () 
    for v, doorType in pairs ( vDoorType ) do 
        if isElement(v) then 
            if not doorTimers[v] then doorTimers[v] = {} end 
            local doorRatios = {} 
            for i=1, 4 do 
                local i = i + 1 -- leftfront=2, rightfront=3, leftrear=4, rightrear=5 
                local doorRatio = getVehicleDoorOpenRatio ( v, i ) 
  
                if doorRatio and oldDoorRatios[v] and oldDoorRatios[v][i] then 
                    local oldDoorRatio = oldDoorRatios[v][i] 
  
                    if not doorStatus[v] then doorStatus[v] ={} end 
                    local doorPreviousState = doorStatus[v][i] 
                    if not doorPreviousState then doorPreviousState = "closed" end 
                    if doorPreviousState == "closed" and doorRatio > oldDoorRatio then 
                        doorStatus[v][i] = "opening" 
                        doorTimers[v][i] = setTimer(function(v,i)doorStatus[v][i]="open" doorTimers[v][i]=nil end,doorAnimTime,1,v,i) 
                    elseif doorPreviousState == "open" and doorRatio < oldDoorRatio then 
                        doorStatus[v][i] = "closing" 
                        doorTimers[v][i] = setTimer(function(v,i)doorStatus[v][i]="closed" doorTimers[v][i]=nil end,doorAnimTime,1,v,i) 
                    end 
                elseif not oldDoorRatios[v] then 
                    oldDoorRatios[v] = {} 
                end 
                if doorRatio then 
                    oldDoorRatios[v][i] = doorRatio 
                end 
            end 
        else 
            vDoorType[v] = nil 
            oldDoorRatios[v] = nil 
            doorStatus[v] = nil 
            doorTimers[v] = nil 
        end 
    end 
  
    for v, doors in pairs ( doorStatus ) do 
        local doorType = vDoorType[v] 
        local rx, ry, rz = unpack ( doorTypeRotation[doorType] ) 
        for door, status in pairs ( doors ) do 
            local ratio = 0 
            if status == "open" then ratio = 1 end 
            local timer = doorTimers[v][door] 
            if timer and isTimer ( timer ) then 
                local timeLeft = getTimerDetails ( timer ) 
                ratio = timeLeft/doorAnimTime 
                if status == "opening" then ratio = 1 - ratio end 
            end 
            local dummyName = doorIDComponentTable[door] 
            if dummyName then 
                local rx, ry, rz = unpack(doorTypeRotation[doorType]) 
                local rx, ry, rz = rx*ratio, ry*ratio, rz*ratio 
                if string.find(dummyName,"rf") or string.find(dummyName,"rr") then 
                    ry, rz = ry*-1, rz*-1 
                end 
                setVehicleComponentRotation ( v, dummyName, rx, ry, rz ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPreRender", root, preRender ) 
  
-- UTILS ----------------------------------------------------------------- 
  
function isDoorType ( type ) 
    if type and tostring(type) then 
        for i, t in pairs ( doorTypes ) do 
            if t == type then return true end 
        end 
    end 
end 
  
function pv (player) 
    if not player then 
        return getPedOccupiedVehicle ( p ) 
    elseif isPlayer(player) then 
        return getPedOccupiedVehicle ( player ) 
    end 
end 
  
function isPlayer ( player ) 
    if player and isElement ( player ) and getElementType(player) == "player" then 
        return true 
    end 
end 
  
function isVehicle ( vehicle ) 
    if vehicle and isElement ( vehicle ) and getElementType(vehicle) == "vehicle" then 
        return true 
    end 
end 
  
  
--Meta-- 

Command Script

addCommandHandler ( "scissor", 
    function ( ) 
        local veh = getPedOccupiedVehicle ( localPlayer ) 
        if ( veh ) then 
            exports [ "door" ]:setVehicleDoorType ( veh, scissor ) 
        end 
    end 
) 
  
--Meta-- 

  

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