Jump to content

Script keeps repeating a few times


Jeeveegee

Recommended Posts

This script teleports you from one warp-marker to another warp-marker. The problem is, the script loops 2 or 3 times when people enter the marker, and while sometimes you end up at the right location, sometimes you just warp to your current location. I tried to fix it by setting timers and something like that, but that isn't working. Anyone who can help me?

function hitMarker(hitElement, matchingDimension) 
     
    function typeEnter() 
     
        local elementType = getElementType(hitElement) 
        if elementType == "player" then 
         
            local warpID = getElementData(source,"warpID") 
            local warpDimension = getElementData(source,"warpDimension") 
            local warpName = getElementData(source,"warpName") 
            local warpRestriction = getElementData(source,"warpRestriction") 
             
            outputDebugString(warpID) 
  
            local result = mysql_query(handler,"SELECT * FROM warps WHERE warpName = '"..warpName.."' AND warpID != '"..warpID.."' LIMIT 1") 
            local count = mysql_num_rows(result) 
  
            if (count == 1) then 
             
            outputChatBox("You are being moved.", hitElement)  
             
            local row = mysql_fetch_assoc(result) 
             
            local warpX = row['warpX'] 
            local warpY = row['warpY'] 
            local warpZ = row['warpZ'] 
            local warpR = row['warpR'] 
            local warpDimension = row['warpDimension'] 
                 
            setElementPosition(hitElement,warpX,warpY,warpZ) 
            setElementRotation(hitElement,0,0,warpR) 
            setElementDimension(hitElement,warpDimension) 
             
            else 
            outputChatBox("Nothing happend.") 
            end  
        end 
    end 
    addCommandHandler("enter",typeEnter) 
end 
addEventHandler("onMarkerHit",getRootElement(),hitMarker) 

Link to comment

you could just do something like this before u set the players new position:

setElementData(source,"justTeleported",true) 
setTimer(setElementData,1000,1,source,"justTeleported",nil) 

then add a check when u hit the marker,

if not getElementData(source,"justTeleported") then 

this would stop anyone who has just teleported from instantly teleporting back and fourth.

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