Jump to content

teleport script


Loren_ita

Recommended Posts

I'm learning how to script in mta.

When i click with the cursor che marker isn't where i click. It appears another place of the map. why? :(

I have copyed this script from mta site and edited it..

Client side:

function Script1 ()
  bindKey( "I", "down", modeIO )
end
 
function modeIO ( source, key, keyState )						--This function toggles the cursor on/off
if isCursorShowing ( source ) then						--If cursor was already showing,
	showCursor ( false )						--then hide it;
else										--if it wasn't showing,
	showCursor ( true ) 						--then show it.
   end
end
 
function Script4 ( key, keyState, element, x, y, z )
   --if keyState == "up" then return end						--Don't do anything if he's releasing the button.
if key == "left" then
    local del = getElementData ( source, "teleport" )								--If it's left-click:
	destroyElement ( del )
	local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
	local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 0, 50 )	--Create a cylindric marker
	setElementData ( theMarker, "type", teleport )				--Mark the cylinder as a teleport
	setElementData ( source, "teleport", theMarker )				--Link the creator to the teleport
	setElementData ( theMarker, "owner", source )				--Link the teleport to its creator
 
elseif key == "right" then							--If it's right-click
    local del = getElementData ( source, "destination" )								--If it's left-click:
	destroyElement ( del )		--Destroy his destination point, if any
	local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
	local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 255, 50 )	--Create a glowing corona
	setElementData ( theMarker, "type", destination )			--Mark the corona as a destination point
	setElementData ( source,"destination", theMarker )			--Link the creator to the teleport
	setElementData ( theMarker, "owner", source )				--Link the teleport to its creator
	end
end
 
	--This event tells what happens if a player steps inside a marker.
function Script5 ( player )
if getElementData ( source, "type" ) == teleport then				--If the marker is a teleport point,
	local owner = getElementData ( source, "owner" )			--Get the owner linked to the teleport point.
	local destination = getElementData ( owner, "destination" )		--Get the destination point linked to the owner.
	if destination then							--If destination point exists,
		local x, y, z = getElementPosition ( destination )		--Get the destination point's position.
		setElementPosition ( thePlayer, x, y, z )				--Put the player there.
	end
end
end
 
--This event tells what happens if a player disconnects.
function Script2 ( reason )
destroyElement ( getElementData ( source, "teleport" ) )			--Destroy his teleport point, if any
destroyElement ( getElementData ( source, "destination" ) )			--Destroy his destination point, if any
end
 
addEventHandler ( "onClientResourceStart", getRootElement(), Script1 )
addEventHandler ( "onClientPlayerQuit", getRootElement(), Script2 )
addEventHandler ( "onClientClick", getRootElement(), Script4 )
addEventHandler ( "onClientMarkerHit", getRootElement(), Script5 )

Please help my!

Link to comment

I'm learning how to script in mta.

When i click with the cursor che marker isn't where i click. It appears another place of the map. why? :(

I have copyed this script from mta site and edited it..

Client side:

function Script1 ()   bindKey( "I", "down", modeIO )end function modeIO ( source, key, keyState )						--This function toggles the cursor on/off	if isCursorShowing ( source ) then						--If cursor was already showing,		showCursor ( false )						--then hide it;	else										--if it wasn't showing,		showCursor ( true ) 						--then show it.    endend function Script4 ( key, keyState, element, x, y, z )    --if keyState == "up" then return end						--Don't do anything if he's releasing the button.	if key == "left" then	    local del = getElementData ( source, "teleport" )								--If it's left-click:		destroyElement ( del )		local screenx, screeny, worldx, worldy, worldz = getCursorPosition()		local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 0, 50 )	--Create a cylindric marker		setElementData ( theMarker, "type", teleport )				--Mark the cylinder as a teleport		setElementData ( source, "teleport", theMarker )				--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	elseif key == "right" then							--If it's right-click	    local del = getElementData ( source, "destination" )								--If it's left-click:		destroyElement ( del )		--Destroy his destination point, if any		local screenx, screeny, worldx, worldy, worldz = getCursorPosition()		local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 255, 50 )	--Create a glowing corona		setElementData ( theMarker, "type", destination )			--Mark the corona as a destination point		setElementData ( source,"destination", theMarker )			--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	endend 		--This event tells what happens if a player steps inside a marker.function Script5 ( player )	if getElementData ( source, "type" ) == teleport then				--If the marker is a teleport point,		local owner = getElementData ( source, "owner" )			--Get the owner linked to the teleport point.		local destination = getElementData ( owner, "destination" )		--Get the destination point linked to the owner.		if destination then							--If destination point exists,			local x, y, z = getElementPosition ( destination )		--Get the destination point's position.			setElementPosition ( thePlayer, x, y, z )				--Put the player there.		end	endend 	--This event tells what happens if a player disconnects.function Script2 ( reason )	destroyElement ( getElementData ( source, "teleport" ) )			--Destroy his teleport point, if any	destroyElement ( getElementData ( source, "destination" ) )			--Destroy his destination point, if anyend addEventHandler ( "onClientResourceStart", getRootElement(), Script1 )addEventHandler ( "onClientPlayerQuit", getRootElement(), Script2 )addEventHandler ( "onClientClick", getRootElement(), Script4 )addEventHandler ( "onClientMarkerHit", getRootElement(), Script5 )

