Jump to content

Teleports


Twisted

Recommended Posts

Hello all i was wondering if you can help me fix something. I'm not getting errors just what ever Teleport i click inside the Grid list it teleports to the same place

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Grid = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.2884,0.2591,0.3909,0.6536,"Teleporter by Twisted",true) 
guiSetVisible(GUIEditor_Window[1],false) 
showCursor(false) 
GUIEditor_Grid[1] = guiCreateGridList(0.0562,0.1116,0.6161,0.8167,true,GUIEditor_Window[1]) 
guiGridListSetSelectionMode(GUIEditor_Grid[1],2) 
  
guiGridListAddColumn(GUIEditor_Grid[1],"Teleports",0.5) 
GUIEditor_Button[1] = guiCreateButton(0.6854,0.8327,0.2884,0.0916,"Close",true,GUIEditor_Window[1]) 
guiSetProperty(GUIEditor_Button[1],"NormalTextColor","FF00FF00") 
GUIEditor_Memo[1] = guiCreateMemo(0.6985,0.1355,0.2659,0.6713,"This teleporter script was made by Twisted and should not be shared without concent Copyrighted(C)  Double click the Teleporter u wish to Travel too \"{SMILIES_PATH}/icon_smile.gif\" alt=\"\" title=\"Smile\" />    ",true,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) 
  
function open() 
    if (guiGetVisible(GUIEditor_Window[1],true)) then 
    guiSetVisible(GUIEditor_Window[1],false) 
    showCursor(false) 
        else 
        guiSetVisible(GUIEditor_Window[1],true) 
        showCursor(true) 
    end 
end 
bindKey("F4","down",open) 
  
function close() 
    if (source == GUIEditor_Button[1]) then 
    guiSetVisible(GUIEditor_Window[1],false) 
    showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick",getRootElement(),close) 
  
  
function addTeleports() 
guiGridListClear(GUIEditor_Grid[1]) 
    if (guiGetVisible(GUIEditor_Window[1]) == true) then 
        local file = xmlLoadFile("Teleports.xml") 
        if file then 
        for i,v in ipairs(xmlNodeGetChildren(file)) do 
        local name = xmlNodeGetAttribute(v,"name") 
        local row = guiGridListAddRow(GUIEditor_Grid[1]) 
        guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring(name), false, true) 
        end 
        end 
    end 
end 
addEventHandler ("onClientRender",getRootElement() , addTeleports) 
       
function teleport() 
local file = xmlLoadFile("Teleports.xml") 
    if file then 
    for i,v in ipairs(xmlNodeGetChildren(file)) do 
    local poX = xmlNodeGetAttribute(v,"posX") 
    local poY = xmlNodeGetAttribute(v,"posY") 
    local poZ = xmlNodeGetAttribute(v,"posZ") 
    setElementPosition(getLocalPlayer(),tostring(poX),tostring(poY),tostring(poZ)) 
    outputChatBox("You have Teleported unharmed",255,255,255) 
    end 
    end 
end 
addEventHandler("onClientGUIDoubleClick",GUIEditor_Grid[1],teleport) 

<Teleports> 
<Teleports name="Santa Maria Beach" posX="302" posY="-1780" posZ="4"/> 
<Teleports name="Middle of map" posX="0" posY="0" posZ="3"/> 
</Teleports> 

No debug errors already checked.

Hope you can help me Thanks :)

Link to comment

Have you inserted the xml file in the meta?

And this:

setElementPosition(getLocalPlayer(),tostring(poX),tostring(poY),tostring(poZ)) 

should be like this:

setElementPosition(getLocalPlayer(),tonumber(poX),tonumber(poY),tonumber(poZ)) 

Look @ line 19 put this:

if (guiGetVisible(GUIEditor_Window[1])) then 

Link to comment
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Grid = {} 
  
GUIEditor_Window[1] = guiCreateWindow(0.2884,0.2591,0.3909,0.6536,"Teleporter by Twisted",true) 
guiSetVisible(GUIEditor_Window[1],false) 
showCursor(false) 
GUIEditor_Grid[1] = guiCreateGridList(0.0562,0.1116,0.6161,0.8167,true,GUIEditor_Window[1]) 
guiGridListSetSelectionMode(GUIEditor_Grid[1],1) 
guiGridListAddColumn(GUIEditor_Grid[1],"Teleports",0.5) 
GUIEditor_Button[1] = guiCreateButton(0.6854,0.8327,0.2884,0.0916,"Close",true,GUIEditor_Window[1]) 
guiSetProperty(GUIEditor_Button[1],"NormalTextColor","FF00FF00") 
GUIEditor_Memo[1] = guiCreateMemo(0.6985,0.1355,0.2659,0.6713,"This teleporter script was made by Twisted and should not be shared without concent Copyrighted(C)  Double click the Teleporter u wish to Travel too \"{SMILIES_PATH}/icon_smile.gif\" alt=\"\" title=\"Smile\" />    ",true,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) 
  
