Jump to content

Script Help


Recommended Posts

Hii There ,,

I add teleports resources .. but it doesn't works.. Can someone tell me where is the error ?

This is Server side

mysql = exports.mysql 
local addCommandHandler_ = addCommandHandler 
      addCommandHandler  = function( commandName, fn, restricted, caseSensitive ) 
    -- add the default command handlers 
    if type( commandName ) ~= "table" then 
        commandName = { commandName } 
    end 
    for key, value in ipairs( commandName ) do 
        if key == 1 then 
            addCommandHandler_( value, fn, restricted, caseSensitive ) 
        else 
            addCommandHandler_( value, 
                function( player, ... ) 
                    -- check if he has permissions to execute the command, default is not restricted (aka if the command is restricted - will default to no permission; otherwise okay) 
                    if hasObjectPermissionTo( player, "command." .. commandName[ 1 ], not restricted ) then 
                        fn( player, ... ) 
                    end 
                end 
            ) 
        end 
    end 
     
    -- check for alternative handlers, such as createinterior = createint 
    for k, v in ipairs( commandName ) do 
        if v:find( "teleport" ) then 
            for key, value in pairs( { "tp" } ) do 
                local newCommand = v:gsub( "teleport", value ) 
                if newCommand ~= v then 
                    -- add a second (replaced) command handler 
                    addCommandHandler_( newCommand, 
                        function( player, ... ) 
                            -- check if he has permissions to execute the command, default is not restricted (aka if the command is restricted - will default to no permission; otherwise okay) 
                            if hasObjectPermissionTo( player, "command." .. commandName[ 1 ], not restricted ) then 
                                fn( player, ... ) 
                            end 
                        end 
                    ) 
                end 
            end 
        end 
    end 
end 
  
-- 
  
local colspheres = { } 
local teleports = { } 
  
local function loadTeleport( id, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ, bInterior, bDimension ) 
    local a = createColSphere( aX, aY, aZ, 1 ) 
    setElementInterior( a, aInterior ) 
    setElementDimension( a, aDimension ) 
     
    local b = createColSphere( bX, bY, bZ, 1 ) 
    setElementInterior( b, bInterior ) 
    setElementDimension( b, bDimension ) 
     
    -- save for further reference 
    colspheres[ a ] = { id = id, other = b } 
    colspheres[ b ] = { id = id, other = a } 
    teleports[ id ] = { a = a, b = b } 
end 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        if not exports.mysql:create_table( 'teleports', 
            { 
                { name = 'teleportID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, 
                { name = 'aX', type = 'float' }, 
                { name = 'aY', type = 'float' }, 
                { name = 'aZ', type = 'float' }, 
                { name = 'aInterior', type = 'tinyint(3) unsigned' }, 
                { name = 'aDimension', type = 'int(10) unsigned' }, 
                { name = 'bX', type = 'float' }, 
                { name = 'bY', type = 'float' }, 
                { name = 'bZ', type = 'float' }, 
                { name = 'bInterior', type = 'tinyint(3) unsigned' }, 
                { name = 'bDimension', type = 'int(10) unsigned' }, 
            } ) then cancelEvent( ) return end 
         
        -- 
         
        local result = exports.mysql:query_assoc( "SELECT * FROM teleports" ) 
        for key, value in ipairs( result ) do 
            loadTeleport( value.teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension ) 
        end 
    end 
) 
  
-- 
  
local p = { } 
  
addEventHandler( "onPlayerQuit", root, 
    function( ) 
        p[ source ] = nil 
    end 
) 
  
