Sign in to follow this  
Insigne

get/setElementDimension/Interior PROBLEM

Recommended Posts

Hello guys, i have a big problem. I created some object in interior, 

after the script was loaded, it did not create the objects.

HERE THE SCRIPT :) pls help

local mysql = exports.mta_connection:getConnection()
local loadedRoulettePoints = 0

function createRoulettePoint(x,y,z,r,i,d,player)
    x = tonumber(x)
    y = tonumber(y)
    z = tonumber(z)
    r = tonumber(r)
    i = tonumber(i)
    d = tonumber(d)
    local insertQuery = dbQuery(mysql, "INSERT INTO roulettes SET position = ?", toJSON({x, y, z, r, i, d}))
    local insertResult, insertNumber, insertID, inti, dim = dbPoll(insertQuery, -1)
    local inti = getElementInterior(player)
    local dim = getElementDimension(player) 

    if insertResult then
        temp = createObject(1978, x, y, z, 0, 0, r)

        if isElement(temp) then
            setElementData(temp, "dbid", insertID)
            setElementInterior(temp, inti)
            setElementDimension(temp, dim)
            setElementData(temp, "isRefill", true)
            
            for k,v in ipairs(getElementsByType("player")) do
                if getElementData(v,"acc:admin") >= 7 then
                    outputChatBox("#7cc576[New - Network]:#0094ff "..getElementData(player, "char:anick").." #fffffflétrehozott egy rulett asztalt. ID:#7cc576 "..insertID,v,255,255,255,true)
                end
            end
        end
    end
end

addCommandHandler("createroulette", function(player)
    if getElementData(player, "acc:admin") >= 7 then
        x,y,z = getElementPosition(player)
        _,_,r = getElementRotation(player)
        i = getElementInterior(player)
        d = getElementDimension(player)
        createRoulettePoint(x,y,z,r,i,d,player)
    end
end)

addCommandHandler("delroulette", function(player)
    if getElementData(player, "acc:admin") < 7 then return end
    
    local id = getNearestRoulettePoint(player)
    local interiorka = getElementInterior(player)
    if id ~= -1 and getElementData(id, "isRefill") then
        id = getElementData(id, "dbid")
        interiorka = getElementData(interiorka, "dbid")
    end
    if id == -1 then
        outputChatBox("#D63F3E[New - Network]: #ffffffNincs a közeledben rulett asztal.", player, 0, 0, 0, true)
        return
    end
        
    local qh = dbQuery(mysql, "DELETE FROM roulettes WHERE id = ?", id)
    local removeResult, _, removeID = dbPoll(qh, -1)
    
    if removeResult then
        for k,v in ipairs(getElementsByType("player")) do
            if getElementData(v,"acc:admin") >= 1 then
                outputChatBox("#7cc576[New - Network]:#0094ff "..getElementData(player, "char:anick").." #fffffftörölt egy rulett asztalt.",v,255,255,255,true)
            end
        end
        
        for k,v in ipairs(getElementsByType("object")) do
            if getElementData(v, "isRefill") and getElementData(v, "dbid") == id then
                destroyElement(v)
            end
        end
    end
end)

function getNearestRoulettePoint(ep)
    local pe = {getElementPosition(ep)}
    local dis = 2
    local dis2 = 0
    local obj = -1

    local type = "object"
    for key, value in ipairs(getElementsByType(type)) do
        local p2 = {getElementPosition(value)}
        dis2 = getDistanceBetweenPoints3D (pe[1], pe[2], pe[3], p2[1], p2[2], p2[3])
            
        if tonumber(dis2) < tonumber(dis)  then
            dis = dis2
            obj = value
        end
    end
    return obj
end

function loadRoulettePoints(resource, object)
    if resource ~= getThisResource() then return end
    
    loadedRoulettePoints = 0
    local loaderQuery = dbPoll(dbQuery(mysql, "SELECT * FROM roulettes"), -1)

    

    if loaderQuery then
        for key, value in ipairs(loaderQuery) do
            local id = tonumber(value["id"])
            local position = fromJSON(value["position"])
            local interior, dimension = getElementsByType("object")

            local inti = getElementInterior(interior)
            local dim = getElementDimension(dimension) 

            for a, p in ipairs (getElementsByType("object")) do
                if p then
                    local loadedRoulettes = createObject(1978, position[1], position[2], position[3], 0, 0, position[4])
                    setElementData(loadedRoulettes, "dbid", id)
                    setElementInterior(loadedRoulettes, inti)
                    setElementDimension(loadedRoulettes, dim)
                    setElementDoubleSided(loadedRoulettes, true) 

                    local loadedPedPoint = createPed(123, position[1], position[2], position[3], position[4]+90)
                    setElementData(loadedPedPoint, "dbid", id)
                    --setElementInterior(loadedPedPoint, inti)
                    --setElementDimension(loadedPedPoint, dim)
                end
            end

            loadedRoulettePoints = loadedRoulettePoints + 1
        end
        outputDebugString(loadedRoulettePoints .. " rulett asztal betöltve.")
    end
end
addEventHandler("onResourceStart", resourceRoot, loadRoulettePoints)

 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.