function open() 
    if (guiGetVisible(GUIEditor_Window[1],true)) then 
        guiSetVisible(GUIEditor_Window[1],false) 
        showCursor(false) 
    else 
        guiSetVisible(GUIEditor_Window[1],true) 
        showCursor(true) 
        addTeleports() 
    end 
end 
bindKey("F4","down",open) 
  
function close() 
    if (source == GUIEditor_Button[1]) then 
        guiSetVisible(GUIEditor_Window[1],false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick",getRootElement(),close) 
  
function addTeleports() 
guiGridListClear(GUIEditor_Grid[1]) 
    if (guiGetVisible(GUIEditor_Window[1]) == true) then 
        local file = xmlLoadFile("Teleports.xml") 
        if file then 
            for i,v in ipairs(xmlNodeGetChildren(file)) do 
                local name = xmlNodeGetAttribute(v,"name") 
                local row = guiGridListAddRow(GUIEditor_Grid[1]) 
                guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring(name), false, true) 
            end 
        end 
    end 
end 
  
function teleport() 
    local row,col = guiGridListGetSelectedItem(source) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local name = guiGridListGetItemText(source, row, 1) 
        local file = xmlLoadFile("Teleports.xml") 
        if file then 
            for i,v in ipairs(xmlNodeGetChildren(file)) do 
                local teleportName = xmlNodeGetAttribute(v,"name") 
                if (teleportName == name) then 
                    local poX = xmlNodeGetAttribute(v,"posX") 
                    local poY = xmlNodeGetAttribute(v,"posY") 
                    local poZ = xmlNodeGetAttribute(v,"posZ") 
                    setElementPosition(localPlayer, tonumber(poX), tonumber(poY), tonumber(poZ)) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientGUIDoubleClick",GUIEditor_Grid[1],teleport,false) 

Link to comment
GUIEditor_Window = { } 
GUIEditor_Button = { } 
GUIEditor_Memo = { } 
GUIEditor_Grid = { } 
  
GUIEditor_Window[1] = guiCreateWindow( 0.2884,0.2591,0.3909,0.6536,"Teleporter by Twisted",true ) 
guiSetVisible( GUIEditor_Window[1],false ) 
showCursor( false) 
GUIEditor_Grid[1] = guiCreateGridList( 0.0562,0.1116,0.6161,0.8167,true,GUIEditor_Window[1] ) 
guiGridListSetSelectionMode( GUIEditor_Grid[1],1 ) 
guiGridListAddColumn( GUIEditor_Grid[1],"Teleports",0.5) 
GUIEditor_Button[1] = guiCreateButton( 0.6854,0.8327,0.2884,0.0916,"Close",true,GUIEditor_Window[1] ) 
guiSetProperty( GUIEditor_Button[1],"NormalTextColor","FF00FF00" ) 
GUIEditor_Memo[1] = guiCreateMemo( 0.6985,0.1355,0.2659,0.6713,"This teleporter script was made by Twisted and should not be shared without concent Copyrighted(C)  Double click the Teleporter u wish to Travel too <!-- s:) --><img src=\"{SMILIES_PATH}/icon_smile.gif\" alt=\"\" title=\"Smile\" /><!-- s:) -->    ",true,GUIEditor_Window[1] ) 
guiMemoSetReadOnly( GUIEditor_Memo[1],true ) 
  
function open( ) 
    if guiGetVisible( GUIEditor_Window[1] ) then 
        guiSetVisible( GUIEditor_Window[1],false ) 
        showCursor( false ) 
    else 
        guiSetVisible( GUIEditor_Window[1],true ) 
        showCursor( true ) 
        addTeleports( ) 
    end 
end 
bindKey( "F4","down",open ) 
  
function close() 
    if source == GUIEditor_Button[1] then 
        guiSetVisible( GUIEditor_Window[1],false ) 
        showCursor( false ) 
    end 
end 
addEventHandler("onClientGUIClick",root,close) 
  
function addTeleports() 
    guiGridListClear( GUIEditor_Grid[1] ) 
    if guiGetVisible(GUIEditor_Window[1]) == true then 
        local file = xmlLoadFile "Teleports.xml" 
        if file then 
            for i,v in ipairs( xmlNodeGetChildren( file ) ) do 
                local name = xmlNodeGetAttribute( v,"name") 
                local row = guiGridListAddRow( GUIEditor_Grid[1] ) 
                guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring(name), false, true ) 
            end 
        end 
    end 
end 
  
