Jump to content

Help Me With Vehicle Spawn


Recommended Posts

------------------------------------------------------------------------------------ 
-- PROJECT: N/A 
-- DEVELOPERS:  Sebbe 
-- RIGHTS:  All rights reserved by developers 
------------------------------------------------------------------------------------ 
  
dataToFindPlayersJob = "gang" 
  
vehicles = 
    { 
        {Roles = "FBI", vehicles = {427, 596}, x = 1592.8000488281, y = -1606.9000244141, z = 13.39999961853, rotation = 25, r = 250, g = 250, b = 250, vehR = 0, vehG = 0, vehB = 255}, 
        {Roles = "FBI", vehicles = {427, 596}, x = 1592.8000488281, y = -1606.9000244141, z = 13.39999961853, rotation = 25, r = 250, g = 250, b = 250, vehR = 0, vehG = 0, vehB = 255}, 
    } 
  

There, you can read "ROTATION".

That's a table.

Link to comment

This is what I have for now :D

------------------------------------------------------------------------------------ 
-- PROJECT: N/A 
-- DEVELOPERS:  Sebbe 
-- RIGHTS:  All rights reserved by developers 
------------------------------------------------------------------------------------ 
  
dataToFindPlayersJob = "gang" 
  
vehicles = 
    { 
        {Roles = "SWAT", vehicles = {596, 597, 598, 599}, x = 1592.8000488281, y = -1606.9000244141, z = 13.39999961853, rotation = 50, r = 0, g = 0, b = 250, vehR = 0, vehG = 0, vehB = 250}, 
        {Roles = "Police", vehicles = {596, 597, 598, 599}, x = 1592.8000488281, y = -1606.9000244141, z = 13.39999961853, rotation = 50, r = 0, g = 0, b = 250, vehR = 0, vehG = 0, vehB = 250}, 
        {Roles = "USNS", vehicles = {595, 473, 446}, x = -1444.4000244141, y = 507.20001220703, z = 0, rotation = 0, r = 45, g = 60, b = 15, vehR = 45, vehG = 60, vehB = 15}, 
        {Roles = "USNS", vehicles = {595, 473, 446}, x = -1444.5999755859, y = 495.39999389648, z = 0, rotation = 0, r = 45, g = 60, b = 15, vehR = 45, vehG = 60, vehB = 15}, 
        {Roles = "USNS", vehicles = {476, 487, 548, 519}, x = -1261.0999755859, y = 507.60000610352, z = 17.200000762939, rotation = 0, r = 45, g = 60, b = 15, vehR = 45, vehG = 60, vehB = 15}, 
        {Roles = "USNS", vehicles = {500, 468, 579, 428, 415, 471, 568}, x = -1241.8000488281, y = 449.5, z = 7.1999998092651, rotation = 0, r = 45, g = 60, b = 15, vehR = 45, vehG = 60, vehB = 15}, 
        {Roles = "USNS", vehicles = {500, 468, 579, 428, 415, 471, 568}, x = -1242, y = 467.29998779297, z = 7.1999998092651, rotation = 0, r = 45, g = 60, b = 15, vehR = 45, vehG = 60, vehB = 15}, 
        {Roles = "SWAT", vehicles = {596, 597, 598, 599, 560, 427, 523, 528, 601, 490}, x = 1246.5, y = -1669.9000244141, z = 13.60000038147, rotation = 0, r = 0, g = 0, b = 70, vehR = 0, vehG = 0, vehB = 70}, 
        {Roles = "SWAT", vehicles = {596, 597, 598, 599, 560, 427, 523, 528, 601, 490}, x = 1236.1999511719, y = -1669.9000244141, z = 13.60000038147, rotation = 0, r = 0, g = 0, b = 70, vehR = 0, vehG = 0, vehB = 70}, 
        {Roles = "SWAT", vehicles = {596, 597, 598, 599, 560, 427, 523, 528, 601, 490}, x = 1223, y = -1669.6999511719, z = 13.60000038147, rotation = 0, r = 0, g = 0, b = 70, vehR = 0, vehG = 0, vehB = 70}, 
    } 
  

