Jump to content

[Help] Vehicle Spawner


Snow-Man

Recommended Posts

Posted

i have made a Vehicle Spawner to Police Job, but i have got a problem on Showing GUI to Occupation, i made like this

Evehicle = getElementData(source, "vehicles") 
   occupation = getElementData(source, "Occupation") 
if ( Evehicle == "Police Officer" ) and ( occupation == "Police Officer") then 
guiSetVisible(window[1], true) 
showCursor(true) 

and the Element of Vehicles is definated

here

local Marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
setElementData(Marker, "vehicles",v.role) 

no errors

thanks for reading :)

Posted
Post your whole code (server and client)

line from table

theTable = { 
{role = "Police Officer", mx=2256.1411132813,my=2444.4133300781,mz=9.8203125,mr=41,mg=41, mb=247, rz=90}, 
} 

no Problem in Server side, the Problem in showing GUI

Posted
in code 1

need end .. and where event ? .. and u sure this name window is correct ?

i told before, window definated, and no errors and all functions definated Correctly, i guess the Problem from element data

Posted
put ur all code
local Markers = { 
-- LS Markers 
{role = "Police Officer", mx=1550.3958740234, my=-1609.7741699219,mz=12.3828125,mr=41,mg=41, mb=247, rz=267.83172607422}, 
{role = "Police Officer", mx=1578.7170410156,my=-1609.7991943359, mz=12.3828125,mr=41,mg=41, mb=247, rz=178.85244750977}, 
-- LV Markers  
{role = "Police Officer", mx=2256.1411132813,my=2444.4133300781,mz=9.8203125,mr=41,mg=41, mb=247, rz=90}, 
{role = "Police Officer", mx=2256.1884765625,my=2476.5065917969, mz=9.8203125, mr=41,mg=41, mb=247, rz=90}, 
-- SF Markers  
{role = "Police Officer", mx=-1593.6441650391, my=652.44372558594,mz=6.1875,mr=41,mg=41, mb=247, rz=0.082412347197533}, 
{role = "Police Officer", mx=-1616.6040039063,my=651.50634765625,mz=6.1875,mr=41,mg=41, mb=247, rz=0.082412347197533}, 
-- LS Bus Job  
{role = "Bus Driver", mx=1098.8491210938,my=-1766.7958984375, mz=12.350924491882, mr=255, mg=216, mb=0, rz=90.146255493164}, 
  
  
} 
  
local button = {} 
local window = {} 
  
        window[1] = guiCreatewindow[1](370, 277, 305, 402, "UGC  ~  Vehicles Spawner", false) 
        guiSetVisible(window[1], false) 
        guiwindow[1]SetSizable(window[1], false) 
        gridlist = guiCreateGridList(9, 63, 282, 268, false, window[1]) 
        Col1 = guiGridListAddColumn(gridlist, "Vehicles", 0.5) 
        Col2 = guiGridListAddColumn(gridlist, "id", 0.5) 
        button[1] = guiCreateButton(10, 350, 113, 22, "Spawn", false, window[1]) 
        guiSetFont(button[1], "default-bold-small") 
        guiSetProperty(button[1], "NormalTextColour", "FFAAAAAA") 
        button[2] = guiCreateButton(178, 350, 113, 22, "Hide", false, window[1]) 
        guiSetFont(button[2], "default-bold-small") 
        guiSetProperty(button[2], "NormalTextColour", "FFAAAAAA")     
    
   function hit(me) 
   Evehicle = getElementData(source, "vehicles") 
   occupation = getElementData(source, "Occupation") 
   mx, my, mz = getElementPosition(source) 
if ( Evehicle == "Police Officer" ) and ( occupation == "Police Officer") then 
guiSetVisible(window[1], true) 
showCursor(true) 
  
end 
end 

that all i can post it

Posted

addEventHandler( "onClientMarkerHit", resourceRoot, function( element ) 
  if ( source == Marker ) then 
    if ( element == getLocalPlayer(   ) ) then 
     if ( getElementData( source, "vehicles" ) == "Police Officer" ) and ( getElementData( source, "Occupation" ) == "Police Officer") then 
                guiSetVisible( window[1], true ) 
                showCursor( guiGetVisible ( window[1] ) ) 
             end 
         end 
     end 
end ) 

and lock at line 22 ``

