Jump to content

Whats Wrong with this Script?


Aaron97

Recommended Posts

Posted

Hey Guys,

 

Im trying to make a working ACL gate script and I cant see what the issue is;

Please take a look and let me know.

-- team, object model, position and rotation, move to position

local gates =

    { "EXAMPLE", 2930, { 257.899, 1871.800, 10.39, 0, 0, 0 }, { 257.899, 1871.800, 13, } },

    { "EXAMPLE", 2930, { 257.899, 1867.900, 10.39, 0, 0, 0 }, { 257.899, 1867.900, 13, } },
		
	{ "EXAMPLE", 2930, { 257.899, 1863, 10.39, 0, 0, 0 }, { 257.899, 1863, 13, } },
		
	{ "EXAMPLE", 2930, { 257.899, 1860, 10.39, 0, 0, 0 }, { 257.899, 1860, 13 } },
		
	{ "EXAMPLE", 2930, { 257.899, 1856.099, 10.39, 0, 0, 0 }, { 257.899, 1856.099, 13 } },
		
	{ "EXAMPLE", 2930, { 257.899, 1852.400, 10.39, 0, 0, 0 }, { 257.899, 1852.400, 13 } }, 
		
	{ "EXAMPLE", 3037, { 256.399, 1843.699, 9.899, 0, 0, 0 }, { 256.399, 1843.699, 12.6 } },
		
	{ "EXAMPLE", 5422, { 248.899, 1841.900, 9.800, 0, 0, 270 }, { 248.899, 1841.900, 12.3 } },
		
	{ "EXAMPLE", 2930, { 240, 1846.599, 10.399, 0, 0, 270 }, { 240, 1846.599, 12.7 } },
    }

local gateData = { } -- A table to store the gates data

addEventHandler ( "onResourceStart", resourceRoot,

    function ( )
        for _, data in ipairs ( gates ) do -- Loop our gates table

            local team, model, posRot, moveTo = unpack ( data ) -- Unpack the gate data

            local x, y, z, rx, ry, rz = unpack ( posRot ) -- Unpack the gate position and rotation

            local mx, my, mz = unpack ( moveTo ) -- Unpack the position to where it has to move

            local object = createObject ( model, x, y, z, rx, ry, rz ) -- Create the gate object

            local colshape = createColTube ( x, y, z - 1, 2, 2 ) -- Create the gate colshape

            if ( colshape ) then -- If the colshape was created

                addEventHandler ( "onColShapeHit", colshape, onGateColshape ) -- Add the event handler for when hit the colshape

                addEventHandler ( "onColShapeLeave", colshape, onGateColshape ) -- Add the event handler for when leave the colshape

                gateData [ colshape ] = -- Use the colshape as index to store the gate data

                    {

                        object = object,

                        team = team,

                        x = x,

                        y = y,

                        z = z,

                        mx = mx,

                        my = my,

                        mz = mz

                    }

            end

        end

    end
}

function onGateColshape ( hitElement, matchD )

    if ( matchD ) then -- If the dimension matches

        local data = gateData [ source ] -- Get the gate data using the colshape as index ( source )

        if ( data ) then -- If there was data

            local team = getPlayerTeam ( hitElement ) -- Get the player team

            local teamName = ( team and getTeamName ( team ) or "" ) -- Get the team name

            if ( teamName == data.team ) then -- If the player team matches the gate team

                if ( eventName == "onColShapeHit" ) then -- If the event name is 'onColShapeHit'

                    moveObject ( data.object, 2200, data.mx, data.my, data.mz ) -- Open the gate

                else -- If the event name is 'onColShapeLeave'

                    moveObject ( data.object, 2200, data.x, data.y, data.z ) -- Close the gate

                end

            end

        end

    end

end

Any suggestions would be great..

 

Thanks

Aaron

Posted

Whats not working with it?

Working for me:
 

Spoiler

-- team, object model, position and rotation, move to position
local gates = {
    {"EXAMPLE", 2930, {257.899, 1871.800, 10.39, 0, 0, 0}, {257.899, 1871.800, 13,}},
    {"EXAMPLE", 2930, {257.899, 1867.900, 10.39, 0, 0, 0}, {257.899, 1867.900, 13,}},
	{"EXAMPLE", 2930, {257.899, 1863, 10.39, 0, 0, 0}, {257.899, 1863, 13, }},
	{"EXAMPLE", 2930, {257.899, 1860, 10.39, 0, 0, 0}, {257.899, 1860, 13 }},
	{"EXAMPLE", 2930, {257.899, 1856.099, 10.39, 0, 0, 0}, {257.899, 1856.099, 13}},
	{"EXAMPLE", 2930, {257.899, 1852.400, 10.39, 0, 0, 0}, {257.899, 1852.400, 13}}, 
	{"EXAMPLE", 3037, {256.399, 1843.699, 9.899, 0, 0, 0}, {256.399, 1843.699, 12.6}},
	{"EXAMPLE", 5422, {248.899, 1841.900, 9.800, 0, 0, 270}, {248.899, 1841.900, 12.3}},	
	{"EXAMPLE", 2930, {240, 1846.599, 10.399, 0, 0, 270}, {240, 1846.599, 12.7}}
}

local gateData = { } -- A table to store the gates data