Link to comment

I have already problems with rotation:

Server:

local vehicle = {} 
  
function isVehicleSpawned(vehicle) 
    return getElementData(vehicle, "jobvehicle") 
end 
  
function doesPlayerHaveVehicleSpawned(player) 
    if (isElement(vehicle[player])) then  
        return true 
    else 
        return false 
    end 
end 
  
function destroyVehicle(vehicle, player) 
    if (isElement(vehicle[player])) then 
        destroyElement(vehicle[player]) 
    end 
end 
  
function createTheJobVehicles() 
    for index, table in ipairs(vehicles) do 
        marker = createMarker(table.x, table.y, table.z, "cylinder", 2, table.r, table.g, table.b) 
        setElementData(marker, "vehiclemarker-role", table.Roles) 
        setElementData(marker, "vehiclemarker-vehicles", table.vehicles) 
        setElementData(marker, "vehiclemarker-rotation", table.rotation) 
        vehicle[marker] = table.Roles 
        local position = table.x..", "..table.y..", "..table.z..", "..", "..table.rotation 
        local color = table.vehR..", "..table.vehG..", "..table.vehB..", " 
        setElementData(marker, "vehiclemarker-position", position) 
        setElementData(marker, "vehiclemarker-color", color) 
        addEventHandler("onMarkerHit", marker, onPlayerVehicleMarkerHit) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, createTheJobVehicles) 
  
function onPlayerVehicleMarkerHit(player) 
    local role = getElementData(source, "vehiclemarker-role") 
    local vehicles = getElementData(source, "vehiclemarker-vehicles") 
    local rotation = getElementData(source, "vehiclemarker-rotation") 
    if (getElementType(player) == "player") then 
        if (getElementData(player, dataToFindPlayersJob) == role or role == "ALL") then 
            if (isPedInVehicle(player)) then return end 
            local position = getElementData(source, "vehiclemarker-position") 
            local color = getElementData(source, "vehiclemarker-color") 
            local posX, posY, posZ, rotation = unpack(split(position, ",")) 
            local r, g, b = unpack(split(color, ",")) 
            triggerClientEvent(player, "jobvehicles.showVehicleGUI", root, vehicles, rotation, posX, posY, posZ, rotation, r, g, b) 
  
        end 
    end 
end 
  
  
function onPlayerSpawnVehicle(vid, vx, vy, vz, rotation, r, g, b) 
    if (isElement(vehicle[client])) then  
        destroyElement(vehicle[client]) 
    end 
    vehicle[client] = createVehicle(vid, vx, vy, vz) 
    setElementData(vehicle[client], "jobvehicle", true) 
    warpPedIntoVehicle(client, vehicle[client]) 
    setElementRotation(vehicle[client], 0, 0, rotation) 
    outputDebugString(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid)) 
    outputServerLog(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid).."'") 
    if (r) then 
        setVehicleColor(vehicle[client], r, g, b) 
    end 
end 
addEvent("jobvehicles.onPlayerSpawnVehicle", true) 
addEventHandler("jobvehicles.onPlayerSpawnVehicle", root, onPlayerSpawnVehicle) 
  
function destroyPlayerVehicle() 
    if (isElement(vehicle[source])) then 
        destroyElement(vehicle[source]) 
    end 
end 
addEventHandler("onPlayerWasted", root, destroyPlayerVehicle) 
addEventHandler("onPlayerLogout", root, destroyPlayerVehicle) 
addEventHandler("onPlayerQuit", root, destroyPlayerVehicle) 
  
