Jump to content

How to put a code on the garages


Eelke

Recommended Posts

This is my meta file:

<meta> 
     <info author="Eelke" type="script" name="My Server" description="Garages" /> 
     <script src="script.lua" /> 
</meta> 

And this is my script.lua file

GARAGE_ID = 18 
  
-- create a collision shape and attach event handlers to it when the resource starts 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function (resource) 
    local garageCube = createColCube(1337, 194, 28, 6, 10, 4) 
    addEventHandler("onColShapeHit", garageCube, onGarageCubeHit) 
    addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave) 
end) 
  
-- open the door when someone enters the garage's collision shape 
function onGarageCubeHit(hitElement, matchingDimension) 
    if (getElementType(hitElement) == "player") then 
        -- check to make sure the door is closed 
        if (not isGarageOpen(GARAGE_ID)) then 
            -- open the door 
            setGarageOpen(GARAGE_ID, true) 
        end 
    end 
end 
  
-- close the door when someone leaves the garage's collision shape 
function onGarageCubeLeave(leaveElement, matchingDimension) 
    if (getElementType(leaveElement) == "player") then 
        -- check to make sure the door is open 
        if (isGarageOpen(GARAGE_ID)) then 
            -- close the door 
            setGarageOpen(GARAGE_ID, false) 
        end 
    end 
end 

But it doesn't open..

Link to comment

new link for you:

https://wiki.multitheftauto.com/wiki/Debugging

and example of debugging:

  
-- open the door when someone enters the garage's collision shape 
function onGarageCubeHit(hitElement, matchingDimension) 
    outputDebugString("something hit the sphere") 
    if (getElementType(hitElement) == "player") then 
        outputDebugString("it was player") 
        -- check to make sure the door is closed 
        outputDebugString("garage status:" ..tostring(isGarageOpen(GARAGE_ID))) 
        if (not isGarageOpen(GARAGE_ID)) then 
            outputDebugString("garage was closed") 
            -- open the door 
            local status = setGarageOpen(GARAGE_ID, true) 
            outputDebugString("status of openning garage:"..tostring(status)) 
        end 
    end 
end 
  

if you dont get even first debug message - the something wrong is with event handler or sphere.

also you need to define even handler function BEFORE adding the handler - not sure how it will behave in way you have it (adding handler on resource start, with functions below) - it's better to move onGarageCubeHit and onGarageCubeLeave BEFORE onResourceStart handler - more info on addEventHandler wiki page (search pls)

Link to comment
  • 4 months later...

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