Jump to content

Bugged script?


Recommended Posts

So.. I got a bit of a bugged script. Its a "elevator script" Basically 2 points , Point a and point b that once you go into it it teleports you else where . We use this in our server to TP cars into garage interiors . The scripts a bit long but some help would be really nice as a friend said to me the script has a massive bug in it that could fuck up a whole server .

mysql = exports.mysql 
 
addEvent("onPlayerInteriorChange", true)
 
function createElevator(thePlayer, commandName, interior, dimension, ix, iy, iz)
    if (exports.global:isPlayerSuperAdmin(thePlayer)) then
        if not (interior) or not (dimension) or not (ix) or not (iy) or not (iz) then
            outputChatBox("SYNTAX: /" .. commandName .. " [interior ID] [Dimension ID] [X] [Y] [Z]", thePlayer, 255, 194, 14)
        else
            local x, y, z = getElementPosition(thePlayer)
           
            interior = tonumber(interior)
            dimension = tonumber(dimension)
            local interiorwithin = getElementInterior(thePlayer)
            local dimensionwithin = getElementDimension(thePlayer)
            ix = tonumber(ix)
            iy = tonumber(iy)
            iz = tonumber(iz)
            id = SmallestElevatorID()
            if id then
                local query = mysql:query_free("INSERT INTO elevators SET id='" .. mysql:escape_string(id) .. "', x='" .. mysql:escape_string(x) .. "', y='" .. mysql:escape_string(y) .. "', z='" .. mysql:escape_string(z) .. "', tpx='" .. mysql:escape_string(ix) .. "', tpy='" .. mysql:escape_string(iy) .. "', tpz='" .. mysql:escape_string(iz) .. "', dimensionwithin='" .. mysql:escape_string(dimensionwithin) .. "', interiorwithin='" .. mysql:escape_string(interiorwithin) .. "', dimension='" .. mysql:escape_string(dimension) .. "', interior='" .. mysql:escape_string(interior) .. "'")
                if (query) then
                    local pickup = createPickup(x, y, z, 3, 1318)
                    exports.pool:allocateElement(pickup)
                    local intpickup = createPickup(ix, iy, iz, 3, 1318)
                    exports.pool:allocateElement(intpickup)
                   
                    exports['anticheat-system']:changeProtectedElementDataEx(pickup, "dbid", id, false)
                    exports['anticheat-system']:changeProtectedElementDataEx(pickup, "other", intpickup)
                    exports['anticheat-system']:changeProtectedElementDataEx(pickup, "car", 0, false)
                    setElementInterior(pickup, interiorwithin)
                    setElementDimension(pickup, dimensionwithin)
                   
                    exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "dbid", id, false)
                    exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "other", pickup)
                    exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "car", 0, false)
                    setElementInterior(intpickup, interior)
                    setElementDimension(intpickup, dimension)
                   
                    outputChatBox("Elevator created with ID #" .. id .. "!", thePlayer, 0, 255, 0)
                end
            else
                outputChatBox("There was an error while creating an elevator. Try again.", thePlayer, 255, 0, 0)
            end
        end
    end
end
addCommandHandler("addelevator", createElevator, false, false)
 
function loadAllElevators(res)
    local result = mysql:query("SELECT id, x, y, z, tpx, tpy, tpz, dimensionwithin, interiorwithin, dimension, interior, car, disabled FROM elevators")
    local counter = 0
   
    if (result) then
        while true do
            local row = mysql:fetch_assoc(result)
            if not row then break end
           
            local id = tonumber(row["id"])
            local x = tonumber(row["x"])
            local y = tonumber(row["y"])
            local z = tonumber(row["z"])
           
            local ix = tonumber(row["tpx"])
            local iy = tonumber(row["tpy"])
            local iz = tonumber(row["tpz"])
           
            local dimensionwithin = tonumber(row["dimensionwithin"])
            local interiorwithin = tonumber(row["interiorwithin"])
           
            local dimension = tonumber(row["dimension"])
            local interior = tonumber(row["interior"])
            local car = tonumber(row["car"])
            local disabled = tonumber(row["disabled"])
           
            local pickup = createPickup(x, y, z, 3, disabled == 1 and 1314 or 1318)
            exports.pool:allocateElement(pickup)
            local intpickup = createPickup(ix, iy, iz, 3, disabled == 1 and 1314 or 1318)
            exports.pool:allocateElement(intpickup)
           
            exports['anticheat-system']:changeProtectedElementDataEx(pickup, "dbid", id, false)
            exports['anticheat-system']:changeProtectedElementDataEx(pickup, "other", intpickup)
            exports['anticheat-system']:changeProtectedElementDataEx(pickup, "car", car, false)
            setElementInterior(pickup, interiorwithin)
            setElementDimension(pickup, dimensionwithin)
               
            exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "dbid", id, false)
            exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "other", pickup)
            exports['anticheat-system']:changeProtectedElementDataEx(intpickup, "car", car, false)
            setElementInterior(intpickup, interior)
            setElementDimension(intpickup, dimension)
            counter = counter + 1
        end
        mysql:free_result(result)
    end
end
addEventHandler("onResourceStart", getResourceRootElement(), loadAllElevators)
 
