Jump to content

which pobrema help:(


Fabioxps

Recommended Posts

hello everyone can help what do I have wrong here please

server

function Start(ped) 
    cams = createVehicle(411, -73.699996948242, 2506.3999023438, 16.299999237061,0,0,270) 
    ped = createPed(0, 138.70454406738, 2491.1267089844, 16.484375) 
    triggerClientEvent( "CameraStart", getRootElement(), CameraStarts ) 
    warpPedIntoVehicle ( ped,cams ) 
  
end 
addCommandHandler("test", Start) 
  

client

  
  
function onStarteds(ped) 
setPedControlState(ped,"accelerate",true) 
Camera(ped) 
end 
addEvent( "onStarted", true ) 
addEventHandler( "onStarted", getRootElement(), onStarteds ) 
  
function Camera(ped) 
local x, y, z = getElementPosition(cams) 
setCameraMatrix(x+5, y+12, z+4, x, y, z) 
end 
  
  
function CameraStarts(ped) 
cams = getPedOccupiedVehicle(ped) 
addEventHandler("onClientPreRender", getRootElement(),Camera) 
end 
addEvent( "CameraStart", true ) 
addEventHandler( "CameraStart", getRootElement(), CameraStarts ) 
  
  
  
  
  

Edited by Guest
Link to comment

the car runs normal but the camera does not follow him because

server

  
addCommandHandler ( "a",  
function() 
    local ped = createPed(0, 138.70454406738, 2491.1267089844, 16.484375) 
    local cams = createVehicle(411, -73.699996948242, 2506.3999023438, 16.299999237061,0,0,270) 
    warpPedIntoVehicle ( ped,cams,0 ) 
    triggerClientEvent("onStarted", getRootElement(), ped) 
outputChatBox("test") 
end 
) 
  
  
  
  
  
  
  
  
  

client

  
 addEvent( "onStarted", true ) 
addEventHandler( "onStarted", getRootElement(), 
function(ped) 
setPedControlState(ped,"accelerate",true) 
Camera(ped) 
end) 
  
  
  
  
function Camera(ped) 
local x, y, z = getElementPosition(cams) 
setCameraMatrix(x+5, y+12, z+4, x, y, z) 
end 
  
  
  
function CameraStarts(ped) 
cams = getPedOccupiedVehicle(ped) 
addEventHandler("onClientPreRender", getRootElement(),Camera) 
triggerServerEvent("onTestYou",getRootElement(), onTestYous) 
end 
addEvent( "onCameraStart", true ) 
addEventHandler( "onCameraStart", getRootElement(), CameraStarts ) 
  
  
  

Link to comment

try this,

Server:

addCommandHandler ( "a",function() 
    local ped = createPed(0, 138.70454406738, 2491.1267089844, 16.484375) 
    local cams = createVehicle(411, -73.699996948242, 2506.3999023438, 16.299999237061,0,0,270) 
    warpPedIntoVehicle ( ped,cams,0 ) 
    triggerClientEvent("onCameraStart", getRootElement(), ped) 
outputChatBox("test") 
end) 

Client:

local peds = {} 
function Camera() 
     for ped,veh in ipairs(peds)do 
          local x, y, z = getElementPosition(veh) 
          setCameraMatrix(x+5, y+12, z+4, x, y, z) 
     end 
end 
  
function CameraStarts(ped) 
     setPedControlState(ped,"accelerate",true) 
     pVeh = getPedOccupiedVehicle(ped) 
     if not peds[ped] then 
          peds[ped] = pVeh 
     end 
     addEventHandler("onClientPreRender",localPlayer,Camera) 
     triggerServerEvent("onTestYou",getRootElement()) 
end 
addEvent( "onCameraStart", true ) 
addEventHandler( "onCameraStart", getRootElement(), CameraStarts ) 

Edited by Guest
Link to comment

ok, try this,

Server:

addCommandHandler ( "a",function() 
    local ped = createPed(0, 138.70454406738, 2491.1267089844, 16.484375) 
    local pVeh = createVehicle(411, -73.699996948242, 2506.3999023438, 16.299999237061,0,0,270) 
    warpPedIntoVehicle ( ped,pVeh ,0 ) 
    triggerClientEvent("onCameraStart",root, ped,pVeh) 
outputChatBox("test") 
end) 

Client:

local peds = {} 
function camera() 
     for ped,veh in ipairs(peds)do 
          local x, y, z = getElementPosition(veh) 
          setCameraMatrix(x+5, y+12, z+4, x, y, z) 
     end 
end 
  
function cameraStarts(ped,pVeh) 
     setPedControlState(ped,"accelerate",true) 
     if not peds[ped] then 
          peds[ped] = pVeh 
     end 
     addEventHandler("onClientPreRender",root,camera) 
     --triggerServerEvent("onTestYou",root) 
end 
addEvent( "onCameraStart", true ) 
addEventHandler( "onCameraStart",root, cameraStarts ) 

Edited by Guest
Link to comment

what do this wrong here

local peds = {} 
  
  
  
  
function camera() 
     for ped,veh in pairs(peds)do 
          local x, y, z = getElementPosition(veh) 
          setCameraMatrix(x+8, y+10, z+4, x, y, z) 
     end 
end 
  
function cameraStarts(ped) 
     setPedControlState(ped,"accelerate",true) 
setTimer(function() setPedControlState(ped,"accelerate",false) end,600,1) 
     pVeh = getPedOccupiedVehicle(ped) 
     if not peds[ped] then 
          peds[ped] = pVeh 
     end 
     addEventHandler("onClientRender",root,camera) 
     addEventHandler("onClientRender",getRootElement(),stunt) 
  
end 
addEvent( "onCameraStart", true ) 
addEventHandler( "onCameraStart",root, cameraStarts ) 
  
  
  
  
function stunt() 
local x, y = guiGetScreenSize() 
if pVeh ~= nil then 
    local x,y,z = getElementPosition(veh) 
    local px,py,pz = x+5, y+10, z+2 
    local distance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) 
    if distance <= 150 then 
        local sx,sy = getScreenFromWorldPosition ( x, y, z+0.55, 0.06 ) 
        if not sx then return end 
        local scale = 1/(0.3 * (distance / 150)) 
        dxDrawRectangle ( sx - 100, sy - 105, 200, 70, tocolor ( 0, 0, 0, 200 ) ) 
        dxDrawColoredText ( "#000000Fabioxps", sx, sy - 70, sx, sy-30, tocolor(255,255,255,255), math.min ( 0.4*(20/distance)*1.4,4), "default-bold", "center", "bottom", false, false, false ) 
        end 
    end 