Please help my!

Link to comment

Please say which script did you take it from because someone who made it was at similar scripting level as you are. (Function names Script1, Script2, etc. wtf?)

-- Change this:
function Script4 ( key, keyState, element, x, y, z )
-- To this:
function Script4 ( key, _, _, _, x, y, z ) -- you don't need keystate, nor absolute screen coords but you need world x, y and z
-------------------------------------------------------
-- Change this
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 0, 50 )
-- To this:
local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )

Link to comment

Please say which script did you take it from because someone who made it was at similar scripting level as you are. (Function names Script1, Script2, etc. wtf?)

-- Change this:function Script4 ( key, keyState, element, x, y, z )-- To this:function Script4 ( key, _, _, _, x, y, z ) -- you don't need keystate, nor absolute screen coords but you need world x, y and z--------------------------------------------------------- Change this      local screenx, screeny, worldx, worldy, worldz = getCursorPosition()      local theMarker = createMarker ( worldx, worldy, worldz, cylinder, 1.5, 1, 255, 0, 50 )-- To this:      local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )

Link to comment

Ok now script work but when i enter in a marker it don't teleport...

I have downloaded the script tutorial N° 1 from mta web site. http://www.mtasa.com/tutorial1.html

Now the script is:

function Binding ()
  bindKey( "I", "down", modeIO )
end
 
function modeIO ( source, key, keyState )						--This function toggles the cursor on/off
if isCursorShowing ( source ) then						--If cursor was already showing,
	showCursor ( false )						--then hide it;
else										--if it wasn't showing,
	showCursor ( true ) 						--then show it.
   end
end
 
function OnClick ( key, _, _, _, x, y, z )
   --if keyState == "up" then return end						--Don't do anything if he's releasing the button.
if key == "left" then
    local del = getElementData ( source, "teleport" )								--If it's left-click:
	destroyElement ( del )
       local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )--Create a cylindric marker
	setElementData ( theMarker, "type", teleport )				--Mark the cylinder as a teleport
	setElementData ( source, "teleport", theMarker )				--Link the creator to the teleport
	setElementData ( theMarker, "owner", source )				--Link the teleport to its creator
 
elseif key == "right" then							--If it's right-click
    local del = getElementData ( source, "destination" )								--If it's left-click:
	destroyElement ( del )		--Destroy his destination point, if any
	local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 255, 50 )	--Create a glowing corona
	setElementData ( theMarker, "type", destination )			--Mark the corona as a destination point
	setElementData ( source,"destination", theMarker )			--Link the creator to the teleport
	setElementData ( theMarker, "owner", source )				--Link the teleport to its creator
	end
end
 
	--This event tells what happens if a player steps inside a marker.
function MarkerHit ( player )
if getElementData ( source, "type" ) == teleport then				--If the marker is a teleport point,
	local owner = getElementData ( source, "owner" )			--Get the owner linked to the teleport point.
	local destination = getElementData ( owner, "destination" )		--Get the destination point linked to the owner.
	if destination then							--If destination point exists,
		local x, y, z = getElementPosition ( destination )		--Get the destination point's position.
		setElementPosition ( thePlayer, x, y, z )				--Put the player there.
	end