addCommandHandler( "markteleport", 
    function( player ) 
        -- this command only makes sense if used with /createteleport 
        if hasObjectPermissionTo( player, "command.createteleport", false ) then 
            -- get all properties we need 
            local x, y, z = getElementPosition( player ) 
            x = math.ceil( x * 100 ) / 100 
            y = math.ceil( y * 100 ) / 100 
            z = math.ceil( z * 100 ) / 100 
            local interior = getElementInterior( player ) 
            local dimension = getElementDimension( player ) 
             
            -- save them 
            if not p[ player ] then 
                p[ player ] = { } 
            end 
            p[ player ].mark = { x = x, y = y, z = z, interior = interior, dimension = dimension } 
             
            -- 
             
            outputChatBox( "Marked teleport position. [" .. table.concat( { "x=" .. x, "y=" .. y, "z=" .. z, "i=" .. interior, "d=" .. dimension }, ", " ) .. "]", player, 0, 255, 153 ) 
        end 
    end 
) 
  
addCommandHandler( "createteleport", 
    function( player, commandName ) 
        local a = p[ player ] and p[ player ].mark 
        if a then 
            local x, y, z = getElementPosition( player ) 
            x = math.ceil( x * 100 ) / 100 
            y = math.ceil( y * 100 ) / 100 
            z = math.ceil( z * 100 ) / 100 
            local interior = getElementInterior( player ) 
            local dimension = getElementDimension( player ) 
             
            local insertid, e = exports.mysql:query_insertid( "INSERT INTO teleports (`aX`, `aY`, `aZ`, `aInterior`, `aDimension`, `bX`, `bY`, `bZ`, `bInterior`, `bDimension`) VALUES (" .. table.concat( { a.x, a.y, a.z, a.interior, a.dimension, x, y, z, interior, dimension }, ", " ) .. ")" ) 
            if insertid then 
                loadTeleport( insertid, a.x, a.y, a.z, a.interior, a.dimension, x, y, z, interior, dimension) 
                outputChatBox( "Teleport created. (ID " .. insertid .. ")", player, 0, 255, 0 ) 
                 
                -- delete the marked position 
                p[ player ].mark = nil 
            else 
                outputChatBox( "MySQL-Query failed.", player, 255, 0, 0 ) 
            end 
        else 
            outputChatBox( "You need to set the opposite spot with /markteleport first.", player, 255, 0, 0 ) 
        end 
    end, 
    true 
) 
  
addCommandHandler( { "deleteteleport", "delteleport" }, 
    function( player, commandName, teleportID ) 
        teleportID = tonumber( teleportID ) 
        if teleportID then 
            local teleport = teleports[ teleportID ] 
            if teleport then 
                if exports.sql:query_free( "DELETE FROM teleports WHERE teleportID = " .. teleportID ) then 
                    outputChatBox( "You deleted teleport " .. teleportID .. ".", player, 0, 255, 153 ) 
                     
                    -- delete the markers 
                    colspheres[ teleport.a ] = nil 
                    destroyElement( teleport.a ) 
                    colspheres[ teleport.b ] = nil 
                    destroyElement( teleport.b ) 
                else 
                    outputChatBox( "MySQL-Query failed.", player, 255, 0, 0 ) 
                end 
            else 
                outputChatBox( "Teleport not found.", player, 255, 0, 0 ) 
            end 
        else 
            outputChatBox( "Syntax: /" .. commandName .. " [id]", player, 255, 255, 255 ) 
        end 
    end, 
    true 
) 
  
addCommandHandler( "nearbyteleports", 
    function( player, commandName ) 
        if hasObjectPermissionTo( player, "command.createteleport", false ) or hasObjectPermissionTo( player, "command.deleteteleport", false ) then 
            local x, y, z = getElementPosition( player ) 
            local dimension = getElementDimension( player ) 
            local interior = getElementInterior( player ) 
             
            outputChatBox( "Nearby Teleports:", player, 255, 255, 0 ) 
            for key, value in pairs( colspheres ) do 
                if getElementDimension( key ) == dimension and getElementInterior( key ) == interior then 
                    local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( key ) ) 
                    if distance < 20 then 
                        outputChatBox( "  Teleport " .. value.id .. ".", player, 255, 255, 0 ) 
                    end 
                end 
            end 
        end 
    end 
) 
  