function hitInteriorPickup( thePlayer )
    local pickuptype = getElementData(source, "type")
   
    local pdimension = getElementDimension(thePlayer)
    local idimension = getElementDimension(source)
   
    if pdimension == idimension then -- same dimension?
        local dbid, thePickup, theExit = call( getResourceFromName( "interior-system" ), "findProperty", player, getElementDimension( getElementData( source, "other" ) ) )
        if thePickup and getElementDimension( thePickup ) ~= getElementDimension( theExit ) then
            local name = getElementData( thePickup, "name" )
           
            if name then
                local owner = getElementData( thePickup, "owner" )
                local cost = getElementData( thePickup, "cost" )
               
                local ownerName = exports['cache']:getCharacterName( owner ) or "None"
                triggerClientEvent(thePlayer, "displayInteriorName", thePlayer, name, ownerName, getElementData( thePickup, "inttype" ), cost, getElementData( thePickup, "fee" ) )
            end
        end
       
        bindKeys( thePlayer, source )
        setTimer( checkLeavePickup, 500, 1, thePlayer, source )
    end
    cancelEvent()
end
addEventHandler("onPickupHit", getResourceRootElement(), hitInteriorPickup)
 
function isInPickup( thePlayer, thePickup, distance )
    local ax, ay, az = getElementPosition(thePlayer)
    local bx, by, bz = getElementPosition(thePickup)
   
    return getDistanceBetweenPoints3D(ax, ay, az, bx, by, bz) < ( distance or 2 ) and getElementInterior(thePlayer) == getElementInterior(thePickup) and getElementDimension(thePlayer) == getElementDimension(thePickup)
end
 
function checkLeavePickup( thePlayer, thePickup )
    if isElement( thePlayer ) then
        if isInPickup( thePlayer, thePickup ) then
            setTimer(checkLeavePickup, 1000, 1, thePlayer, thePickup)
        else
            unbindKeys(thePlayer, thePickup)
        end
    end
end
 
function func (player, f, down, player, pickup) enterElevator(player, pickup) end
 
function bindKeys(player, pickup)
    if (isElement(player)) then
        if not(isKeyBound(player, "enter", "down", func)) then
            bindKey(player, "enter", "down", func, player, pickup)
        end
       
        if not(isKeyBound(player, "f", "down", func)) then
            bindKey(player, "f", "down", func, player, pickup)
        end
       
        exports['anticheat-system']:changeProtectedElementDataEx( player, "interiormarker", true, false )
    end
end
 
function unbindKeys(player, pickup)
    if (isElement(player)) then
        if (isKeyBound(player, "enter", "down", func)) then
            unbindKey(player, "enter", "down", func, player, pickup)
        end
       
        if (isKeyBound(player, "f", "down", func)) then
            unbindKey(player, "f", "down", func, player, pickup)
        end
       
        exports['anticheat-system']:changeProtectedElementDataEx( player, "interiormarker" )
        triggerClientEvent( player, "displayInteriorName", player )
    end
end
 
 
function isInteriorLocked(dimension)
    local result = mysql:query_fetch_assoc("SELECT type, locked FROM `interiors` WHERE id = " .. mysql:escape_string(dimension))
    local locked = false
    if result then
        if tonumber(result["rype"]) ~= 2 and tonumber(result["locked"]) == 1 then
            locked = true
        end
    end
    return locked
end
 
--[[
Car Teleport Modes:
0: players only
1: players and vehicles
2: vehicles only
3: no entrance
]]--
function enterElevator(player, pickup)
    local cartp = getElementData( pickup, "car" )
    if cartp == 3 then
        outputChatBox("You try the door handle, but it seems to be locked.", player, 255, 0,0, true)
        return
    end
   
    vehicle = getPedOccupiedVehicle( player )
    if isInPickup ( player, pickup ) and ( ( vehicle and cartp ~= 0 and getVehicleOccupant( vehicle ) == player ) or not vehicle ) then
        if not vehicle and cartp == 2 then
            outputChatBox( "This entrance is for vehicles only.", player, 255, 0, 0 )
            return
        end
       
        if getElementModel( pickup ) == 1314 then
            outputChatBox( "This interior is currently disabled.", player, 255, 0, 0 )
            return
        end
       
        local other = getElementData( pickup, "other" )
       
        local x, y, z = getElementPosition( other )
        local interior = getElementInterior( other )
        local dimension = getElementDimension( other )
       
        -- find the pickup inside to see if the house is locked
        local ldimension = getElementDimension( pickup )
       
        local locked = false
        if ldimension == 0 and dimension ~= 0 then -- entering a house
            locked = isInteriorLocked(dimension)
        elseif ldimension ~= 0 and dimension == 0 then -- leaving a house
            locked = isInteriorLocked(ldimension)
        elseif ldimension ~= 0 and dimension ~= 0 and ldimension ~= dimension then -- changing between two houses
            locked = isInteriorLocked(ldimension) or isInteriorLocked(dimension)
        else -- outside
            locked = false
        end
       
        if locked then
            outputChatBox("You try the door handle, but it seems to be locked.", player, 255, 0,0, true)
            return
        end
       
        -- check for entrance fee
        local dbid, thePickup = call( getResourceFromName( "interior-system" ), "findProperty", player, dimension )
        if dimension ~= ldimension and thePickup then
            if getElementData( player, "adminduty" ) ~= 1 and not exports.global:hasItem( player, 5, getElementData( thePickup, "dbid" ) ) then
                local fee = getElementData( thePickup, "fee" )
                if fee and fee > 0 then
                    if not exports.global:takeMoney( player, fee ) then
                        outputChatBox( "You don't have enough money with you to enter this interior.", player, 255, 0, 0 )
                        return
                    else
                        local ownerid = getElementData( thePickup, "owner" )
                        local query = mysql:query_free("UPDATE characters SET bankmoney = bankmoney + " .. mysql:escape_string(fee) .. " WHERE id = " .. mysql:escape_string(ownerid) )
                        if query then
                            for k, v in pairs( getElementsByType( "player" ) ) do
                                if isElement( v ) then
                                    if getElementData( v, "dbid" ) == ownerid then
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...