Jump to content

I need help with checking something..


mint3d

Recommended Posts

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

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
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 by Guest
Link to comment

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

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