end
end
 
--This event tells what happens if a player disconnects.
function Quit ( reason )
destroyElement ( getElementData ( source, "teleport" ) )			--Destroy his teleport point, if any
destroyElement ( getElementData ( source, "destination" ) )			--Destroy his destination point, if any
end
 
addEventHandler ( "onClientResourceStart", getRootElement(), Binding )
addEventHandler ( "onClientPlayerQuit", getRootElement(), Quit )
addEventHandler ( "onClientClick", getRootElement(), OnClick )
addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )

Link to comment

Ok now script work but when i enter in a marker it don't teleport...

I have downloaded the script tutorial N° 1 from mta web site. http://www.mtasa.com/tutorial1.html

Now the script is:

function Binding ()   bindKey( "I", "down", modeIO )end function modeIO ( source, key, keyState )						--This function toggles the cursor on/off	if isCursorShowing ( source ) then						--If cursor was already showing,		showCursor ( false )						--then hide it;	else										--if it wasn't showing,		showCursor ( true ) 						--then show it.    endend function OnClick ( key, _, _, _, x, y, z )    --if keyState == "up" then return end						--Don't do anything if he's releasing the button.	if key == "left" then	    local del = getElementData ( source, "teleport" )								--If it's left-click:		destroyElement ( del )        local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )--Create a cylindric marker		setElementData ( theMarker, "type", teleport )				--Mark the cylinder as a teleport		setElementData ( source, "teleport", theMarker )				--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	elseif key == "right" then							--If it's right-click	    local del = getElementData ( source, "destination" )								--If it's left-click:		destroyElement ( del )		--Destroy his destination point, if any		local theMarker = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 255, 50 )	--Create a glowing corona		setElementData ( theMarker, "type", destination )			--Mark the corona as a destination point		setElementData ( source,"destination", theMarker )			--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	endend 		--This event tells what happens if a player steps inside a marker.function MarkerHit ( player )	if getElementData ( source, "type" ) == teleport then				--If the marker is a teleport point,		local owner = getElementData ( source, "owner" )			--Get the owner linked to the teleport point.		local destination = getElementData ( owner, "destination" )		--Get the destination point linked to the owner.		if destination then							--If destination point exists,			local x, y, z = getElementPosition ( destination )		--Get the destination point's position.			setElementPosition ( thePlayer, x, y, z )				--Put the player there.		end	endend 	--This event tells what happens if a player disconnects.function Quit ( reason )	destroyElement ( getElementData ( source, "teleport" ) )			--Destroy his teleport point, if any	destroyElement ( getElementData ( source, "destination" ) )			--Destroy his destination point, if anyend addEventHandler ( "onClientResourceStart", getRootElement(), Binding )addEventHandler ( "onClientPlayerQuit", getRootElement(), Quit )addEventHandler ( "onClientClick", getRootElement(), OnClick )addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )

Link to comment

function Binding ()
  bindKey( "I", "down", modeIO )
end
 
function modeIO ( source, key, keyState )						
if isCursorShowing ( source ) then					
	showCursor ( false )						
else										
	showCursor ( true ) 						
   end
end
 
--function modeIO ( thePlayer )
--	local currentState = isCursorShowing ( thePlayer )  
--	local oppositeState = not currentState              
--	showCursor ( thePlayer, oppositeState )             
--end
 
 
 
 
function OnClick ( key, _, _, _, x, y, z )
   --if keyState == "up" then return end						
if key == "left" then
    local del = getElementData ( source, "teleport" )								
	destroyElement ( del )
       tele1 = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )
       setElementData ( tele1, "type", teleport )				
	setElementData ( source, "teleport", tele1 )				
	setElementData ( tele1, "owner", source )				
 
elseif key == "right" then							
    local del = getElementData ( source, "destination" )								
	destroyElement ( del )		
       tele2 = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 255, 50 )
	setElementData ( tele2, "type", destination )			
	setElementData ( source,"destination", tele2 )			
	setElementData ( tele2, "owner", source )				
	end
end
 
function MarkerHit ( thePlayer )
local x, y, z = getElementPosition ( tele2 )
setElementPosition( thePlayer, x, y + 1, z )
end
 
 
function Quit ( reason )
destroyElement ( getElementData ( source, "teleport" ) )			
destroyElement ( getElementData ( source, "destination" ) )			
end
 