-- 
  
local function useTeleport( player, key, state, colShape ) 
    local data = colspheres[ colShape ] 
    if data then 
        local other = data.other 
        if other then 
            triggerEvent( "onColShapeLeave", colShape, player, true ) 
            -- teleport the player 
            setElementDimension( player, getElementDimension( other ) ) 
            setElementInterior( player, getElementInterior( other ) ) 
            setCameraInterior( player, getElementInterior( other ) ) 
            setElementPosition( player, getElementPosition( other ) ) 
            setCameraTarget( player, player ) 
             
            triggerEvent( "onColShapeHit", other, player, true ) 
        end 
    end 
end 
  
addEventHandler( "onColShapeHit", resourceRoot, 
    function( element, matching ) 
        if matching and getElementType( element ) == "player" then 
            if not p[ element ] then 
                p[ element ] = { } 
            elseif p[ element ].tp then 
                unbindKey( element, "enter_exit", "down", useTeleport, p[ element ].tp ) 
            end 
             
            p[ element ].tp = source 
            bindKey( element, "enter_exit", "down", useTeleport, p[ element ].tp ) 
            setElementData( element, "interiorMarker", true, false ) 
        end 
    end 
) 
  
addEventHandler( "onColShapeLeave", resourceRoot, 
    function( element, matching ) 
        if matching and getElementType( element ) == "player" then 
            if not p[ element ].tp then 
                p[ element ].tp = { } 
            else 
            unbindKey( element, "enter_exit", "down", useTeleport, p[ element ].tp ) 
            removeElementData( element, "interiorMarker", true, false ) 
            p[ element ].tp = nil 
        end 
    end 
end 
) 
  

This is client side

--[[ 
Copyright (c) 2010 MTA: Paradise 
  
This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 3 of the License, or 
(at your option) any later version. 
  
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
GNU General Public License for more details. 
  
You should have received a copy of the GNU General Public License 
along with this program. If not, see . 
]] 
  
local localPlayer = getLocalPlayer( ) 
local pickups = { } 
  
local function destroy( colshape ) 
    if pickups[ colshape ] then 
        destroyElement( pickups[ colshape ].pickup ) 
        pickups[ colshape ] = nil 
    end 
end 
  
addEventHandler( "onClientRender", getRootElement( ), 
    function( ) 
        -- get the camera matrix 
        local cx, cy, cz = getCameraMatrix( ) 
         
        -- loop through all vehicles you can buy 
        local dimension = getElementDimension( localPlayer ) 
        for key, colshape in ipairs ( getElementsByType( "colshape", resourceRoot ) ) do 
            if getElementDimension( colshape ) == dimension then 
                local px, py, pz = getElementPosition( colshape ) 
                local distance = getDistanceBetweenPoints3D( px, py, pz, cx, cy, cz ) 
                if distance <= 17.5 then 
                    -- pickup to it 
                    if not pickups[ colshape ] then 
                        pickup = createPickup( px, py, pz, 3, 1318 ) 
                        setElementInterior( pickup, getElementInterior( localPlayer ) ) 
                        setElementDimension( pickup, dimension ) 
                         
                        pickups[ colshape ] = { pickup = pickup } 
                    end 
                else 
                    destroy( colshape ) 
                end 
            else 
                destroy( colshape ) 
            end 
        end 
    end 
) 
  
addEventHandler( "onClientElementDestroy", resourceRoot, 
    function( ) 
        destroy( source ) 
    end 
) 
  

This Script made by Mabako..

Thanks For Help ...

Link to comment

It is funny how you expect a single resource, belonging to a whole game mode, to be compatible with your own server. No, it is not going to work, and we also are not going to give you help as you copy and paste the raw code the resource has in it. Figure it out yourself by learning how to script; debug the code and find out what is causing the problem. I am certain it is the exports, as you do not have all the scripts on your server.

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