Posted
addEventHandler( "onClientMarkerHit", resourceRoot, function( element ) 
  if ( source == Marker ) then 
    if ( element == getLocalPlayer(   ) ) then 
     if ( getElementData( source, "vehicles" ) == "Police Officer" ) and ( getElementData( source, "Occupation" ) == "Police Officer") then 
                guiSetVisible( window[1], true ) 
                showCursor( guiGetVisible ( window[1] ) ) 
             end 
         end 
     end 
end ) 

and lock at line 22 ``

the problem at line 22 from copying and pasting

and i tried your script its not work :(

help?

Posted
  
local Marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
setElementData(Marker, "vehicles",v.role) 
  

Are you even setting the marker "Occupation" data to the correct job? Because it seems like you mean to check the occupation of the player, and not the marker. In that case you should use this

  
local Marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
setElementData(Marker, "vehicles",v.role) 
addEventHandler("onClientMarkerHit", Marker, vehicleMarkerHit) 
  
function vehicleMarkerHit(hitElement) 
  if hitElement == localPlayer then 
    if getElementData(source, "vehicles") == getElementData(localPlayer, "Occupation") then 
      guiSetVisible(window[1],true) 
      showCursor(guiGetVisible(window[1])) 
    end 
  end 
end 
  

Posted
  
local Marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
setElementData(Marker, "vehicles",v.role) 
  

Are you even setting the marker "Occupation" data to the correct job? Because it seems like you mean to check the occupation of the player, and not the marker. In that case you should use this

  
local Marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
setElementData(Marker, "vehicles",v.role) 
addEventHandler("onClientMarkerHit", Marker, vehicleMarkerHit) 
  
function vehicleMarkerHit(hitElement) 
  if hitElement == localPlayer then 
    if getElementData(source, "vehicles") == getElementData(localPlayer, "Occupation") then 
      guiSetVisible(window[1],true) 
      showCursor(guiGetVisible(window[1])) 
    end 
  end 
end 
  

no, why should i set data to Occupation because it already Exist

if i do like that Medic Markers won't work and error will be anyone allowed to spawn vehicles in others Markers job

Posted

I meant, what you are doing is when the player hits the marker, you check the "vehicles" data and the "Occupation" data of that marker, and if they're equal, you continue the function. But when you create the marker, you only set the "vehicles" data to the corresponding role (v.role) and you don't set the "Occupation" data anywhere(as far as I can see.) This would mean that when you try and get their data's, "vehicles" would return the correct role, and "Occupation" would return nill thus the function discontinues.

So what I did was checking the "vehicles" data of the marker, and the "Occupation" data from the player, so if the player has the job the marker spawns vehicles for, the function continues, and otherwise it doesn't. Your script doesn't check the job of the player anywhere.

  • Moderators
Posted

Ok try this:

-- easier to replace the name if needed 
local ROLES = { 
    POLICE_OFFICER = "Police Officer", 
    BUS_DRIVER = "Bus Driver" 
} 
  
local roleMarkers = { 
    -- LS Markers 
    {role = ROLES.POLICE_OFFICER, mx=1550.3958740234, my=-1609.7741699219,mz=12.3828125,mr=41,mg=41, mb=247, rz=267.83172607422}, 
    {role = ROLES.POLICE_OFFICER, mx=1578.7170410156,my=-1609.7991943359, mz=12.3828125,mr=41,mg=41, mb=247, rz=178.85244750977}, 
    -- LV Markers 
    {role = ROLES.POLICE_OFFICER, mx=2256.1411132813,my=2444.4133300781,mz=9.8203125,mr=41,mg=41, mb=247, rz=90}, 
    {role = ROLES.POLICE_OFFICER, mx=2256.1884765625,my=2476.5065917969, mz=9.8203125, mr=41,mg=41, mb=247, rz=90}, 
    -- SF Markers 
    {role = ROLES.POLICE_OFFICER, mx=-1593.6441650391, my=652.44372558594,mz=6.1875,mr=41,mg=41, mb=247, rz=0.082412347197533}, 
    {role = ROLES.POLICE_OFFICER, mx=-1616.6040039063,my=651.50634765625,mz=6.1875,mr=41,mg=41, mb=247, rz=0.082412347197533}, 
    -- LS Bus Job 
    {role = ROLES.BUS_DRIVER, mx=1098.8491210938,my=-1766.7958984375, mz=12.350924491882, mr=255, mg=216, mb=0, rz=90.146255493164}, 
} 
  
for i,v in ipairs(roleMarkers) do 
    local marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
    setElementData(marker, "role", v.role) 
    addEventHandler("onClientMarkerHit", marker, onRoleMarkerHit) 
end 
  
local button = {} 
local window = {} 
  
window[1] = guiCreatewindow[1](370, 277, 305, 402, "UGC  ~  Vehicles Spawner", false) 
guiSetVisible(window[1], false) 
guiwindow[1]SetSizable(window[1], false) 
gridlist = guiCreateGridList(9, 63, 282, 268, false, window[1]) 
Col1 = guiGridListAddColumn(gridlist, "Vehicles", 0.5) 
Col2 = guiGridListAddColumn(gridlist, "id", 0.5) 
button[1] = guiCreateButton(10, 350, 113, 22, "Spawn", false, window[1]) 
guiSetFont(button[1], "default-bold-small") 
guiSetProperty(button[1], "NormalTextColour", "FFAAAAAA") 
button[2] = guiCreateButton(178, 350, 113, 22, "Hide", false, window[1]) 
guiSetFont(button[2], "default-bold-small") 
guiSetProperty(button[2], "NormalTextColour", "FFAAAAAA") 
guiSetVisible(window[1], false) 
  
function onRoleMarkerHit( element ) 
    if element ~= localPlayer then return end 
    local markerRole = getElementData(source, "role") 
    local playerRole = getElementData(element, "Occupation") 
    mx, my, mz = getElementPosition(source) 
    if markerRole == ROLES.POLICE_OFFICER and playerRole == ROLE.POLICE_OFFICER then 
        guiSetVisible(window[1], true) 
        showCursor(true) 
    end 
end 

  • Moderators
Posted
thanks Citizen

No problem.

line 32
guiWindowSetSizable(window[1], false) 

Yeah, didn't see but you pasted it like this. I mean it's not my error.

Cheers,

Citizen

Posted
thanks Citizen

No problem.

line 32
guiWindowSetSizable(window[1], false) 

Yeah, didn't see but you pasted it like this. I mean it's not my error.

Cheers,

Citizen

yes, i know

Anyways Thanks :)

  • Moderators
