Jump to content

[HELP] If there's a created vehicle


LabiVila

Recommended Posts

So hey guys over again, I hope I'm not being repetitive. So I'm stuck somewhere... how can I see if the vehicle was already created?

--server side

addEvent ("spawnEuro", true) 
addEventHandler ("spawnEuro", getRootElement(), 
    function (px, py, pz) 
        createVehicle (565, px+2, py+2, pz) 
        outputChatBox ("Flash was created successfully.", client, 255, 255, 255) 
    end 
) 

--client side (not needed I guess)

addEventHandler ("onClientRender", root, 
    function () 
        dxDrawRectangle (x/1.225, y/2.1, x/5.75, y/7, tocolor (0, 0, 0, 100)) 
        dxDrawText ("Commands: ", x/1.20, y/2, x, y, tocolor (255, 255, 255)) 
        dxDrawText ("1: Spawn sanchez.", x/1.20, y/1.85, x, y, tocolor (255, 255, 255)) 
        dxDrawText ("2: Spawn flash.", x/1.20, y/1.75, x, y, tocolor (255, 255, 255)) 
    end 
) 

how can I check if Flash has been successfully created once, so if I type 2 again, it won't create another car (flash).

Link to comment

give a name to your car.

createVehicle (565, px+2, py+2, pz) 

Like this

flash = createVehicle (565, px+2, py+2, pz) 
if (flash) then 
    outputChatBox ("Flash was created successfully.", client, 255, 255, 255) 
end 
  

if you are not using it outside then function the declare it as a local else it will be global.

local flash = createVehicle (565, px+2, py+2, pz) 

Link to comment

try this:

local vehicle = { } 
addEvent ( "spawnEuro", true ) 
addEventHandler ("spawnEuro", root,  
    function ( px, py, pz ) 
        if isElement ( vehicle [source] ) then 
            outputChatBox ( "Error - You already have a flash.", source, 255, 0, 0 ) 
            return end 
            vehicle [source] = createVehicle ( 565, px + 2, py + 2, pz ) 
            outputChatBox ( "Flash was created successfully.", source, 0, 255, 0 ) 
        end 
    end 
) 
  
addEventHandler ("onPlayerQuit", root,  
    function ( ) 
        if isElement ( vehicle [source] ) then 
            destroyElement ( vehicle [source] ) 
            vehicle [source] = nil 
        end 
    end 
) 
Link to comment

ERROR: Loading srcipt failed: test\server.lua:34: ')' expected (to close '(' at line 26) near 'end'

this is what I get. Here's full script

function test (resourcename) 
    if (resourcename == getThisResource ()) then 
        outputDebugString ("Resource "..getResourceName(resourcename).." loaded asd.") 
    end 
end 
addEventHandler ("onResourceStart", getRootElement(), test) 
  
function spawn () 
    spawnPlayer (source, 1959.55, -1714.46, 17) 
    fadeCamera (source, true) 
    setCameraTarget (source, source) 
    setPlayerHudComponentVisible (source, "all", false) 
end 
addEventHandler ("onPlayerJoin", getRootElement(), spawn) 
  
local vehicle = { } 
addEvent ( "spawnEuro", true ) 
addEventHandler ("spawnEuro", root, 
    function ( px, py, pz ) 
        if isElement ( vehicle [source] ) then 
            outputChatBox ( "Error - You already have a flash.", source, 255, 0, 0 ) 
            return end 
            vehicle [source] = createVehicle ( 565, px + 2, py + 2, pz ) 
            outputChatBox ( "Flash was created successfully.", source, 0, 255, 0 ) 
        end 
    end 
) 
  
addEventHandler ("onPlayerQuit", root, 
    function ( ) 
        if isElement ( vehicle [source] ) then 
            destroyElement ( vehicle [source] ) 
            vehicle [source] = nil 
        end 
    end 
) 

Link to comment
local vehicle = { } 
addEvent ( "spawnEuro", true ) 
addEventHandler ("spawnEuro", root, 
    function ( px, py, pz ) 
        if isElement ( vehicle [source] ) then 
            outputChatBox ( "Error - You already have a flash.", source, 255, 0, 0 ) 
            return end 
            vehicle [source] = createVehicle ( 565, px + 2, py + 2, pz ) 
            outputChatBox ( "Flash was created successfully.", source, 0, 255, 0 ) 
        end 
    end 
) 

1 end to much, you already did

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