function destroyMyOwnVehicle(player) 
    if (isElement(vehicle[player])) then  
        outputChatBox("You have succesfully destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).."!", player, 0, 255, 10) 
        destroyElement(vehicle[player]) 
    elseif (not isElement(vehicle[player])) then 
        outputChatBox("You currently do not have a job vehicle spawned to destroy!", player, 250, 0, 0) 
    end 
end 
addCommandHandler("destroyv", destroyMyOwnVehicle) 
  
  
function destroyVehicleOnExplode() 
    if (getElementData(source, "jobvehicle")) then 
        destroyElement(source) 
    end 
end 
addEventHandler("onVehicleExplode", root, destroyVehicleOnExplode) 
  
function onAdminDestroyJobVehicle(admin, cmd, target) 
    local accountname = getAccountName(getPlayerAccount(admin)) 
    if (hasObjectPermissionTo("user."..accountname, "function.kickPlayer") and target) then 
        local player = getPlayerFromName(target) 
        if (isElement(vehicle[player]) and player) then 
            outputChatBox("You have destroyed "..getPlayerName(player).."' s "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", admin, 0, 255, 10) 
            outputChatBox(getPlayerName(admin).." has destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", player, 255, 10, 0) 
            destroyElement(vehicle[player]) 
        elseif (not isElement(vehicle[player]) and player) then 
            outputChatBox(getPlayerName(player).. " does not currently have any job vehicle spawned.", admin, 255, 10, 0) 
        else 
            outputChatBox("The player do not exist!", admin, 250, 0, 0) 
        end 
    end 
end 
addCommandHandler("dv", onAdminDestroyJobVehicle) 
  

Client:

local screenWidth, screenHeight = guiGetScreenSize() 
local v_table = {} 
  
  
function createVehicleChooserGUI() 
    if (isElement(wndVehicle)) then 
        if (guiGetVisible(wndVehicle)) then return end 
    end 
    wndVehicle = guiCreateWindow(385, 165, 280, 383, "Vehicle spawn",false) 
vehicleLabel = guiCreateLabel(9,25,262,25,"Select vehicle:",false,wndVehicle) 
    gridVehicle = guiCreateGridList(9,47,260,285,false,wndVehicle) 
    vehicleColumn = guiGridListAddColumn(gridVehicle,"Vehicle",0.-- s8) -->
    vehicleSpawn = guiCreateButton(151,336,122,38,"Select",false,wndVehicle) 
    vehicleClose = guiCreateButton(9,336,122,38,"Close",false,wndVehicle) 
    addEventHandler("onClientGUIClick", vehicleSpawn, onPlayerSelectVehicle) 
    addEventHandler("onClientGUIClick", vehicleClose, onPlayerExitVehicleGUI) 
end 
  
function showVehicleGUI(vehicles, rotation, posX, posY, posZ, rotation, r, g, b) 
    createVehicleChooserGUI() 
    v_table[1] = posX 
    v_table[2] = posY 
    v_table[3] = posZ 
    v_table[4] = rotation 
    v_table[5] = r 
    v_table[6] = g 
    v_table[7] = b 
    showCursor(true) 
    guiGridListClear(gridVehicle) 
    for index, vehicles in ipairs(vehicles) do 
        vehicleRow = guiGridListAddRow(gridVehicle) 
        guiGridListSetItemText(gridVehicle, vehicleRow, vehicleColumn, getVehicleNameFromModel(vehicles), false, true) 
    end 
end 
addEvent("jobvehicles.showVehicleGUI", true) 
addEventHandler("jobvehicles.showVehicleGUI", root, showVehicleGUI) 
  
function onPlayerExitVehicleGUI(button, state) 
    if (button ~= "left" or state ~= "up") then return end 
    guiSetVisible(wndVehicle, false) 
    showCursor(false) 
end 
  
function onPlayerSelectVehicle(button, state) 
    if (button ~= "left" or state ~= "up") then return end 
    if (guiGridListGetSelectedItem(gridVehicle) == -1) then return end 
    local vrow = guiGridListGetSelectedItem(gridVehicle) 
    local vname = guiGridListGetItemText(gridVehicle, vrow, vehicleColumn) 
    local vid = getVehicleModelFromName(vname) 
    guiSetVisible(wndVehicle, false) 
    showCursor(false) 
    triggerServerEvent("jobvehicles.onPlayerSpawnVehicle", root, vid, v_table[1], v_table[2], v_table[3], v_table[4], v_table[5], v_table[6], v_table[7]) 
end 
  

Link to comment
I have already problems with rotation:

Server:

local vehicle = {} 
  
function isVehicleSpawned(vehicle) 
    return getElementData(vehicle, "jobvehicle") 
end 
  
function doesPlayerHaveVehicleSpawned(player) 
    if (isElement(vehicle[player])) then  
        return true 
    else 
        return false 
    end 
end 
  
function destroyVehicle(vehicle, player) 
    if (isElement(vehicle[player])) then 
        destroyElement(vehicle[player]) 
    end 
end 
  
function createTheJobVehicles() 
    for index, table in ipairs(vehicles) do 
        marker = createMarker(table.x, table.y, table.z, "cylinder", 2, table.r, table.g, table.b) 
        setElementData(marker, "vehiclemarker-role", table.Roles) 
        setElementData(marker, "vehiclemarker-vehicles", table.vehicles) 
        setElementData(marker, "vehiclemarker-rotation", table.rotation) 
        vehicle[marker] = table.Roles 
        local position = table.x..", "..table.y..", "..table.z..", "..", "..table.rotation 
        local color = table.vehR..", "..table.vehG..", "..table.vehB..", " 
        setElementData(marker, "vehiclemarker-position", position) 
        setElementData(marker, "vehiclemarker-color", color) 
        addEventHandler("onMarkerHit", marker, onPlayerVehicleMarkerHit) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, createTheJobVehicles) 
  
function onPlayerVehicleMarkerHit(player) 
    local role = getElementData(source, "vehiclemarker-role") 
    local vehicles = getElementData(source, "vehiclemarker-vehicles") 
    local rotation = getElementData(source, "vehiclemarker-rotation") 
    if (getElementType(player) == "player") then 
        if (getElementData(player, dataToFindPlayersJob) == role or role == "ALL") then 
            if (isPedInVehicle(player)) then return end 
            local position = getElementData(source, "vehiclemarker-position") 
            local color = getElementData(source, "vehiclemarker-color") 
            local posX, posY, posZ, rotation = unpack(split(position, ",")) 
            local r, g, b = unpack(split(color, ",")) 
            triggerClientEvent(player, "jobvehicles.showVehicleGUI", root, vehicles, rotation, posX, posY, posZ, rotation, r, g, b) 
  
        end 
    end 
end 
  
  
function onPlayerSpawnVehicle(vid, vx, vy, vz, rotation, r, g, b) 
    if (isElement(vehicle[client])) then  
        destroyElement(vehicle[client]) 
    end 
    vehicle[client] = createVehicle(vid, vx, vy, vz) 
    setElementData(vehicle[client], "jobvehicle", true) 
    warpPedIntoVehicle(client, vehicle[client]) 
    setElementRotation(vehicle[client], 0, 0, rotation) 
    outputDebugString(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid)) 
    outputServerLog(getPlayerName(client).. " has spawned a '"..getVehicleNameFromModel(vid).."'") 
    if (r) then 
        setVehicleColor(vehicle[client], r, g, b) 
    end 
