Fabioxps Posted March 17, 2013 Share Posted March 17, 2013 (edited) 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 March 17, 2013 by Guest Link to comment
Tete omar Posted March 17, 2013 Share Posted March 17, 2013 in server side you shouldn't define all variables as global, also you're triggering a client side function 'CameraStarts'??, also what is 'ped' argument for? sorry i couldn't help enough because i'm using mobile internet. Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 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
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 the car runs normal but the camera does not follow him because how can I trigger the camera with the command "a" Link to comment
Jaysds1 Posted March 17, 2013 Share Posted March 17, 2013 (edited) 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 March 17, 2013 by Guest Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 thanks for replying, but still not working the camera does not follow the car Link to comment
Jaysds1 Posted March 17, 2013 Share Posted March 17, 2013 Copy the script again and try it. Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 I think it does not work Link to comment
Jaysds1 Posted March 17, 2013 Share Posted March 17, 2013 So you want to create a ped using the command then set it driving, and you want to watch it drive. Am I right? Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 yes but the camera follow vehicle Link to comment
Jaysds1 Posted March 17, 2013 Share Posted March 17, 2013 (edited) 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 March 17, 2013 by Guest Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 longer works because the car shakes? thanks for the help Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 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
Castillo Posted March 17, 2013 Share Posted March 17, 2013 If you don't tell us what is the problem, we won't be able to tell you what is wrong on that script. Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 I want to create a rectangle on top of the vehicle with my name more giving this error WARNING: "getElemetPosition" ERROR: local 'x' (a bolean value) Link to comment
Castillo Posted March 17, 2013 Share Posted March 17, 2013 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
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 is to stay on top of the vehicle this in my car Link to comment
Castillo Posted March 17, 2013 Share Posted March 17, 2013 I don't understand what do you mean. Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 I want the rectangle to stay in the vehicle created but this on top of my vehicle Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 I want the rectangle to stay in the vehicle created Link to comment
Castillo Posted March 17, 2013 Share Posted March 17, 2013 I don't understand what do you mean by "stay", the rectangle will draw on the position above the vehicle. Link to comment
Fabioxps Posted March 17, 2013 Author Share Posted March 17, 2013 I do not know how I can explain can follow me on my server? Link to comment
Tete omar Posted March 17, 2013 Share Posted March 17, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now