Jump to content

[HELP] Doesn't get self.col as an element


..:D&G:..

Recommended Posts

Hello guys, I got some problems with an interaction system. On my other server it works perfectly, but on my main server it doesn't. I want to get the interior and dimension of an element which is self.col

local cFunc = {};       -- Local Functions  
local cSetting = {};    -- Local Settings 
  
Interaction_System = {}; 
Interaction_System.__index = Interaction_System; 
  
  
function Interaction_System:New(...) 
    local obj = setmetatable({}, {__index = self}); 
    if obj.Constructor then 
        obj:Constructor(...); 
    end 
    return obj; 
end 
  
  
function Interaction_System:Render() 
    local x, y, z = getElementPosition(localPlayer) 
    local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) 
     
    if(int ~= getElementInterior(self.col)) then 
        setElementInterior(self.col, int) 
    end 
    if(dim ~= getElementDimension(self.col)) then 
        setElementDimension(self.col, dim) 
    end 
     
    setElementPosition(self.col, x, y, z); 
end 
  
function Interaction_System:HitCol(hitElement) 
    if(isPedInVehicle(localPlayer) == false) then 
        local lastdis = math.huge; 
        for index, ele in pairs(getElementsWithinColShape(self.col)) do 
            if(self.allowedInteraction[getElementType(ele)] == true) and (getElementData(ele, "SLOTMACHINE:LEVER")) then 
                local x, y, z = getElementPosition(localPlayer) 
                local x2, y2, z2 = getElementPosition(ele) 
                if(getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) < lastdis) then 
                    lastdis = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) 
                    hitElement = ele 
                end 
            end 
        end 
     
        if(isElement(hitElement)) then 
            self.interactElement = hitElement; 
        end 
    end 
end 
  
  
function Interaction_System:LeaveCol(hitElement) 
    self.interactElement = nil; 
end 
  
  
function Interaction_System:Toggle() 
    if(isElement(self.interactElement)) then 
        if(getElementData(self.interactElement, "SLOTMACHINE:LEVER") == true) then 
            triggerServerEvent("onSlotmachineStartPlayer", self.interactElement, localPlayer) 
        end 
    end 
end 
  
function Interaction_System:Constructor(...) 
    self.renderFunc = function() self:Render() end; 
    self.colHitFunc = function(...) self:HitCol(...) end; 
    self.colLeaveFunc = function(...) self:LeaveCol(...) end; 
    self.toggleFunc = function(...) self:Toggle() end; 
     
    self.allowedInteraction = { 
        ["object"] = true, 
        ["vehicle"] = true, 
    } 
     
    self.interactElement = nil; 
     
    -- Instanzen  
    self.col = createColSphere(0, 0, 0, 4); 
     
    addEventHandler("onClientRender", getRootElement(), self.renderFunc) 
    addEventHandler("onClientColShapeHit", self.col, self.colHitFunc) 
    addEventHandler("onClientColShapeLeave", self.col, self.colLeaveFunc) 
     
    bindKey("h", "down", self.toggleFunc) 
     
    outputDebugString("[CALLING] Interaction_System: Constructor"); 
end 
  
-- EVENT HANDLER -- 
  
  
local interaction_system = Interaction_System:New() 
  

Any ideas? I don't get why it works on a server but not on the other..

Link to comment

This is the function with the render, and the function that gives all the errors:

function Interaction_System:Render() 
    local x, y, z = getElementPosition(localPlayer) 
    local int, dim = getElementInterior(localPlayer), getElementDimension(localPlayer) 
    
    if(int ~= getElementInterior(self.col)) then 
        setElementInterior(self.col, int) 
    end 
    if(dim ~= getElementDimension(self.col)) then 
        setElementDimension(self.col, dim) 
    end 
    
    setElementPosition(self.col, x, y, z); 
end 

It is defined a bit more down, in another function.

I am saying this again, it worked on my second server but not on my first. Is there any way that another script could intersect with this one and make it stop working?

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