Posted

Ok so ... There were some errors that were shown.

Do you know that client side errors doesn't display on the server console right ?

You have to use /debugscript 3 as admin (so /login first and be sure you are in the admin acl group).

Anyway, here is the fixed code:

local button = {} 
local window = {} 
  
window[1] = guiCreateWindow(370, 277, 305, 402, "UGC  ~  Vehicles Spawner", false) 
guiSetVisible(window[1], false) 
guiWindowSetSizable(window[1], false) 
gridlist = guiCreateGridList(9, 63, 282, 268, false, window[1]) 
Col1 = guiGridListAddColumn(gridlist, "Vehicles", 0.5) 
Col2 = guiGridListAddColumn(gridlist, "id", 0.5) 
button[1] = guiCreateButton(10, 350, 113, 22, "Spawn", false, window[1]) 
guiSetFont(button[1], "default-bold-small") 
guiSetProperty(button[1], "NormalTextColour", "FFAAAAAA") 
button[2] = guiCreateButton(178, 350, 113, 22, "Hide", false, window[1]) 
guiSetFont(button[2], "default-bold-small") 
guiSetProperty(button[2], "NormalTextColour", "FFAAAAAA") 
guiSetVisible(window[1], false) 
  
function onRoleMarkerHit( element ) 
    if element ~= localPlayer then return end 
    local markerRole = getElementData(source, "role") 
    local playerRole = getElementData(element, "Occupation") 
    mx, my, mz = getElementPosition(source) 
    if markerRole == ROLES.POLICE_OFFICER and playerRole == ROLES.POLICE_OFFICER then 
        guiSetVisible(window[1], true) 
        showCursor(true) 
    end 
end 
  
for i,v in ipairs(roleMarkers) do 
    local marker = createMarker(v.mx, v.my, v.mz, "cylinder", 1.5, v.mr, v.mg, v.mb) 
    setElementData(marker, "role", v.role) 
    addEventHandler("onClientMarkerHit", marker, onRoleMarkerHit) 
end 

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