TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 (edited) I used too but thought it was best to use db etc. instead Edit:- Last 1 he posted, debugger cry's like a baby at it lol Edited January 3, 2012 by Guest Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 mysql module in more functional all the same Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 I know it is but that's bit off topic Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 Night, post the code, I lost track of what you're trying to do. Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Okay no worries 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 local key = dbConnect( "sqlite", "Storedinfo.db" ) addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) ) local returnedData = dbPoll ( dbQuery ( key , "SELECT * FROM table" ), -1 )-- this 1 has syntax error local result = dbPoll ( dbQuery( key, "SELECT * FROM teleports" ),-1 ) end ) --for key, value in ipairs( result ) do -- dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) local p = { } addEventHandler( "onPlayerQuit", root, function( ) p[ source ] = nil end ) addCommandHandler( "marktele", 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( "createtele", 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 = dbQuery( "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( "SQL-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 dbQuery ("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( "DB-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 getElementType( element ) == "player" and p[ element ].tp then unbindKey( element, "enter_exit", "down", useTeleport, p[ element ].tp ) removeElementData( element, "interiorMarker", true, false ) p[ element ].tp = nil end end ) Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbExec( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) local result = dbPoll ( dbQuery( key, "SELECT * FROM teleports" ),-1 ) end ) --for key, value in ipairs( result ) do -- dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) local p = { } addEventHandler( "onPlayerQuit", root, function( ) p[ source ] = nil end ) addCommandHandler( "marktele", 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( "createtele", 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 ) dbExec(key, "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( "SQL-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 dbExec ("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( "DB-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 getElementType( element ) == "player" and p[ element ].tp then unbindKey( element, "enter_exit", "down", useTeleport, p[ element ].tp ) removeElementData( element, "interiorMarker", true, false ) p[ element ].tp = nil end end ) Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 ok /debugscript 3? Of course am using debugscript 3 Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 OKay mate and thanks again. Link to comment
TheNightRider Posted January 4, 2012 Author Share Posted January 4, 2012 Okay cool and I looked at the code you wrote the debugger said bad argument at line 77 expected string got table the other problem I found it isn't creating any tables etc. in the db file. addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbExec( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) local result = dbPoll ( dbQuery( key, "SELECT * FROM teleports" ),-1 ) end ) Link to comment
JR10 Posted January 4, 2012 Share Posted January 4, 2012 Was it creating the table with dbQuery? addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree(dbQuery( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) local result = dbPoll ( dbQuery( key, "SELECT * FROM teleports" ),-1 ) end ) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now