end 
  
  
  
local screen_width, screen_height = guiGetScreenSize() 
  
function dxDrawColoredText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
    right = right or screen_width 
    bottom = bottom or screen_height 
    while(left < 0) do 
        left = screen_width - math.abs(left) 
    end 
    while(top < 0) do 
        top = screen_height - math.abs(top) 
    end 
    while(right < 0) do 
        right = screen_width - math.abs(right) 
    end 
    while(bottom < 0) do 
        bottom = screen_height - math.abs(bottom) 
    end 
    if(right > screen_width)then right = screen_width end 
    if(bottom > screen_height)then bottom = screen_height end 
    color = color or tocolor(255, 255, 255, 200) 
    scale = scale or 1 
    font = font or "default" 
    alignX = alignX or "left" 
    alignY = alignY or "top" 
    clip = clip or false 
    wordBreak = wordBreak or false 
    postGUI = postGUI or true 
    local alpha = intToAlpha(color) 
    local text_width = 0 
    local offset = 0 
    local text_height = dxGetFontHeight(scale, font) 
    local TEXT_WIDTH = dxGetTextWidth(text:gsub("#%x%x%x%x%x%x", ""), scale, font) 
    local off = -TEXT_WIDTH 
    local width = 0 
    local height = 0 
    if(alignX == "center")then 
        left = left + width/2 - TEXT_WIDTH/2 
    end 
    if(alignX == "right")then 
        left = left + width - TEXT_WIDTH 
    end 
    if(alignY == "center")then 
        top = top + height/2 - text_height/2 
    end 
    if(alignY == "bottom")then 
        top = top + height - text_height 
    end 
    alignX = "left" 
    alignY = "top" 
     
    -- 0 index ? 
    local col1, col2 = string.find(text, "#%x%x%x%x%x%x") 
    if col1 ~= nil then col1 = col1-1 end 
     
    -- draw text with the color we sent until we find hexadecimal code. 
    for i = 1, col1 or string.len(text) do 
        text_width = dxGetTextWidth(string.sub(text, i, i), scale, font) 
        dxDrawText(string.sub(text, i, i), left + offset, top, right-off+offset, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
        offset = offset + text_width 
    end 
    while(string.find(text, "#%x%x%x%x%x%x", i))do 
        local hex1, hex2 = string.find(text, "#%x%x%x%x%x%x") 
        local r, g, b, a = getColorFromString(string.sub(text, hex1, hex2)) 
        text = string.sub(text, hex2 + 1) 
        hex1, hex2 = string.find(text, "#%x%x%x%x%x%x") 
        if hex1 ~= nil then hex1 = hex1-1 end 
        for i = 1, hex1 or string.len(text) do 
            text_width = dxGetTextWidth(string.sub(text, i, i), scale, font) 
            dxDrawText(string.sub(text, i, i), left + offset, top, right-off+offset, bottom, tocolor(r, g, b, alpha), scale, font, alignX, alignY, clip, wordBreak, postGUI) 
            offset = offset + text_width 
        end 
    end 
end 
  
function intToAlpha(color) 
    local a = 16777216 
    local red, green, blue, alpha = 0, 0, 0, 0 
    local ap = 1 
     
    if(color < 0)then 
        color = 2147483648 + (-color) 
        alpha = 383 
        ap = -ap 
    end 
     
    while(color >= a)do 
        alpha = alpha + ap 
        color = color - a 
    end 
    return alpha 
end 
  
  
  
  
  
  
  

Link to comment

You had forgot to get the vehicle.

function stunt ( ) 
    local x, y = guiGetScreenSize ( ) 
    local veh = getPedOccupiedVehicle ( localPlayer ) 
    if ( veh ) then 
        local x, y, z = getElementPosition ( veh ) 
        local px, py, pz = x + 5, y + 10, z + 2 
        local distance = getDistanceBetweenPoints3D ( x, y, z, px, py, pz ) 
        if ( distance <= 150 ) then 
            local sx, sy = getScreenFromWorldPosition ( x, y, z + 0.55, 0.06 ) 
            if ( sx ) then 
                local scale = 1 / ( 0.3 * ( distance / 150 ) ) 
                dxDrawRectangle ( sx - 100, sy - 105, 200, 70, tocolor ( 0, 0, 0, 200 ) ) 
                dxDrawText ( "#000000Fabioxps", sx, sy - 70, sx, sy - 30, tocolor ( 255, 255, 255, 255 ), math.min ( 0.4 * ( 20 / distance ) * 1.4, 4 ), "default-bold", "center", "bottom", false, false, false, true ) 
            end 
        end 
    end 
end 

Link to comment
I don't understand what do you mean by "stay", the rectangle will draw on the position above the vehicle.

They wants the rectangle to follow them anywhere they go, and my answer is, you get your position on every frame while rendering, and set the rectangle's position as yours.

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