Michcio Posted February 17, 2013 Share Posted February 17, 2013 My script doesn't work. I can't find mistake in it. local scx,scy = guiGetScreenSize() function suszara () local target = getPedTarget(getLocalPlayer()) local px,py,pz=getElementPosition(getLocalPlayer()) if getPlayerTeam(getLocalPlayer()) == getTeamFromName("Policja") then if target and getElementType(target) == "player" then if target ~= getLocalPlayer() then local x,y,z = getElementPosition(target) local car = getPedOccupiedVehicle( target ) if car then local speed = math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(car)) * 100 * 1.61) if speed then if getVehicleController(car) == target then local dystans=getDistanceBetweenPoints3D(x,y,z,px,py,pz) local cx,cy,cz = getCameraMatrix() if dystans <= 60 then if isLineOfSightClear(cx,cy,cz,px,py,pz,true,false,false,true,false,false,false,getPedOccupiedVehicle(getLocalPlayer())) then dxDrawText(getPlayerName(getVehicleController(car)).." : "..speed.." km/h", scx*(213/1280), scy*(842/1024), scx*(977/1280), scy*(913/1024), tocolor(255, 255, 255, 255), 1, "bankgothic", "center", "center", false, false, true, false, false) end end end end end end end end end addEventHandler("onClientRender",getRootElement(),suszara) Link to comment
Castillo Posted February 17, 2013 Share Posted February 17, 2013 Do you get any error on the debugscript? NOTE: The errors won't appear on the server console, since it's a client side script. Link to comment
Michcio Posted February 17, 2013 Author Share Posted February 17, 2013 There's no errors in debugscript. Link to comment
50p Posted February 17, 2013 Share Posted February 17, 2013 getElementVelocity returns 3 values. You need to use Pythagoras theorem to calculate actual speed since the velocity is returned in x, y and z format so you need to calculate the length of these values (x*x + y*y + z*z) * 100 (or 160). Calling function like that (line 12) will work but the multiplication would only multiply z (the last value returned from getElementVelocity function). Also, is it possible to target yourself? (line 8 seems pointless). Link to comment
Castillo Posted February 17, 2013 Share Posted February 17, 2013 I guess that he could also use: https://wiki.multitheftauto.com/wiki/GetElementSpeed Link to comment
Michcio Posted February 17, 2013 Author Share Posted February 17, 2013 Doesn't work. Problem is not in speed. function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end local scx,scy = guiGetScreenSize() function suszara () local target = getPedTarget(getLocalPlayer()) local px,py,pz=getElementPosition(getLocalPlayer()) if getPlayerTeam(getLocalPlayer()) == getTeamFromName("Policja") then if target and getElementType(target) == "player" then if target ~= getLocalPlayer() then local x,y,z = getElementPosition(target) local car = getPedOccupiedVehicle( target ) if car then local speed = getElementSpeed(car,"kph") if speed then if getVehicleController(car) == target then local dystans=getDistanceBetweenPoints3D(x,y,z,px,py,pz) local cx,cy,cz = getCameraMatrix() if dystans <= 60 then if isLineOfSightClear(cx,cy,cz,px,py,pz,true,false,false,true,false,false,false,getPedOccupiedVehicle(getLocalPlayer())) then outputChatBox(speed) dxDrawText(getPlayerName(getVehicleController(car)).." : "..speed.." km/h", scx*(213/1280), scy*(842/1024), scx*(977/1280), scy*(913/1024), tocolor(255, 255, 255, 255), 1, "bankgothic", "center", "center", false, false, true, false, false) end end end end end end end end end addEventHandler("onClientRender",getRootElement(),suszara) Link to comment
Castillo Posted February 17, 2013 Share Posted February 17, 2013 Try adding debug outputs until you find what's wrong. Link to comment
50p Posted February 17, 2013 Share Posted February 17, 2013 It's much more helpful and easier to find the problem when you say what doesn't work. Link to comment
Michcio Posted February 19, 2013 Author Share Posted February 19, 2013 Problem is here: local car = getPedOccupiedVehicle( target ) Link to comment
Castillo Posted February 22, 2013 Share Posted February 22, 2013 Problem is here: local car = getPedOccupiedVehicle( target ) "car" is not returning a vehicle element? Link to comment
50p Posted February 22, 2013 Share Posted February 22, 2013 Problem is here: local car = getPedOccupiedVehicle( target ) As far as I know, when you target at a vehicle getPedTarget will return vehicle (target = vehicle) so there is no point "getting occupied vehicle of vehicle". Link to comment
gokalpfirat Posted February 22, 2013 Share Posted February 22, 2013 If 50p saying true then you should use if loop that if it is a vehicle getVehicleOccupant(target) 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