Jump to content

Warp


Recommended Posts

Hello, I made a warp panel , but when i click warp, i'm not warped to the selected player, No errors in debugscript 3, hope somebody help me with this. Thanks

Server;

addEvent("warp", true) 
addEventHandler("warp", root, 
function (source, playername) 
local player = getPlayerFromName(playername or "") 
if player then 
    --local x,y,z = getElementPosition(player) 
    if ( isPedInVehicle(player) ) then 
        local playerVehicle = getPedOccupiedVehicle ( player ) 
        local numseats = getVehicleMaxPassengers ( playerVehicle ) 
        local i = 0 
        while ( i < numseats ) do 
            if ( getVehicleOccupant ( playerVehicle, i ) ) then 
                i = i + 1 
                else 
                break 
                end 
            end 
            if ( i < numseats ) then 
                warpPedIntoVehicle ( source, playerVehicle, i ) 
            else 
                outputChatBox ( "Sorry, the player's vehicle is full (" .. getVehicleName ( playerVehicle ) .. " " .. i .. "/" .. numseats .. ")", source ) 
            end 
    else 
            x, y, z = getElementPosition ( player ) 
            r = getPedRotation ( player ) 
            interior = getElementInterior ( player ) 
            dimension = getElementDimension ( player ) 
            x = x - ( ( math.cos ( math.rad ( r + 90 ) ) ) * d ) 
            y = y - ( ( math.sin ( math.rad ( r + 90 ) ) ) * d ) 
            setTimer ( setElementInterior, 800, 1, source, interior ) 
            setTimer ( setElementDimension, 900, 1, source, dimension ) 
            setTimer ( setElementPosition, 1000, 1, source, x, y, z ) 
            setTimer ( setPedRotation, 1000, 1, source, r ) 
            fadeCamera ( source, false, 1, 0, 0, 0 ) 
            setTimer ( fadeCamera, 1000, 1, source, true, 1 ) 
            --setElementPosition(source, x,y,z) 
    end 
end 
end) 

Link to comment
addEventHandler("onClientGUIClick", guiRoot, 
function() 
    if source == warpPanel.button[2] then 
        local row, column = guiGridListGetSelectedItem(warpPanel.gridlist[1]) 
        if row == -1 then return end 
        local playerName = guiGridListGetItemText(warpPanel.gridlist[1],row,column) 
        local player = getPlayerFromName(playerName) 
        if not playerName then 
            guiGridListRemoveRow(row) 
            return 
        end 
            triggerServerEvent("warp", player,playerName) 
        end 
end) 

Link to comment
  • 2 weeks later...

I have rewrite the whole code, here is it;

addEvent("warp", true) 
addEventHandler("warp", root, 
function (sourcePlayer, _, playername) 
    if ( not sourcePlayer or not playername ) then return end 
    local x, y, z, r, d = 0, 0, 0, 0, 2.5 
    local player = getPlayerFromNick ( playername ) 
    if ( player ) then 
        if ( isPlayerInVehicle ( player ) ) then 
            local playervehicle = getPlayerOccupiedVehicle ( player ) 
            local numseats = getVehicleMaxPassengers ( playervehicle ) 
            local i = 0 
            while ( i < numseats ) do 
                if ( getVehicleOccupant ( playervehicle, i ) ) then 
                    i = i + 1 
                else 
                    break 
                end 
            end 
            if ( i < numseats ) then 
                warpPlayerIntoVehicle ( sourcePlayer, playervehicle, i ) 
            else 
                outputChatBox ( "Sorry, the player's vehicle is full (" .. getVehicleName ( playervehicle ) .. " " .. i .. "/" .. numseats .. ")", sourcePlayer ) 
            end 
        else 
            x, y, z = getElementPosition ( player ) 
            r = getPlayerRotation ( player ) 
            interior = getElementInterior ( player ) 
            dimension = getElementDimension ( player ) 
            x = x - ( ( math.cos ( math.rad ( r + 90 ) ) ) * d ) 
            y = y - ( ( math.sin ( math.rad ( r + 90 ) ) ) * d ) 
            setTimer ( setElementInterior, 800, 1, sourcePlayer, interior ) 
            setTimer ( setElementDimension, 900, 1, sourcePlayer, dimension ) 
            setTimer ( setElementPosition, 1000, 1, sourcePlayer, x, y, z ) 
            setTimer ( setPlayerRotation, 1000, 1, sourcePlayer, r ) 
            fadeCamera ( sourcePlayer, false, 1, 0, 0, 0 ) 
            setTimer ( fadeCamera, 1000, 1, sourcePlayer, true, 1 ) 
        end 

Link to comment

Change this at line 3:

function ( playername) 

Change this at line 4:

if not playername then return end 

Change this at line 26:

local _, _, r = getElementRotation ( player ) 

And replace sourcePlayer with source(if you do other stuff for the player who triggered the event ) else replace it with player.

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