Greetings to those who came here . I have a problem , I can do so that the trucker has delivered the goods and received the money for it, writes to me that I 'm not in the car. How to do so that would be needed to bring the trailer with a load and take it, and not the car?
Sorry my English
Script
g_Me = getLocalPlayer()
gRoot = getRootElement()
gResRoot = getResourceRootElement( getThisResource () )
local screenW, screenH = guiGetScreenSize()
local jobPos = {
{"San Fiero","Материал",math.random (200, 300),1658.24805, 314.63394, 31.16051},
{"Los Santos","Материал",math.random (150, 250),2003.87732, -1415.97266, 16.99219,591}
}
local vehicle = {
{"International Navistar 9800", 515},
{"Peterbilt 387", 403},
{"Mack СН-613", 514}
}
local vehicleJob = { [515]=true, [514]=true, [403]=true }
function create3Dtext(markerName,text,z1)
local x, y, z = getElementPosition( markerName )
local cx, cy, cz = getCameraMatrix()
if isLineOfSightClear( cx, cy, cz, x, y, z, false, false, false, false, false, false, false, markerName ) then
local distance = getDistanceBetweenPoints3D( cx, cy, cz, x, y, z )
if distance < 0 then
local px, py = getScreenFromWorldPosition( x, y, z + z1, 0.06 )
if px then
dxDrawFramedText ( tostring(text),px, py,px, py, tocolor( 255, 255, 255, 255 ) , ( screenW/ 1440 ) * 2 , "default-bold" , "center" , "center" , false , false , false )
end
end
end
end
function dxDrawFramedText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI )
dxDrawText ( message , left + 1 , top + 1 , width + 1 , height + 1 , tocolor ( 0 , 0 , 0 , 255 ) , scale , font , alignX , alignY , clip , wordBreak , postGUI )
dxDrawText ( message , left + 1 , top - 1 , width + 1 , height - 1 , tocolor ( 0 , 0 , 0 , 255 ) , scale , font , alignX , alignY , clip , wordBreak , postGUI )
dxDrawText ( message , left - 1 , top + 1 , width - 1 , height + 1 , tocolor ( 0 , 0 , 0 , 255 ) , scale , font , alignX , alignY , clip , wordBreak , postGUI )
dxDrawText ( message , left - 1 , top - 1 , width - 1 , height - 1 , tocolor ( 0 , 0 , 0 , 255 ) , scale , font , alignX , alignY , clip , wordBreak , postGUI )
dxDrawText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , postGUI )
end
addEventHandler ( "onClientResourceStart",gResRoot,
function()
markerVehicle = createMarker( 1052.15625, 1913.7465820313, 10, 'Cylinder',1, 0, 0, 255, 40 )
JobPed = createPed ( 202,2811.02246, 892.47406, 10.75780 )
setPedFrozen ( JobPed, not isPedFrozen ( JobPed ) )
addEventHandler ( "onClientPedDamage" , JobPed ,damage)
end)
function damage( )
cancelEvent ( )
end
addEventHandler ( 'onClientRender', gRoot,
function()
create3Dtext(markerVehicle,"Выбор Транспорта",3 )
create3Dtext(JobPed,"Работа Дальнобойщика",1 )
end)
--===============================================Gui окна===================================================--
GUIEditor = {
gridlist = {},
button = {},
window = {},
}
GUIEditor.window[1] = guiCreateWindow((screenW - 330) / 2, (screenH - 307) / 2, 330, 307, "Выбор груза", false)
guiWindowSetSizable(GUIEditor.window[1], false)
guiSetVisible(GUIEditor.window[1],false)
GUIEditor.gridlist[1] = guiCreateGridList(9, 23, 311, 239, false, GUIEditor.window[1])
guiGridListAddColumn(GUIEditor.gridlist[1], "Город", 0.3)
guiGridListAddColumn(GUIEditor.gridlist[1], "Груз", 0.3)
GUIEditor.button[1] = guiCreateButton(10, 267, 121, 30, "Выбрать", false, GUIEditor.window[1])
guiSetFont(GUIEditor.button[1], "default-bold-small")
guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFFFFFFF")
for i,data in ipairs(jobPos) do
local row = guiGridListAddRow(GUIEditor.gridlist[1])
guiGridListSetItemText(GUIEditor.gridlist[1], row, 1, data[1], false, false)
guiGridListSetItemData(GUIEditor.gridlist[1], row, 1, {data[3],data[4],data[5],data[6],data[7]})
guiGridListSetItemText(GUIEditor.gridlist[1], row, 2, data[2], false, false)
guiGridListSetItemText(GUIEditor.gridlist[1], row, 3, data[3], false, false)
end
GUIEditor.window[2] = guiCreateWindow((screenW - 330) / 2, (screenH - 307) / 2, 330, 307, "Работа Дальнобойщика", false)
guiWindowSetSizable(GUIEditor.window[2], false)
guiSetVisible(GUIEditor.window[2],false)
GUIEditor.gridlist[2] = guiCreateGridList(9, 23, 311, 239, false, GUIEditor.window[2])
guiGridListAddColumn(GUIEditor.gridlist[2], "Скин", 0.9)
GUIEditor.button[3] = guiCreateButton(10, 267, 121, 30, "Работать", false, GUIEditor.window[2])
guiSetFont(GUIEditor.button[3], "default-bold-small")
guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FFFFFFFF")
GUIEditor.button[4] = guiCreateButton(199, 267, 121, 30, "Закрыть", false, GUIEditor.window[2])
guiSetFont(GUIEditor.button[4], "default-bold-small")
guiSetProperty(GUIEditor.button[4], "NormalTextColour", "FFFFFFFF")
GUIEditor.window[3] = guiCreateWindow((screenW - 330) / 2, (screenH - 307) / 2, 330, 307, "Выбор транспорта", false)
guiWindowSetSizable(GUIEditor.window[3], false)
guiSetVisible(GUIEditor.window[3],false)
GUIEditor.gridlist[3] = guiCreateGridList(9, 23, 311, 239, false, GUIEditor.window[3])
guiGridListAddColumn(GUIEditor.gridlist[3], "Транспорт", 0.9)
GUIEditor.button[5] = guiCreateButton(10, 267, 121, 30, "Выбрать", false, GUIEditor.window[3])
guiSetFont(GUIEditor.button[5], "default-bold-small")
guiSetProperty(GUIEditor.button[5], "NormalTextColour", "FFFFFFFF")
GUIEditor.button[6] = guiCreateButton(199, 267, 121, 30, "Закрыть", false, GUIEditor.window[3])
guiSetFont(GUIEditor.button[6], "default-bold-small")
guiSetProperty(GUIEditor.button[6], "NormalTextColour", "FFFFFFFF")
for i,v in ipairs(vehicle) do
local row = guiGridListAddRow(GUIEditor.gridlist[3])
guiGridListSetItemText(GUIEditor.gridlist[3], row, 1, tostring(v[1]), false, false)
guiGridListSetItemData(GUIEditor.gridlist[3], row, 1, tostring(v[2]))
end
--==================================================================================================--
addEventHandler( "onClientGUIClick", gRoot,
function ()
if source == GUIEditor.button[1] then
local row, col = guiGridListGetSelectedItem(GUIEditor.gridlist[1])
local data = guiGridListGetItemData(GUIEditor.gridlist[1], row, col)
if row and col and row ~= -1 and col ~=-1 then
money, x, y, z,trailer_id = unpack(data)
closeGui(GUIEditor.window[1])
OpenGui(GUIEditor.window[3])
end
elseif source == GUIEditor.button[5] then
local vehicle_id = guiGridListGetItemData( GUIEditor.gridlist[3], guiGridListGetSelectedItem( GUIEditor.gridlist[3] ) )
if vehicle_id then
triggerServerEvent ( "SetVehicle", g_Me,vehicle_id,trailer_id)
createM( g_Me,x, y, z )
closeGui(GUIEditor.window[3])
end
elseif source == GUIEditor.button[2] then
closeGui(GUIEditor.window[1])
elseif source == GUIEditor.button[6] then
closeGui(GUIEditor.window[3])
end
end
)
function closeGui(windows_id)
if guiGetVisible(windows_id) == true then
guiSetVisible(windows_id,false)
showCursor(false)
end
end
function OpenGui(windows_id)
if guiGetVisible(windows_id) == false then
guiSetVisible(windows_id,true)
showCursor(true)
end
end
function createM( thePlayer,x, y, z )
if ( isElement ( marker ) ) and ( isElement ( blip ) ) then
RemoveMarker()
end
marker = createMarker ( x, y, z, "cylinder", 15, 255, 255, 255, 90,thePlayer )
blip = createBlipAttachedTo (marker, 56, 2, 255, 0, 0, 255, 0, 99999999,thePlayer)
end
function RemoveMarker()
if isElement(marker) then
destroyElement(marker)
end
if isElement(blip) then
destroyElement(blip)
end
end
function wasted ( )
if ( isElement ( marker ) ) and ( isElement ( blip ) ) then
RemoveMarker()
end
end
addEventHandler ( "onClientPlayerWasted", g_Me, wasted )
addEventHandler( "onClientPlayerQuit", g_Me, wasted )
addEventHandler ("onClientMarkerHit",gRoot,
function( hitElement, matchingDimension )
if getElementType(hitElement) == "player" and (hitElement == g_Me) then
if ( source == marker ) then
local vehicle = getPedOccupiedVehicle(hitElement)
if vehicle and getVehicleController(vehicle) == hitElement and vehicleJob[getElementModel(vehicle)] then
if ( getElementData ( vehicle, "JobVeh" ) ) then
outputChatBox("Вы успешно доставили груз ваша зарплата #ffffff"..money.."#00ff00$" , 0, 255, 0, true )
triggerServerEvent("RemoveVehicle", hitElement,money)
RemoveMarker()
else
outputChatBox("Ты меня за дурака держешь что ли?", 255, 0, 0, true )
end
else
outputChatBox("Хаха, ты бы ещё на велике приехал, клоун..", 255, 255, 0, true )
end
elseif ( source == markerVehicle ) then
if not isPedInVehicle ( hitElement ) then
OpenGui(GUIEditor.window[1])
end
end
end
end
)
and the script responsible for creating the trailer:
gResRoot = getResourceRootElement( getThisResource () )
createBlip ( 1052.15625, 1913.7465820313, 9.75000, 51 )
function joinPilot(id)
setElementModel(source, id)
end
addEvent("SetSkin", true)
addEventHandler("SetSkin",root,joinPilot)
local trailer ={}
function vehicle(vehicle_id,trailer_id)
if ( isElement ( trailer[source] ) ) then
removeVeh(source)
end
trailer[source] = createVehicle ( tostring(trailer_id), 986.78558, 2129.03101, 11.71653,0,0,180 )
mBlip = createBlipAttachedTo ( trailer[source] )
setElementData ( trailer[source], "JobVeh", true )
end
addEvent("SetVehicle", true)
addEventHandler("SetVehicle",root,vehicle)
function removeVeh(thePlayer)
if isElement(trailer[thePlayer]) then
destroyElement(trailer[thePlayer])
destroyElement(mBlip)
end
end
function finish(money)
if ( isElement ( trailer[source] ) ) then
removeVeh(source)
end
givePlayerMoney ( source, money )
end
addEvent("RemoveVehicle", true)
addEventHandler("RemoveVehicle",root,finish)
function destroy ( )
if eventName == "onResourceStop" then
for _, thePlayer in ipairs ( getElementsByType ( "player" ) ) do
removeVeh(thePlayer)
end
else
removeVeh( source )
end
end
addEventHandler ( "onResourceStop", gResRoot, destroy )
addEventHandler ( "onPlayerWasted", root, destroy )
addEventHandler ( "onPlayerQuit", root, destroy )
---
parkgate1 = createObject( 968, 2777.123, 905.84, 10.666, 0, 90, 90 )
parkgate2 = createObject( 968, 2777.127, 920.71, 10.62, 0, -90, 90 )
parkmarker = createMarker(2777, 912.994, 7.75, "cylinder", 13, 255, 0, 0,0 )
isMoving = false
function gatefunc( hitPlayer )
if isMoving == false then
isMoving = true
moveObject ( parkgate1, 2000, 2777.123, 905.84, 10.666, 0, -90, 0, "OutBounce")
moveObject ( parkgate2, 2000, 2777.127, 920.71, 10.62, 0, 90, 0, "OutBounce")
setTimer( triggerEvent, 3000, 1, "gatefuncclose", root)
end
end
addEventHandler( "onMarkerHit", parkmarker, gatefunc )
function gatefuncclose( )
moveObject ( parkgate1, 2000, 2777.123, 905.84, 10.666, 0, 90, 0, "OutBounce")
moveObject ( parkgate2, 2000, 2777.127, 920.71, 10.62, 0, -90, 0, "OutBounce")
setTimer ( function()
isMoving = false
end, 2000, 1 )
end
addEvent ( "gatefuncclose", true )
addEventHandler("gatefuncclose", getRootElement(), gatefuncclose)