addEventHandler ( "onClientResourceStart", getRootElement(), Binding )
addEventHandler ( "onClientPlayerQuit", getRootElement(), Quit )
addEventHandler ( "onClientClick", getRootElement(), OnClick )
addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )

Now it work but i want to improve it. Who can help my?

Link to comment

function Binding ()   bindKey( "I", "down", modeIO )end function modeIO ( source, key, keyState )							if isCursorShowing ( source ) then							showCursor ( false )							else												showCursor ( true ) 						    endend --function modeIO ( thePlayer )--	local currentState = isCursorShowing ( thePlayer )  --	local oppositeState = not currentState              --	showCursor ( thePlayer, oppositeState )             --end    function OnClick ( key, _, _, _, x, y, z )    --if keyState == "up" then return end							if key == "left" then	    local del = getElementData ( source, "teleport" )										destroyElement ( del )        tele1 = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 0, 50 )        setElementData ( tele1, "type", teleport )						setElementData ( source, "teleport", tele1 )						setElementData ( tele1, "owner", source )				 	elseif key == "right" then								    local del = getElementData ( source, "destination" )										destroyElement ( del )		        tele2 = createMarker ( x, y, z, cylinder, 1.5, 1, 255, 255, 50 )		setElementData ( tele2, "type", destination )					setElementData ( source,"destination", tele2 )					setElementData ( tele2, "owner", source )				 	endend function MarkerHit ( thePlayer ) local x, y, z = getElementPosition ( tele2 ) setElementPosition( thePlayer, x, y + 1, z )end  function Quit ( reason )	destroyElement ( getElementData ( source, "teleport" ) )				destroyElement ( getElementData ( source, "destination" ) )			end addEventHandler ( "onClientResourceStart", getRootElement(), Binding )addEventHandler ( "onClientPlayerQuit", getRootElement(), Quit )addEventHandler ( "onClientClick", getRootElement(), OnClick )addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )

Now it work but i want to improve it. Who can help my?

Link to comment

These tutorials are outdated unless someone has changed them and I don't know it.

Why don't you debug it yourself? Learn to debug, it will save you time to wait for reply and save us time asking you to find out what "this" and "that" returns, holds, etc.

As I said, these tutorials are outdated so you better try looking at wiki instead or force authors of these tutorials to remake them.

Are the markers actually created when you click? If so, I can't believe it's this code that creates the marker.

cylinder seems to be variable. Have you defined it somewhere? It should be string "cylinder". Similar with if statement (where teleport is). It's almost morning here... I'm tired and there is so many errors in the code that you should trace them yourself. Again, debug.

Link to comment

These tutorials are outdated unless someone has changed them and I don't know it.

Why don't you debug it yourself? Learn to debug, it will save you time to wait for reply and save us time asking you to find out what "this" and "that" returns, holds, etc.

As I said, these tutorials are outdated so you better try looking at wiki instead or force authors of these tutorials to remake them.

Are the markers actually created when you click? If so, I can't believe it's this code that creates the marker.

cylinder seems to be variable. Have you defined it somewhere? It should be string "cylinder". Similar with if statement (where teleport is). It's almost morning here... I'm tired and there is so many errors in the code that you should trace them yourself. Again, debug.

Link to comment

Once you learn how to debug what is basically showing what variables contain in your chatbox or debug window, you will fix many scripts yourself, even with little scripting knowledge. Most of people posting their problems here just ignore debugging what makes them go mad sometimes because they can't wait for replies. You have to understand error messages your scripts may give you since they will come up very often if you're new scripter. If you don't understand English very well, use a translator or a dictionary to find out what wiki is trying to tell you.

Link to comment

Once you learn how to debug what is basically showing what variables contain in your chatbox or debug window, you will fix many scripts yourself, even with little scripting knowledge. Most of people posting their problems here just ignore debugging what makes them go mad sometimes because they can't wait for replies. You have to understand error messages your scripts may give you since they will come up very often if you're new scripter. If you don't understand English very well, use a translator or a dictionary to find out what wiki is trying to tell you.

Link to comment
  • 9 months later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...