Jump to content

Car Jacking Script


Recommended Posts

Hello,

I'm creating a Car Jacking script for my server.

But there is something wrong with line 2

I'm not a pro scripter i'm trying to learn it. :P

Server.lua

function JobDone ( hitElement, matchingDimension ) 
    local elementType = getElementType( hitElement ) 
    if elemenyType == "player" then 
        if isElement( EndDesMarker ) then 
            destroyElement( EndDesMarker ) 
        end 
        if isElement( EndDesBlip ) then 
            destroyElement( EndDesBlip ) 
        end 
        if isElement( CarJacker ) then 
            destroyElement( CarJacker ) 
        end 
        if isElement( CarJackerBlip ) then 
            destroyElement( CarJackerBlip ) 
        end 
        money = math.random ( 2000, 5000 ) 
        givePlayerMoney ( source, money ) 
        outputChatBox ( "Got job! You received $" ..money, source ) 
    end 
end 
addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) 

Can somebody tell me what's wrong with it?

Link to post

Typo at line 3 -- Other guy posted while I was typing --

    function JobDone ( hitElement, matchingDimension ) 
        local elementType = getElementType( hitElement ) 
        if elementType == "player" then 
            if isElement( EndDesMarker ) then 
                destroyElement( EndDesMarker ) 
            end 
            if isElement( EndDesBlip ) then 
                destroyElement( EndDesBlip ) 
            end 
            if isElement( CarJacker ) then 
                destroyElement( CarJacker ) 
            end 
            if isElement( CarJackerBlip ) then 
                destroyElement( CarJackerBlip ) 
            end 
            money = math.random ( 2000, 5000 ) 
            givePlayerMoney ( source, money ) 
            outputChatBox ( "Got job! You received $" ..money, source ) 
        end 
    end 
    addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) 

Link to post
        function JobDone ( hitElement, matchingDimension ) 
             if hitElement then 
            local elementType = getElementType( hitElement ) 
            if elementType == "player" then 
                if isElement( EndDesMarker ) then 
                    destroyElement( EndDesMarker ) 
                end 
                if isElement( EndDesBlip ) then 
                    destroyElement( EndDesBlip ) 
                end 
                if isElement( CarJacker ) then 
                    destroyElement( CarJacker ) 
                end 
                if isElement( CarJackerBlip ) then 
                    destroyElement( CarJackerBlip ) 
                end 
                money = math.random ( 2000, 5000 ) 
                givePlayerMoney ( hitElement , money ) 
                outputChatBox ( "Got job! You received $" ..money, hitElement ) 
            end 
        end 
        addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) 

Link to post

Sure!

function JobDone ( hitElement, matchingDimension ) 
    if hitElement then 
        local elementType = getElementType( hitElement ) 
        if elementType == "player" then 
            if isElement( EndDesMarker ) then 
                destroyElement( EndDesMarker ) 
            end 
            if isElement( EndDesBlip ) then 
                destroyElement( EndDesBlip ) 
            end 
            if isElement( CarJacker ) then 
                destroyElement( CarJacker ) 
            end 
            if isElement( CarJackerBlip ) then 
                destroyElement( CarJackerBlip ) 
            end 
            money = math.random ( 2000, 5000 ) 
            givePlayerMoney ( hitElement, money ) 
            outputChatBox ( "Got job! You received $" ..money, hitElement ) 
        end 
    end 
end 
addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) 

Link to post

Oow i thought you mean that part of the code :P

local EndDesMarker = createMarker ( 2411.81, -1300.46, 23.62, "cylinder", 1, 255, 255, 0, 170 ) 
EndDesBlip = createBlipAttachedTo ( EndDesMarker, 53 ) 
setElementVisibleTo ( EndDesMarker, root, false ) 
setElementVisibleTo ( EndDesBlip, root, false ) 
  
local CarParks = 
{ 
    { 2415.27, -1238.13, 23.45 }; 
    { 2433.49, -1224.88, 24.74 }; 
} 
  
local CarTypes = 
{ 
    { 518 }; 
    { 457 }; 
} 
  
function unpackCarParks () 
    return unpack ( CarParks [ math.random ( #CarParks ) ] ) 
end 
  
function unpackCarTypes () 
    return unpack ( CarTypes [ math.random ( #CarTypes ) ] ) 
end 
  
function CreateCar () 
    x, y, z = unpackCarParks () 
    Veh = unpackCarTypes () 
    CarJacker = createVehicle ( Veh, x, y, z, 0, 0, 9 ) 
    CarJackerBlip = createBlipAttachedTo ( CarJacker, 55 ) 
end 
addEventHandler ( "onResourceStart", root, CreateCar ) 
  
function enterVehicle () 
    setElementVisibleTo ( EndDesMarker, root, true ) 
    setElementVisibleTo ( EndDesBlip, root, true ) 
end 
addEventHandler ( "onVehicleEnter", root, enterVehicle ) 
  
function DestroyStuff () 
    setElementVisibleTo ( EndDesMarker, root, false ) 
    setElementVisibleTo ( EndDesBlip, root, false ) 
end 
addEventHandler ( "onVehicleExit", root, DestroyStuff ) 
  
function JobDone ( hitElement, matchingDimension ) 
    if hitElement then 
        local elementType = getElementType( hitElement ) 
        if elementType == "player" then 
            if isElement( EndDesMarker ) then 
                destroyElement( EndDesMarker ) 
            end 
            if isElement( EndDesBlip ) then 
                destroyElement( EndDesBlip ) 
            end 
            if isElement( CarJacker ) then 
                destroyElement( CarJacker ) 
            end 
            if isElement( CarJackerBlip ) then 
                destroyElement( CarJackerBlip ) 
            end 
            money = math.random ( 2000, 5000 ) 
            givePlayerMoney ( hitElement, money ) 
            outputChatBox ( "Got job! You received $" ..money, hitElement ) 
        end 
    end 
end 
addEventHandler( "onMarkerHit", EndDesMarker, JobDone ) 
  
addEventHandler ( "onResourceStop", root,  
    function () 
        if isElement( CarJacker ) then 
            destroyElement( CarJacker ) 
        end 
        if isElement( CarJackerBlip ) then 
            destroyElement( CarJackerBlip ) 
        end 
    end  
) 

Link to post

tested it,

if isElement(hitElement) then 
        if getElementType (hitElement) == "player" then 

Also a few suggestions / ideas perhaps, wouldn't it be better to just create a marker client side and destroy it when finished instead of having it all time invisible. Also you're doing 4 if's to check for element and destroy it, You can put those in an table and then loopthrough it with (for key, value in table do)

Kind regards

Link to post

Thx and i'm still busy with it so there are some bugs maybe and i'm learning it so its hard for me to make a script like this. (

without any bugs).

And that's a good idea.. xD i have really no idee why i was use the server-side to create the marker and destroy it).

Normally i use the client-side (Really no idee why but that's how i learned it).

Also sorry for my bad English :P

Link to post

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