function teleport( ) 
    local row,col = guiGridListGetSelectedItem( source ) 
    if row and col and row ~= -1 and col ~= -1 then 
        local name = guiGridListGetItemText( source, row, 1 ) 
        local file = xmlLoadFile "Teleports.xml" 
        if file then 
            for i,v in ipairs( xmlNodeGetChildren( file ) ) do 
                local teleportName = xmlNodeGetAttribute( v,"name" ) 
                if teleportName == name then 
                    local poX = xmlNodeGetAttribute( v,"posX" ) 
                    local poY = xmlNodeGetAttribute( v,"posY" ) 
                    local poZ = xmlNodeGetAttribute( v,"posZ" ) 
                    setElementPosition( getPedOccupiedVehicle( localPlayer ) or localPlayer, tonumber( poX ), tonumber( poY ), tonumber( poZ ) ) 
                end 
            end 
        end 
    end 
end 
addEventHandler( "onClientGUIDoubleClick",GUIEditor_Grid[1],teleport,false ) 

Updated again.

P.S

xmlLoadFile "Teleports.xml" -- this is not mistake we can call function if one argument and if it argument string 

xmlLoadFile [[Teleports.xml]] -- same 

http://www.lua.org/manual/5.1/manual.html

Link to comment
GUIEditor_Window = { } 
GUIEditor_Button = { } 
GUIEditor_Memo = { } 
GUIEditor_Grid = { } 
  
GUIEditor_Window[1] = guiCreateWindow( 0.2884,0.2591,0.3909,0.6536,"Teleporter by Twisted",true ) 
guiSetVisible( GUIEditor_Window[1],false ) 
showCursor( false) 
GUIEditor_Grid[1] = guiCreateGridList( 0.0562,0.1116,0.6161,0.8167,true,GUIEditor_Window[1] ) 
guiGridListSetSelectionMode( GUIEditor_Grid[1],1 ) 
guiGridListAddColumn( GUIEditor_Grid[1],"Teleports",0.5) 
GUIEditor_Button[1] = guiCreateButton( 0.6854,0.8327,0.2884,0.0916,"Close",true,GUIEditor_Window[1] ) 
guiSetProperty( GUIEditor_Button[1],"NormalTextColor","FF00FF00" ) 
GUIEditor_Memo[1] = guiCreateMemo( 0.6985,0.1355,0.2659,0.6713,"This teleporter script was made by Twisted and should not be shared without concent Copyrighted(C)  Double click the Teleporter u wish to Travel too <!-- s:) --><img src=\"{SMILIES_PATH}/icon_smile.gif\" alt=\"\" title=\"Smile\" /><!-- s:) -->    ",true,GUIEditor_Window[1] ) 
guiMemoSetReadOnly( GUIEditor_Memo[1],true ) 
  
function open( ) 
    if guiGetVisible( GUIEditor_Window[1] ) then 
        guiSetVisible( GUIEditor_Window[1],false ) 
        showCursor( false ) 
    else 
        guiSetVisible( GUIEditor_Window[1],true ) 
        showCursor( true ) 
        addTeleports( ) 
    end 
end 
bindKey( "F4","down",open ) 
  
function close() 
    if source == GUIEditor_Button[1] then 
        guiSetVisible( GUIEditor_Window[1],false ) 
        showCursor( false ) 
    end 
end 
addEventHandler("onClientGUIClick",root,close) 
  
function addTeleports() 
    guiGridListClear( GUIEditor_Grid[1] ) 
    if guiGetVisible(GUIEditor_Window[1]) == true then 
        local file = xmlLoadFile "Teleports.xml" 
        if file then 
            for i,v in ipairs( xmlNodeGetChildren( file ) ) do 
                local name = xmlNodeGetAttribute( v,"name") 
                local row = guiGridListAddRow( GUIEditor_Grid[1] ) 
                guiGridListSetItemText ( GUIEditor_Grid[1], row, 1, tostring(name), false, true ) 
            end 
        end 
    end 
end 
  
function teleport( ) 
    local row,col = guiGridListGetSelectedItem( source ) 
    if row and col and row ~= -1 and col ~= -1 then 
        local name = guiGridListGetItemText( source, row, 1 ) 
        local file = xmlLoadFile "Teleports.xml" 
        if file then 
            for i,v in ipairs( xmlNodeGetChildren( file ) ) do 
                local teleportName = xmlNodeGetAttribute( v,"name" ) 
                if teleportName == name then 
                    local poX = xmlNodeGetAttribute( v,"posX" ) 
                    local poY = xmlNodeGetAttribute( v,"posY" ) 
                    local poZ = xmlNodeGetAttribute( v,"posZ" ) 
                    setElementPosition( getPedOccupiedVehicle( localPlayer ) or localPlayer, tonumber( poX ), tonumber( poY ), tonumber( poZ + 2 ) ) 
                end 
            end 
        end 
    end 
end 
addEventHandler( "onClientGUIDoubleClick",GUIEditor_Grid[1],teleport,false ) 

Just poZ + 2.Regulate it if needed.( line 63 )

Or you can use function getGroundPosition.

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