addEventHandler ( "onResourceStart", resourceRoot,
    function ( )
        for _, data in ipairs ( gates ) do -- Loop our gates table
            local team, model, posRot, moveTo = unpack ( data ) -- Unpack the gate data
            local x, y, z, rx, ry, rz = unpack ( posRot ) -- Unpack the gate position and rotation
            local mx, my, mz = unpack ( moveTo ) -- Unpack the position to where it has to move
            local object = createObject ( model, x, y, z, rx, ry, rz ) -- Create the gate object
            local colshape = createColTube ( x, y, z - 2, 2, 2 ) -- Create the gate colshape
            if ( colshape ) then -- If the colshape was created
                addEventHandler ( "onColShapeHit", colshape, onGateColshape ) -- Add the event handler for when hit the colshape
                addEventHandler ( "onColShapeLeave", colshape, onGateColshape ) -- Add the event handler for when leave the colshape
                gateData [ colshape ] = -- Use the colshape as index to store the gate data
                    {
                        object = object,
                        team = team,
                        x = x,
                        y = y,
                        z = z,
                        mx = mx,
                        my = my,
                        mz = mz
                    }
            end
        end
    end
)

function onGateColshape ( hitElement, matchD )
    if ( matchD ) then -- If the dimension matches
        local data = gateData [ source ] -- Get the gate data using the colshape as index ( source )
        if ( data ) then -- If there was data
            local team = getPlayerTeam ( hitElement ) -- Get the player team
            local teamName = ( team and getTeamName ( team ) or "" ) -- Get the team name
            if ( teamName == data.team ) then -- If the player team matches the gate team
                if ( eventName == "onColShapeHit" ) then -- If the event name is 'onColShapeHit'
                    moveObject ( data.object, 2200, data.mx, data.my, data.mz ) -- Open the gate
                else -- If the event name is 'onColShapeLeave'
                    moveObject ( data.object, 2200, data.x, data.y, data.z ) -- Close the gate
                end
            end
        end
    end
end

 

Posted (edited)
34 minutes ago, NeXuS™ said:

Whats not working with it?

Working for me:
 

  Hide contents


 
-- team, object model, position and rotation, move to position
local gates = {
    {"EXAMPLE", 2930, {257.899, 1871.800, 10.39, 0, 0, 0}, {257.899, 1871.800, 13,}},
    {"EXAMPLE", 2930, {257.899, 1867.900, 10.39, 0, 0, 0}, {257.899, 1867.900, 13,}},
	{"EXAMPLE", 2930, {257.899, 1863, 10.39, 0, 0, 0}, {257.899, 1863, 13, }},
	{"EXAMPLE", 2930, {257.899, 1860, 10.39, 0, 0, 0}, {257.899, 1860, 13 }},
	{"EXAMPLE", 2930, {257.899, 1856.099, 10.39, 0, 0, 0}, {257.899, 1856.099, 13}},
	{"EXAMPLE", 2930, {257.899, 1852.400, 10.39, 0, 0, 0}, {257.899, 1852.400, 13}}, 
	{"EXAMPLE", 3037, {256.399, 1843.699, 9.899, 0, 0, 0}, {256.399, 1843.699, 12.6}},
	{"EXAMPLE", 5422, {248.899, 1841.900, 9.800, 0, 0, 270}, {248.899, 1841.900, 12.3}},	
	{"EXAMPLE", 2930, {240, 1846.599, 10.399, 0, 0, 270}, {240, 1846.599, 12.7}}
}

local gateData = { } -- A table to store the gates data

addEventHandler ( "onResourceStart", resourceRoot,
    function ( )
        for _, data in ipairs ( gates ) do -- Loop our gates table
            local team, model, posRot, moveTo = unpack ( data ) -- Unpack the gate data
            local x, y, z, rx, ry, rz = unpack ( posRot ) -- Unpack the gate position and rotation
            local mx, my, mz = unpack ( moveTo ) -- Unpack the position to where it has to move
            local object = createObject ( model, x, y, z, rx, ry, rz ) -- Create the gate object
            local colshape = createColTube ( x, y, z - 2, 2, 2 ) -- Create the gate colshape
            if ( colshape ) then -- If the colshape was created
                addEventHandler ( "onColShapeHit", colshape, onGateColshape ) -- Add the event handler for when hit the colshape
                addEventHandler ( "onColShapeLeave", colshape, onGateColshape ) -- Add the event handler for when leave the colshape
                gateData [ colshape ] = -- Use the colshape as index to store the gate data
                    {
                        object = object,
                        team = team,
                        x = x,
                        y = y,
                        z = z,
                        mx = mx,
                        my = my,
                        mz = mz
                    }
            end
        end
    end
)

function onGateColshape ( hitElement, matchD )
    if ( matchD ) then -- If the dimension matches
        local data = gateData [ source ] -- Get the gate data using the colshape as index ( source )
        if ( data ) then -- If there was data
            local team = getPlayerTeam ( hitElement ) -- Get the player team
            local teamName = ( team and getTeamName ( team ) or "" ) -- Get the team name
            if ( teamName == data.team ) then -- If the player team matches the gate team
                if ( eventName == "onColShapeHit" ) then -- If the event name is 'onColShapeHit'
                    moveObject ( data.object, 2200, data.mx, data.my, data.mz ) -- Open the gate
                else -- If the event name is 'onColShapeLeave'
                    moveObject ( data.object, 2200, data.x, data.y, data.z ) -- Close the gate
                end
            end
        end
    end
end

 

When I start the resource on my MTA Server nothing loads althought it says the resource is running.

Edited by Aaron97
Posted

I know ignore that lol, my bad

9 minutes ago, NeXuS™ said:

Alright, you quoted me, but didnt write anything. :D@Aaron97

Just double checked this script and it loads the objects in game but doesnt move when a player in that ACL approaches.

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