end 
addEvent("jobvehicles.onPlayerSpawnVehicle", true) 
addEventHandler("jobvehicles.onPlayerSpawnVehicle", root, onPlayerSpawnVehicle) 
  
function destroyPlayerVehicle() 
    if (isElement(vehicle[source])) then 
        destroyElement(vehicle[source]) 
    end 
end 
addEventHandler("onPlayerWasted", root, destroyPlayerVehicle) 
addEventHandler("onPlayerLogout", root, destroyPlayerVehicle) 
addEventHandler("onPlayerQuit", root, destroyPlayerVehicle) 
  
function destroyMyOwnVehicle(player) 
    if (isElement(vehicle[player])) then  
        outputChatBox("You have succesfully destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).."!", player, 0, 255, 10) 
        destroyElement(vehicle[player]) 
    elseif (not isElement(vehicle[player])) then 
        outputChatBox("You currently do not have a job vehicle spawned to destroy!", player, 250, 0, 0) 
    end 
end 
addCommandHandler("destroyv", destroyMyOwnVehicle) 
  
  
function destroyVehicleOnExplode() 
    if (getElementData(source, "jobvehicle")) then 
        destroyElement(source) 
    end 
end 
addEventHandler("onVehicleExplode", root, destroyVehicleOnExplode) 
  
function onAdminDestroyJobVehicle(admin, cmd, target) 
    local accountname = getAccountName(getPlayerAccount(admin)) 
    if (hasObjectPermissionTo("user."..accountname, "function.kickPlayer") and target) then 
        local player = getPlayerFromName(target) 
        if (isElement(vehicle[player]) and player) then 
            outputChatBox("You have destroyed "..getPlayerName(player).."' s "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", admin, 0, 255, 10) 
            outputChatBox(getPlayerName(admin).." has destroyed your "..getVehicleNameFromModel(getElementModel(vehicle[player])).." (jobvehicle)", player, 255, 10, 0) 
            destroyElement(vehicle[player]) 
        elseif (not isElement(vehicle[player]) and player) then 
            outputChatBox(getPlayerName(player).. " does not currently have any job vehicle spawned.", admin, 255, 10, 0) 
        else 
            outputChatBox("The player do not exist!", admin, 250, 0, 0) 
        end 
    end 
end 
addCommandHandler("dv", onAdminDestroyJobVehicle) 
  

Client:

local screenWidth, screenHeight = guiGetScreenSize() 
local v_table = {} 
  
  
function createVehicleChooserGUI() 
    if (isElement(wndVehicle)) then 
        if (guiGetVisible(wndVehicle)) then return end 
    end 
    wndVehicle = guiCreateWindow(385, 165, 280, 383, "Vehicle spawn",false) 
vehicleLabel = guiCreateLabel(9,25,262,25,"Select vehicle:",false,wndVehicle) 
    gridVehicle = guiCreateGridList(9,47,260,285,false,wndVehicle) 
    vehicleColumn = guiGridListAddColumn(gridVehicle,"Vehicle",0.-- s8) -->
    vehicleSpawn = guiCreateButton(151,336,122,38,"Select",false,wndVehicle) 
    vehicleClose = guiCreateButton(9,336,122,38,"Close",false,wndVehicle) 
    addEventHandler("onClientGUIClick", vehicleSpawn, onPlayerSelectVehicle) 
    addEventHandler("onClientGUIClick", vehicleClose, onPlayerExitVehicleGUI) 
end 
  
function showVehicleGUI(vehicles, rotation, posX, posY, posZ, rotation, r, g, b) 
    createVehicleChooserGUI() 
    v_table[1] = posX 
    v_table[2] = posY 
    v_table[3] = posZ 
    v_table[4] = rotation 
    v_table[5] = r 
    v_table[6] = g 
    v_table[7] = b 
    showCursor(true) 
    guiGridListClear(gridVehicle) 
    for index, vehicles in ipairs(vehicles) do 
        vehicleRow = guiGridListAddRow(gridVehicle) 
        guiGridListSetItemText(gridVehicle, vehicleRow, vehicleColumn, getVehicleNameFromModel(vehicles), false, true) 
    end 
end 
addEvent("jobvehicles.showVehicleGUI", true) 
addEventHandler("jobvehicles.showVehicleGUI", root, showVehicleGUI) 
  
function onPlayerExitVehicleGUI(button, state) 
    if (button ~= "left" or state ~= "up") then return end 
    guiSetVisible(wndVehicle, false) 
    showCursor(false) 
end 
  
function onPlayerSelectVehicle(button, state) 
    if (button ~= "left" or state ~= "up") then return end 
    if (guiGridListGetSelectedItem(gridVehicle) == -1) then return end 
    local vrow = guiGridListGetSelectedItem(gridVehicle) 
    local vname = guiGridListGetItemText(gridVehicle, vrow, vehicleColumn) 
    local vid = getVehicleModelFromName(vname) 
    guiSetVisible(wndVehicle, false) 
    showCursor(false) 
    triggerServerEvent("jobvehicles.onPlayerSpawnVehicle", root, vid, v_table[1], v_table[2], v_table[3], v_table[4], v_table[5], v_table[6], v_table[7]) 
end 
  

Did I have to change something because the script just fked up

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