Jump to content

need help with script


mint3d

Recommended Posts

i need help with my script i want to make it so you pick the car. Instead of it randomly giving you one

Client

Client][ 
Color = {255,0,0} 
currentPosition = {} 
local Key = "z" 
local render = false 
  
GUIEditor = { 
    combobox = {}, 
    button = {}, 
    edit = {}, 
    label = {}, 
} 
  
System = {} 
itemTextCombobox = {"Arabic|العربية","English","Italiano","Français","Español"} 
  
  
local X, Y = guiGetScreenSize() 
System.wnd = guiCreateWindow(X-343, Y/2-269/2, 333, 269, ".:: [ Vehicle Marker Creator System ] ::.", false) 
guiSetVisible(System.wnd, not guiGetVisible(System.wnd)) 
guiWindowSetMovable(System.wnd, false) 
guiWindowSetSizable(System.wnd, false) 
guiSetAlpha(System.wnd, 1.00) 
guiSetProperty(System.wnd, "CaptionColour", "FF00D2F8") 
  
GUIEditor.label[1] = guiCreateLabel(7, 27, 415, 25, "Welcome To Vehicle Marker System ( =", false, System.wnd) 
guiSetFont(GUIEditor.label[1], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[1], 248, 0, 0) 
GUIEditor.label[2] = guiCreateLabel(11, 59, 111, 25, "Position :", false, System.wnd) 
guiSetFont(GUIEditor.label[2], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[2], 240, 237, 7) 
GUIEditor.label[3] = guiCreateLabel(11, 92, 118, 21, "x", false, System.wnd) 
guiSetFont(GUIEditor.label[3], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[3], 99, 244, 2) 
GUIEditor.edit[1] = guiCreateEdit(9, 115, 130, 19, "", false, System.wnd) 
GUIEditor.label[4] = guiCreateLabel(10, 140, 118, 21, "y", false, System.wnd) 
guiSetFont(GUIEditor.label[4], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[4], 99, 244, 2) 
GUIEditor.edit[2] = guiCreateEdit(10, 167, 130, 19, "", false, System.wnd) 
GUIEditor.label[5] = guiCreateLabel(10, 192, 118, 21, "z", false, System.wnd) 
guiSetFont(GUIEditor.label[5], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[5], 99, 244, 2) 
GUIEditor.edit[3] = guiCreateEdit(10, 213, 130, 17, "", false, System.wnd) 
GUIEditor.label[6] = guiCreateLabel(148, 59, 125, 23, "Language :", false, System.wnd) 
guiSetFont(GUIEditor.label[6], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[6], 241, 232, 4) 
GUIEditor.combobox[1] = guiCreateComboBox(148, 92, 171, 100, "", false, System.wnd) 
for i = 1, #itemTextCombobox do 
guiComboBoxAddItem(GUIEditor.combobox[1], itemTextCombobox[i]) 
end 
GUIEditor.button[1] = guiCreateButton(146, 129, 175, 22, "Get Position", false, System.wnd) 
guiSetFont(GUIEditor.button[1], "default-bold-small") 
guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF5CF202") 
GUIEditor.button[2] = guiCreateButton(148, 161, 175, 22, "Set Marker Color", false, System.wnd) 
guiSetFont(GUIEditor.button[2], "default-bold-small") 
guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FF00ACF4") 
GUIEditor.button[3] = guiCreateButton(150, 202, 173, 22, "Create Marker", false, System.wnd) 
guiSetFont(GUIEditor.button[3], "default-bold-small") 
guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FFF40000") 
GUIEditor.button[4] = guiCreateButton(298, 21, 26, 29, "X", false, System.wnd) 
guiSetFont(GUIEditor.button[4], "default-bold-small") 
guiSetProperty(GUIEditor.button[4], "NormalTextColour", "FFF40000") 
GUIEditor.label[7] = guiCreateLabel(9, 242, 322, 21, "Vehicle Marker Creator System v.2", false, System.wnd) 
guiSetFont(GUIEditor.label[7], "default-bold-small") 
guiLabelSetColor(GUIEditor.label[7], 30, 213, 207) 
for k, v in pairs( GUIEditor.edit ) do guiEditSetReadOnly( v, true ) end 
  
  
addEventHandler("onClientGUIClick",root, 
    function () 
        if ( source == GUIEditor.button[2] ) then 
            openColorPicker() 
        elseif ( source == GUIEditor.button[1] ) then 
            local x,y,z = getElementPosition(localPlayer)    
            guiSetText (GUIEditor.edit[1], x ) 
            guiSetText (GUIEditor.edit[2], y ) 
            guiSetText (GUIEditor.edit[3], z ) 
            currentPosition = {x,y,z} 
        elseif ( source == GUIEditor.button[3] ) then 
            if #currentPosition == 0 then return end 
            local send = { 
            [1] = currentPosition[1], [2] = currentPosition[2],  
            [3] = currentPosition[3], [4] = Color[1], 
            [5] = Color[2], [6] = Color[3], 
            } 
            newPos = {} 
            triggerServerEvent("CreateMarker", localPlayer, unpack(send)) 
        elseif ( source == GUIEditor.button[4] ) then 
            guiSetVisible(System.wnd, not guiGetVisible(System.wnd)) 
            showCursor(guiGetVisible(System.wnd)) 
            if render then 
                openColorPicker() 
            end      
       end 
    end 
) 
  
addEventHandler ( "onClientGUIComboBoxAccepted", guiRoot, 
    function ( combo ) 
        if ( combo == GUIEditor.combobox[1] ) then 
            local text = tostring ( guiComboBoxGetItemText ( combo, guiComboBoxGetSelected ( combo ) ) ) 
            if ( text ) then 
                local lang = AddLanguage( text ) 
                for k, v in pairs ( lang ) do 
                    guiSetText( v.element, v.id) 
                end 
            end 
        end 
    end 
) 
  
bindKey (Key, "down", 
    function() 
        if getElementData( localPlayer, 'OpenMakerPanel') ~= nil then    
            guiSetVisible(System.wnd, not guiGetVisible(System.wnd)) 
            showCursor(guiGetVisible(System.wnd)) 
            if render then 
                openColorPicker() 
            end 
        end 
    end  
) 
  
addEvent( 'LogOutSetVisible', true ) 
addEventHandler( 'LogOutSetVisible', root, function() 
    if guiGetVisible(System.Wnd) then 
        guiSetVisible( System.Wnd, false ) 
        showCursor( false ) 
    end  
end) 
  
function openColorPicker() 
    if render then 
        colorPicker.closeSelect() 
        removeEventHandler("onClientRender", root, updateColor)  
    else 
        colorPicker.openSelect() 
        addEventHandler("onClientRender", root, updateColor) 
    end 
    render = not render 
end 
  
  
function updateColor() 
    if (not colorPicker.isSelectOpen) then return end 
    local r, g, b = colorPicker.updateTempColors() 
    Color = {r,g,b} 
end 

Server

  
  
rRoot = getResourceRootElement(getThisResource()) 
Cars = {} 
antiFloodMarker = {} 
local cmd = 'RemoveMarker' --- Delete Marker Command  
local allowedGroup = 'Admin' 
local vehicleIDS = { -- Vehicle ID   
415,561,587,541,527,480,603 
} 
  
addEventHandler( 'onResourceStart', rRoot, 
    function( ) 
        executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Marker_System ( posX, posY, posZ, r, g, b, ID)' ) 
        for i, player in ipairs( getElementsByType( 'player' ) ) do 
            if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then 
                setElementData( player, 'OpenMakerPanel', true) 
            else 
                setElementData( player, 'OpenMakerPanel', nil) 
            end 
        end  
        creatMarkerSystem()      
    end 
) 
  
function creatMarkerSystem() 
    local GetAllMarker = executeSQLQuery( "SELECT * FROM Marker_System" ) 
    if ( type ( GetAllMarker ) == "table" and #GetAllMarker > 0 ) then 
        for i = 1, #GetAllMarker do 
            local n = {GetAllMarker[i]["posX"], GetAllMarker[i]["posY"], GetAllMarker[i]["posZ"], GetAllMarker[i]["r"], GetAllMarker[i]["g"],GetAllMarker[i]["b"]} 
            for ii = 1, #n do n[ ii ] = tonumber( n[ ii ] ) end          
            local marker = createMarker( n[1], n[2],   n[3], 'cylinder', 1.25, n[4], n[5], n[6], 255 ) 
            setElementData( marker, 'id', i ) 
            setElementData( marker, 'giveCarSystem', true )          
        end 
    end 
end 
  
addEventHandler( 'onMarkerHit', rRoot, function( player ) 
    if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then 
      if getElementData( source, 'giveCarSystem' ) then 
            randomCarID = tonumber(vehicleIDS[math.random(#vehicleIDS)]) 
            if Cars[player] and getElementType(Cars[player]) == "vehicle" then destroyElement(Cars[player]) end 
                x,y,z = getElementPosition(player) 
                    Cars[player] = createVehicle(randomCarID, x+1,y,z) 
                if Cars[player] then 
                    warpPedIntoVehicle(player,Cars[player]) 
            end  
      end 
    end 
end) 
  
addEventHandler( 'onPlayerJoin', root, function() 
    setElementData( source, 'OpenMakerPanel', nil) 
end ) 
  
addEventHandler( 'onPlayerLogin', root, function( _, acc ) 
    if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( allowedGroup ) ) then 
        setElementData( source, 'OpenMakerPanel', true) 
    else 
        setElementData( source, 'OpenMakerPanel', nil)   
    end 
end 
) 
  
addEventHandler( 'onPlayerLogout', root, function( _, acc ) 
    triggerClientEvent( source, 'LogOutSetVisible', root) 
    setElementData( source, 'OpenMakerPanel', nil)  
end ) 
  
addEvent( 'CreateMarker', true ) 
addEventHandler( 'CreateMarker', root,  
function( X, Y, Z, r, g, b) 
if antiFloodMarker[source] then return outputChatBox( "Please wait 6 seconds before creating new marker", source, 255, 255, 0 ) end 
antiFloodMarker[source] = true 
if getPedOccupiedVehicle( source ) then Z = Z else Z = Z - 1 end 
local AllMarker = executeSQLQuery( "SELECT * FROM Marker_System" ) 
id = #AllMarker + 1 
executeSQLQuery( "INSERT INTO Marker_System ( posX, posY, posZ, r, g, b, ID ) VALUES ( "..X..", "..Y..", "..Z..", "..r..", "..g..", "..b..", "..id..")" ) 
local marker = createMarker( X, Y, Z, 'cylinder', 1.25, r, g, b, 255 ) 
setElementData( marker, 'giveCarSystem', true ) 
setElementData( marker, 'id', id ) 
outputChatBox( "Marker Was Created", source, 255, 255, 0 ) 
setTimer(removeFlood, 6000, 1, source) 
end 
) 
  
function removeFlood(plr) 
if antiFloodMarker[plr] then antiFloodMarker[plr] = false end 
end 
  
addEventHandler("onPlayerQuit",root,function() 
if Cars[source] then destroyElement(Cars[source]) Cars[source] = nil end 
end) 
  
addEventHandler("onVehicleExplode",root,function() 
setTimer(destroyElement,2000,1,source) 
end) 
  
addCommandHandler( cmd, function(player, Command) 
    if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then 
        local mrker = getMarkerByHit( player ) 
        if mrker then 
            local id = tonumber ( getElementData( mrker, 'id') or 0 ) 
            if id == 0 then return end 
            if executeSQLQuery("DELETE FROM `Marker_System` WHERE `ID`=?", id) then 
                destroyElement( mrker ) 
                outputChatBox( "Marker Was Deleted", player, 255, 255, 0 ) 
            else 
                outputChatBox( "error", player, 255, 255, 0 )        
            end 
        end 
    else 
        outputChatBox( "Access denied", player, 255, 255, 0 )    
    end  
end 
) 
  
function getMarkerByHit( plr ) 
  for i, v in ipairs( getElementsByType( 'marker', rRoot ) ) do 
    if isElementWithinMarker(plr, v) then 
      return v 
    end 
  end 
  return false,outputChatBox( "Error: Please enter the marker", plr, 255, 255, 0 ) 
end 

Link to comment

This is my script change server.lua to

  
  
rRoot = getResourceRootElement(getThisResource()) 
Cars = {} 
antiFloodMarker = {} 
local cmd = 'RemoveMarker' --- Delete Marker Command  
local allowedGroup = 'Admin' 
local VehicleID = 411  
addEventHandler( 'onResourceStart', rRoot, 
    function( ) 
        executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Marker_System ( posX, posY, posZ, r, g, b, ID)' ) 
        for i, player in ipairs( getElementsByType( 'player' ) ) do 
            if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then 
                setElementData( player, 'OpenMakerPanel', true) 
            else 
                setElementData( player, 'OpenMakerPanel', nil) 
            end 
        end  
        creatMarkerSystem()      
    end 
) 
  
function creatMarkerSystem() 
    local GetAllMarker = executeSQLQuery( "SELECT * FROM Marker_System" ) 
    if ( type ( GetAllMarker ) == "table" and #GetAllMarker > 0 ) then 
        for i = 1, #GetAllMarker do 
            local n = {GetAllMarker[i]["posX"], GetAllMarker[i]["posY"], GetAllMarker[i]["posZ"], GetAllMarker[i]["r"], GetAllMarker[i]["g"],GetAllMarker[i]["b"]} 
            for ii = 1, #n do n[ ii ] = tonumber( n[ ii ] ) end          
            local marker = createMarker( n[1], n[2],   n[3], 'cylinder', 1.25, n[4], n[5], n[6], 255 ) 
            setElementData( marker, 'id', i ) 
            setElementData( marker, 'giveCarSystem', true )          
        end 
    end 
end 
  
addEventHandler( 'onMarkerHit', rRoot, function( player ) 
    if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then 
      if getElementData( source, 'giveCarSystem' ) then 
            randomCarID = tonumber(vehicleIDS[math.random(#vehicleIDS)]) 
            if Cars[player] and getElementType(Cars[player]) == "vehicle" then destroyElement(Cars[player]) end 
                x,y,z = getElementPosition(player) 
                    Cars[player] = createVehicle(VehicleID, x+1,y,z) 
                if Cars[player] then 
                    warpPedIntoVehicle(player,Cars[player]) 
            end  
      end 
    end 
end) 
  
addEventHandler( 'onPlayerJoin', root, function() 
    setElementData( source, 'OpenMakerPanel', nil) 
end ) 
  
addEventHandler( 'onPlayerLogin', root, function( _, acc ) 
    if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( allowedGroup ) ) then 
        setElementData( source, 'OpenMakerPanel', true) 
    else 
        setElementData( source, 'OpenMakerPanel', nil)   
    end 
end 
) 
  
addEventHandler( 'onPlayerLogout', root, function( _, acc ) 
    triggerClientEvent( source, 'LogOutSetVisible', root) 
    setElementData( source, 'OpenMakerPanel', nil)  
end ) 
  
addEvent( 'CreateMarker', true ) 
addEventHandler( 'CreateMarker', root,  
function( X, Y, Z, r, g, b) 
if antiFloodMarker[source] then return outputChatBox( "Please wait 6 seconds before creating new marker", source, 255, 255, 0 ) end 
antiFloodMarker[source] = true 
if getPedOccupiedVehicle( source ) then Z = Z else Z = Z - 1 end 
local AllMarker = executeSQLQuery( "SELECT * FROM Marker_System" ) 
id = #AllMarker + 1 
executeSQLQuery( "INSERT INTO Marker_System ( posX, posY, posZ, r, g, b, ID ) VALUES ( "..X..", "..Y..", "..Z..", "..r..", "..g..", "..b..", "..id..")" ) 
local marker = createMarker( X, Y, Z, 'cylinder', 1.25, r, g, b, 255 ) 
setElementData( marker, 'giveCarSystem', true ) 
setElementData( marker, 'id', id ) 
outputChatBox( "Marker Was Created", source, 255, 255, 0 ) 
setTimer(removeFlood, 6000, 1, source) 
end 
) 
  
function removeFlood(plr) 
if antiFloodMarker[plr] then antiFloodMarker[plr] = false end 
end 
  
addEventHandler("onPlayerQuit",root,function() 
if Cars[source] then destroyElement(Cars[source]) Cars[source] = nil end 
end) 
  
addEventHandler("onVehicleExplode",root,function() 
setTimer(destroyElement,2000,1,source) 
end) 
  
addCommandHandler( cmd, function(player, Command) 
    if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then 
        local mrker = getMarkerByHit( player ) 
        if mrker then 
            local id = tonumber ( getElementData( mrker, 'id') or 0 ) 
            if id == 0 then return end 
            if executeSQLQuery("DELETE FROM `Marker_System` WHERE `ID`=?", id) then 
                destroyElement( mrker ) 
                outputChatBox( "Marker Was Deleted", player, 255, 255, 0 ) 
            else 
                outputChatBox( "error", player, 255, 255, 0 )        
            end 
        end 
    else 
        outputChatBox( "Access denied", player, 255, 255, 0 )    
    end  
end 
) 
  
function getMarkerByHit( plr ) 
  for i, v in ipairs( getElementsByType( 'marker', rRoot ) ) do 
    if isElementWithinMarker(plr, v) then 
      return v 
    end 
  end 
  return false,outputChatBox( "Error: Please enter the marker", plr, 255, 255, 0 ) 
end 

The is here you can see it in the first file ;

local VehicleID = 411  

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