LabiVila Posted December 14, 2014 Share Posted December 14, 2014 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
ViRuZGamiing Posted December 14, 2014 Share Posted December 14, 2014 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
LabiVila Posted December 14, 2014 Author Share Posted December 14, 2014 Yea, I did it but it isn't resulting successful. It isn't preventing the user to create another flash... Link to comment
The Killer Posted December 14, 2014 Share Posted December 14, 2014 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
LabiVila Posted December 14, 2014 Author Share Posted December 14, 2014 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
ViRuZGamiing Posted December 14, 2014 Share Posted December 14, 2014 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
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