#Ivan7 Posted June 17, 2014 Share Posted June 17, 2014 ok I want to make the TaxiJob with out creating a Team that will show on tab.. how would i start this off on client and server? Link to comment
xXMADEXx Posted June 17, 2014 Share Posted June 17, 2014 You can use element data to store the player job, to check it if you need it. You'll need: setElementData, getElementData Link to comment
diesel974 Posted June 17, 2014 Share Posted June 17, 2014 i had made a taxi job but mostly server side, so as to protect my codes from being copied or stolen. Also, its a good practice to make ur scripts mostly server side so that the clients( i mean the other players) dont have too much to download. Heres a simple plan of how i made the script : i made the marker, so that when the player enters it, a gui will appear to him so that he can choose to take the job or not. (server side) i made the guis when the player press the accept job button, gui disappear and trigger server to give the job to the player. create a table for the locations of the markers and the peds start the job give the taxi to the player create marker1 and ped when player hits marker1, warp the ped into the taxi destroy marker1, and create marker2 when player hits marker2, remove the ped from the taxi and give the player his money now, this can be elaborated more, and if you are doing the job serverside, you gonna use setElementData and getElementData to avoid collisions.... read more about that a wiki Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 I know i did same thing... but now i want imrpove my script make it more complex for example now im practicing dxDrawText and im having problems with that to Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 this would be the client side : local g_screenX, g_screenY = guiGetScreenSize(); local gScale = 0.3; local gAlphaDistance = 25; local gMaxDistance = 50; -- Max Distance local gTextAlpha = 120; local gTextSize = 1; local gAlphaDiff = gMaxDistance - gAlphaDistance; gScale = 1 / gScale * 800 / g_screenY; local gMaxScaleCurve = { { 0, 0 }, { 3, 3 }, { 13, 5 } }; local gTextScaleCurve = { { 0, 0.8 }, { 0.8, 1.2 }, { 99, 99 } }; local gTextAlphaCurve = { { 0, 0 }, { 25, 100 }, { 120, 190 }, { 255, 190 } }; local markertaxi = createMarker( -2479.9282226563, -197.41656494141, 24.623662948608, 'Cylinder', 1.5, 255, 0, 255, 170 ); addEventHandler ( 'onClientRender', root, function ( ) -- local x, y, z = getCameraMatrix(); local x1, y1, z1 = getElementPosition ( markertaxi ); local distance_1 = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ); -- -- Marker #1 if distance_1 <= gMaxDistance then local x1_, y1_ = getScreenFromWorldPosition( x1, y1, z1 + 0.95, 0.06 ); if x1_ and y1_ then -- local scale = 1 / ( gScale * ( distance_1 / gMaxDistance ) ); local alpha = ( ( distance_1 - gAlphaDistance ) / gAlphaDiff ); alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); scale = math.evalCurve( gMaxScaleCurve, scale ); end local textscale = math.evalCurve( gTextScaleCurve, scale ); local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); end -- dxDrawText( "Taxi Job", x1_, y1_, x1_, y1_, tocolor ( 255, 255, 255, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); end ); function math.evalCurve( curve, input ) if input < curve[ 1 ][ 1 ] then return curve[ 1 ][ 2 ]; end for idx = 2, #curve do if input < curve[ idx ][ 1 ] then local x1 = curve[ idx - 1 ][ 1 ]; local y1 = curve[ idx - 1 ][ 2 ]; local x2 = curve[ idx ][ 1 ]; local y2 = curve[ idx ][ 2 ]; local alpha = ( input - x1 ) / ( x2 - x1 ); return math.lerp( y1, y2, alpha ); end end return curve[ #curve ][ 2 ]; end function math.lerp( from, to, alpha ) return from + ( to-from ) * alpha; end GUIEditor = { memo = {}, button = {}, window = {}, } GUIEditor.window[1] = guiCreateWindow(0.4, 0.16, 0.35, 0.45, "Gta-Ar Taxi Job", true) guiWindowSetSizable(GUIEditor.window[1], false) guiSetVisible(GUIEditor.window[1], false) bAccept = guiCreateButton(0.10, 0.90, 0.41, 0.80, "Accept", true, GUIEditor.window[1]) guiSetProperty(bAccept, "NormalTextColour", "FFAAAAAA") bClose = guiCreateButton(0.52, 0.90, 0.41, 0.80, "Decline", true, GUIEditor.window[1]) guiSetProperty(bClose, "NormalTextColour", "FFAAAAAA") GUIEditor.memo[1] = guiCreateMemo(0.10, 0.1, 0.80, 0.75, " Gta-Ar Taxi Job Rules: 1) Go To Player (Blue Blip). 2) Pick up Player by pressing car horn. 3) Drop off Player to Red Blip. Be sure not to die, if you do you will lose your customer. Every dropoff you will earn up to $1000! Made By: [Gta-Ar]#Ivan ", true, GUIEditor.window[1]) createBlipAttachedTo( markertaxi, 42) function showGUIbt(hitElement) if getElementType(hitElement) == "player" and (hitElement == localPlayer) and getTeamN(hitElement) ~= "Police" and not isPedInVehicle ( hitElement ) then if getElementData(hitElement,"JobNew") ~= 4 then guiSetVisible(GUIEditor.window[1], true) showCursor( true ) else joinTeam() end end end addEventHandler("onClientMarkerHit", joinBD, showGUIbt) function showGUIbf() if source == bAccept then guiSetVisible (GUIEditor.window[1], false ) showCursor ( false ) joinTeam() elseif source == bClose then guiSetVisible (GUIEditor.window[1], false ) showCursor ( false ) end end addEventHandler("onClientGUIClick", resourceRoot, showGUIbf) Link to comment
diesel974 Posted June 17, 2014 Share Posted June 17, 2014 Sorry, but i never used dxDrawText ;/ i always tried to keep my scripts as simple as i can Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 Problem for this is it doesnt show the dxDrawText and im deleting all the joinTeam so should i just replace all joinTeam with a setElementData and getElementData Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 Its alright diesel thanks for the reply though Link to comment
xXMADEXx Posted June 17, 2014 Share Posted June 17, 2014 dxDrawText is a really basic function, once you start to understand it. You just have to make sure you put it into one of the render events. Here is a basic example: addEventHandler ( "onClientRender", root, function ( ) dxDrawText ( "This is my direct x text!", 0, 0, 500, 20 ) end ) Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 I have that but it just wont show up addEventHandler ( 'onClientRender', root, function ( ) -- local x, y, z = getCameraMatrix(); local x1, y1, z1 = getElementPosition ( markertaxi ); local distance_1 = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ); -- -- Marker #1 if distance_1 <= gMaxDistance then local x1_, y1_ = getScreenFromWorldPosition( x1, y1, z1 + 0.95, 0.06 ); if x1_ and y1_ then -- local scale = 1 / ( gScale * ( distance_1 / gMaxDistance ) ); local alpha = ( ( distance_1 - gAlphaDistance ) / gAlphaDiff ); alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); scale = math.evalCurve( gMaxScaleCurve, scale ); end local textscale = math.evalCurve( gTextScaleCurve, scale ); local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); end -- dxDrawText( "Taxi Job", x1_, y1_, x1_, y1_, tocolor ( 255, 255, 255, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); end ); Link to comment
xXMADEXx Posted June 17, 2014 Share Posted June 17, 2014 Tell me if debugscript says anything (if it does, take a screenshot and upload the error to http://imgur.com) (Debug: /debugscript 3) Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 Nah it does say anything.. Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 Actually it said this: http://imgur.com/okPkkjZ Link to comment
diesel974 Posted June 17, 2014 Share Posted June 17, 2014 Plz use the Lua tag to make code reading easier . Also, indent your codes.. oka, lets get to the real deal : addEventHandler ( 'onClientRender', root, function ( ) -- local x, y, z = getCameraMatrix(); local x1, y1, z1 = getElementPosition ( markertaxi ); local distance_1 = getDistanceBetweenPoints3D( x, y, z, x1, y1, z1 ); -- -- Marker #1 if distance_1 <= gMaxDistance then local x1_, y1_ = getScreenFromWorldPosition( x1, y1, z1 + 0.95, 0.06 ); if x1_ and y1_ then -- local scale = 1 / ( gScale * ( distance_1 / gMaxDistance ) ); local alpha = ( ( distance_1 - gAlphaDistance ) / gAlphaDiff ); alpha = ( alpha < 0 ) and gTextAlpha or gTextAlpha - ( alpha * gTextAlpha ); scale = math.evalCurve( gMaxScaleCurve, scale ); end local textscale = math.evalCurve( gTextScaleCurve, scale ); local textalpha = math.evalCurve( gTextAlphaCurve, alpha ); end -- dxDrawText( "Taxi Job", x1_, y1_, x1_, y1_, tocolor ( 255, 255, 255, textalpha ), textscale * gTextSize, "arial", "center", "bottom", false, false, false, true ); end ) oka,like debugscript said, : attempt to perform arithmetic on global "textscale" (a nil value), means that textscale is nil here, it does not hold any value. So, look at your codes. your problem is on the line 19, you defined textscale...oka, but then, when you are about to use it on the line 22, textscale is already out of scope, mean, in the block you had defined it (from line 10 to 21), at the end of line 21, the local variable textscale becomes nil bekoz it is local and its out of scope since its block has already ended. So, the solution would be to transfer the line 22 below the line 20 Link to comment
#Ivan7 Posted June 17, 2014 Author Share Posted June 17, 2014 No it doesnt work its fine thought i took it out .. Link to comment
#DRAGON!FIRE Posted June 18, 2014 Share Posted June 18, 2014 Just remove marker on line 2 and set ur marker name and set Text addEventHandler( "onClientRender", root, function ( ) local x, y, z = getElementPosition( marker ) local Mx, My, Mz = getCameraMatrix( ) if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 15 ) then local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1, 0.07 ) if ( WorldPositionX and WorldPositionY ) then dxDrawText ( "Text", WorldPositionX, WorldPositionY, WorldPositionX, WorldPositionY, tocolor(255,255,255,255), 1, "arial" ) end end end ) Link to comment
diesel974 Posted June 18, 2014 Share Posted June 18, 2014 Can u plz post the whole script in the Lua tag so that i can see which line 36 is debugscript referring?? 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