mint3d Posted June 15, 2014 Share Posted June 15, 2014 Ok so I am making a VIP system but I need help how can I make it check to see if the player already has a vip vehicle spawned before spawning another one? function vehiclecar ( ) if exports.vip_system:isPlayerDonator(source) then x,y,z = getElementPosition ( source ) createVehicle ( 411, x + 3, y, z + 1 ) outputChatBox("[VIP]Vehicle Created",source,255,255,0,false) end end addEvent( "vehiclecar", true ) addEventHandler( "vehiclecar", getRootElement(),vehiclecar ) Link to comment
xXMADEXx Posted June 15, 2014 Share Posted June 15, 2014 This: local vehs = { } function vehiclecar ( ) if exports.vip_system:isPlayerDonator(source) then if ( isElement ( vehs [ source ] ) ) then -- Here the vehicle already exists end local x,y,z = getElementPosition ( source ) vehs [ source ] = createVehicle ( 411, x + 3, y, z + 1 ) outputChatBox("[VIP]Vehicle Created",source,255,255,0,false) end end addEvent( "vehiclecar", true ) addEventHandler( "vehiclecar", getRootElement(),vehiclecar ) Link to comment
mint3d Posted June 15, 2014 Author Share Posted June 15, 2014 It didn't work... I could click VIP Vehicle then click it again and 2 spawned.. I want it to destroy it if they click VIP Vehicle so only one can spawn at a time for each player.. Link to comment
Cadell Posted June 15, 2014 Share Posted June 15, 2014 Use setelement on spawn setelwmwnt vehicle vip or blaaa and on spawn check if get element data return false esle spawn return tru Link to comment
mint3d Posted June 15, 2014 Author Share Posted June 15, 2014 the makes no sense to me? Link to comment
Et-win Posted June 15, 2014 Share Posted June 15, 2014 (edited) function vehiclecar() if exports.vip_system:isPlayerDonator(source) then local vehicleExists = false for placeNumber, vehicleData in ipairs(getElementsByType("vehicle")) do if (getElementData(vehicleData, "vehicleVIPFrom") == getPlayerAccount(source)) then vehicleExists = true end end if (vehicleExists == false) then x,y,z = getElementPosition ( source ) local vehicleVIP = createVehicle ( 411, x + 3, y, z + 1 ) setElementData(vehicleVIP, "vehicleVIPFrom", getPlayerAccount(source)) outputChatBox("[VIP]Vehicle Created",source,255,255,0,false) else outputChatBox("[VIP]Your vehicle was already created", source, 255, 255, 0, false) end end end addEvent( "vehiclecar", true ) addEventHandler( "vehiclecar", getRootElement(),vehiclecar ) First check all vehicles on data "vehicleVIPFrom". If one has the account data of the client on it (Since I think the player is logged in, right?), then he will get the message he already have his vehicle created. Otherwise create the vehicle and set the account data on it from the client. Edited June 15, 2014 by Guest Link to comment
mint3d Posted June 15, 2014 Author Share Posted June 15, 2014 I don't know if you can help me I am making a VIP System and ye I am gonna use that code ^ I haven't tested it but I was thinking like because your code doesn't destroy it how can I make it destroy it? This is my client side.. function VIPCVehicle () triggerServerEvent ("VIPCVehicle", localplayer) end addEventHandler("onClientGUIClick", GUIEditor.button[3], VIPCVehicle, false) function VIPDVehicle () triggerServerEvent ("VIPDVehicle", localplayer) end addEventHandler("onClientGUIClick", GUIEditor.button[4], VIPDVehicle, false) Link to comment
Et-win Posted June 15, 2014 Share Posted June 15, 2014 Do you want to have it destroyed, and immediately spawn the new one? Link to comment
mint3d Posted June 15, 2014 Author Share Posted June 15, 2014 Nah I have 2 buttons Vehicle Create and Vehicle Destroy.. One Creates it other Destroys it.. Link to comment
Et-win Posted June 15, 2014 Share Posted June 15, 2014 function vehicledcar() if exports.vip_system:isPlayerDonator(source) then local vehicleExists = false for placeNumber, vehicleData in ipairs(getElementsByType("vehicle")) do if (getElementData(vehicleData, "vehicleVIPFrom") == getPlayerAccount(source)) then vehicleExists = true destroyElement(vehicleData) --You can change this to blowVehicle too, if you like that more end end if (vehicleExists == true) then outputChatBox("[VIP]Your vehicle was destroyed successfully", source, 255, 255, 0, false) elseif (vehicleExists == false) then outputChatBox("[VIP]No vehicles found", source, 255, 255, 0, false) end end end addEvent( "VIPDVehicle", true ) addEventHandler( "VIPDVehicle", getRootElement(),vehicledcar ) Link to comment
TAPL Posted June 15, 2014 Share Posted June 15, 2014 I don't know if you can help me I am making a VIP System and ye I am gonna use that code ^ I haven't tested it but I was thinking like because your code doesn't destroy it how can I make it destroy it? This is my client side.. function VIPCVehicle () triggerServerEvent ("VIPCVehicle", localplayer) end addEventHandler("onClientGUIClick", GUIEditor.button[3], VIPCVehicle, false) function VIPDVehicle () triggerServerEvent ("VIPDVehicle", localplayer) end addEventHandler("onClientGUIClick", GUIEditor.button[4], VIPDVehicle, false) local vehs = {} addEvent("VIPCVehicle", true) addEventHandler("VIPCVehicle", root, function() if exports.vip_system:isPlayerDonator(source) then if (isElement(vehs[source])) then destroyElement(vehs[source]) vehs[source] = nil end local x, y, z = getElementPosition(source) vehs[source] = createVehicle(411, x+3, y, z+1) outputChatBox("[VIP]Vehicle Created", source, 255, 255, 0) end end) addEvent("VIPDVehicle", true) addEventHandler("VIPDVehicle", root, function() if exports.vip_system:isPlayerDonator(source) then if (isElement(vehs[source])) then destroyElement(vehs[source]) vehs[source] = nil outputChatBox("[VIP]Vehicle Destroyed", source, 255, 0, 0) end end end) function VIPCVehicle () triggerServerEvent ("VIPCVehicle", localPlayer) end addEventHandler("onClientGUIClick", GUIEditor.button[3], VIPCVehicle, false) function VIPDVehicle () triggerServerEvent ("VIPDVehicle", localPlayer) end addEventHandler("onClientGUIClick", GUIEditor.button[4], VIPDVehicle, false) Link to comment
mint3d Posted June 15, 2014 Author Share Posted June 15, 2014 Thanks TAPL your stuff always works for me.. 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