Jump to content

TaxiHelp


#Ivan7

Recommended Posts

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

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

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

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 :D

Link to comment

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

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