Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2020-11-03, 14:27


kazet12383







Wiek: 30
Na forum: 2340 dni
Posty: 14
Nick w MP: toja



Respekt: 50

Znalazlem fajny angielski skrypt na prace dorywcz? - kierowc? ci??ar?wki. I teraz mam pytanie. Pozmienialem polecenia na chacie na polskie i spolszczylem gui. Jak ustawi? w tym kodzie zarobki (zmieni? je, bo s? za niskie, serwer ma jaki? smieszny przelicznik i trzeba by dopisac z 2-3 zera) oraz jak naprawic gui, bo jak wejdziesz w nie, to nie wyjdziesz bez wybrania jednej z dwoch opcji.


client
cargoMarkers = {--Player hits cargoMarker and list is shown, "Locations" table contains the locations on that list.
{2213.8576660156, -2226.1547851563, 12, "Ocean Docks"},
{2747.6467285156, -2410.5747070313, 13.45193195343, "Easter Basin"},
{1613.8598632813, 2330.9729003906, 10.8203125, "Redsands West"},
{-1623.6088867188, 77.336196899414, 3.5546875, "Easter Basin"}
}

local shipmentMarkerVault = {}
local shipmentBlipVault = {}

Locations = {--Here is the table for the locations on cargo list, x, y, z, location (cash is calculated in below function)
{-1351.5205078125, -503.66796875, 14.171875, "SF Airport"},
{2838.658203125, 999.6708984375, 10.75, "Linden Side"},
{2262.89453125, 2792.927734375, 10.8203125, "Spinybed"},
{-576.53063964844, -550.34674072266, 25.529611587524, "Fallen Tree"},
{1414.8941650391, 1088.4053955078, 10.8203125, "LVA Freight Depot"},
{1696.5225830078, 2329.0310058594, 10.8203125, "Redsands West"}
}--Above table is places the player will choose when they hit a "cargoMarker" from the first table, remember to read how the tables are structured.


local Name
local marker
local blip
local cash

function spawnTheTruck(md)
local screenW, screenH = guiGetScreenSize()
    window = guiCreateWindow((screenW - 312) / 2, (screenH - 104) / 2, 312, 104, "Zespawnowac ci pojazd, czy masz juz wczesniejszy?", false)
    guiWindowSetSizable(window, false)
    showCursor(true)
    
    label1 = guiCreateLabel(56, 27, 201, 17, "Tak - zespawnuj.", false, window)
    label2 = guiCreateLabel(56, 40, 201, 17, "Nie - Mam poprzedni.", false, window)
    guiLabelSetHorizontalAlign ( label1, "center")
    guiLabelSetHorizontalAlign ( label2, "center")
    
    Yes_btn = guiCreateButton(56, 64, 89, 30, "Yes", false, window)
    No_btn = guiCreateButton(168, 65, 89, 29, "No", false, window) 

    marker_data = md
        
    addEventHandler("onClientGUIClick", Yes_btn, spawnYes)
    addEventHandler("onClientGUIClick", No_btn, spawnNo)
end

addEvent("spawnTruck", true)
addEventHandler("spawnTruck", getRootElement(), spawnTheTruck)

function spawnYes(button, state)
    if source == Yes_btn and button == "left" and state == "up" then 
            triggerServerEvent("spawnTruckYes", root, localPlayer, marker_data)
            destroyElement(window)
            showCursor(false)
    end
end

function spawnNo(button, state)
    if source == No_btn and button == "left" and state == "up" then 
        triggerServerEvent("spawnTruckNo", root, localPlayer)
        destroyElement(window)
        showCursor(false)
    end
end

function showGUI()
local screenW, screenH = guiGetScreenSize()
    window = guiCreateWindow((screenW - 498) / 2, (screenH - 266) / 2, 498, 266, "Shipments", false)
    guiWindowSetSizable(window, false)
    gridlist = guiCreateGridList(9, 27, 479, 194, false, window)
    colLocation = guiGridListAddColumn(gridlist, "Location", 0.33)
    colDistance = guiGridListAddColumn(gridlist, "Distance", 0.33)
    colCash = guiGridListAddColumn(gridlist, "Cash", 0.33)
    for i=1,#Locations do --I know this is saying for each line in the table
        local x,y,z,text = Locations[i][1],Locations[i][2],Locations[i][3],Locations[i][4]--x = key 1, y = key 2, z = key 3
        local px,py,pz = getElementPosition(localPlayer)
        local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z)
        cash = math.floor(distance*3)
        local row = guiGridListAddRow ( gridlist,text, math.floor(distance), cash )
    end
    btn_acc = guiCreateButton(72, 231, 140, 25, "Accept", false, window)
    guiSetFont(btn_acc, "sa-header")
    btn_exit = guiCreateButton(284, 231, 140, 25, "Exit", false, window)
    guiSetFont(btn_exit, "sa-header")    
    showCursor(true)
    
    --Disable Collisions
    local v = getPedOccupiedVehicle(localPlayer) -- Get her's Vehicle ID
    for index,vehicle in ipairs(getElementsByType("vehicle")) do --LOOP through all Vehicles
        setElementCollidableWith(vehicle, v, false) -- Set the Collison off with the Other vehicles.
    end
    
    local playerVehicle = getPedOccupiedVehicle ( localPlayer )
    if (playerVehicle) then
        setElementFrozen ( playerVehicle, true )
    end
    
    addEventHandler("onClientGUIClick", btn_acc, Accept)
    addEventHandler("onClientGUIClick", btn_exit, Exit)
    addEventHandler("onClientDoubleClick", root, DoubleClick)
end

addEvent("TruckerStart", true)
addEventHandler("TruckerStart", getRootElement(), showGUI)


function DoubleClick (button)
    if button == "left" then 
        Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (Location[4])
        local x, y, z
        for i=1,#Locations do
            if Name == Locations[i][4] then
                x, y, z = Locations[i][1], Locations[i][2], Locations[i][3]
            end
        end
        if isElement (marker) then
            removeEventHandler("onClientMarkerHit", marker, reward)
            destroyElement(marker)
            destroyElement(blip)
        end
        marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 )
        blip = createBlipAttachedTo(marker, 51 ) --Type, Size, R, G, B
        cash = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),3)
        --outputChatBox(""..cash,255,0,0)
        addEventHandler("onClientMarkerHit", marker, reward)
        
        removeEventHandler("onClientDoubleClick", root, DoubleClick)
        removeEventHandler("onClientGUIClick", btn_acc, DoubleClick)
        destroyElement(window)
        showCursor(false)
        triggerServerEvent("createTrailer", localPlayer)
        
        if #shipmentMarkerVault ~= 0 then
            for index = 1, #shipmentMarkerVault do
                destroyElement(shipmentMarkerVault[index])
                shipmentMarkerVault[index] = nil
            end
        end
        
        if #shipmentBlipVault ~= 0 then
            for index = 1, #shipmentBlipVault do
                destroyElement(shipmentBlipVault[index])
                shipmentBlipVault[index] = nil
            end
        end
        
        local playerVehicle = getPedOccupiedVehicle ( localPlayer )
        if (playerVehicle) then
            setElementFrozen ( playerVehicle, false )
        end
    end
end


function Accept(button, state)
    if source == btn_acc and button == "left" and state == "up" then 
        Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (Location[4])
        local x, y, z
        for i=1,#Locations do
            if Name == Locations[i][4] then
                x, y, z = Locations[i][1], Locations[i][2], Locations[i][3]
            end
        end
        if isElement (marker) then
            removeEventHandler("onClientMarkerHit", marker, reward)
            destroyElement(marker)
            destroyElement(blip)
        end
        marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 )
        blip = createBlipAttachedTo(marker, 51 ) --Type, Size, R, G, B
        cash = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),3)
        addEventHandler("onClientMarkerHit", marker, reward)
        
        removeEventHandler("onClientDoubleClick", root, DoubleClick)
        removeEventHandler("onClientGUIClick", btn_acc, DoubleClick)
        destroyElement(window)
        showCursor(false)
        triggerServerEvent("createTrailer", localPlayer)
        
        --destroy markers and clear the table
        if #shipmentMarkerVault ~= 0 then
            for index = 1, #shipmentMarkerVault do
                destroyElement(shipmentMarkerVault[index])
                shipmentMarkerVault[index] = nil
            end
        end
        
        if #shipmentBlipVault ~= 0 then
            for index = 1, #shipmentBlipVault do
                destroyElement(shipmentBlipVault[index])
                shipmentBlipVault[index] = nil
            end
        end
        
        local playerVehicle = getPedOccupiedVehicle ( localPlayer )
        if (playerVehicle) then
            -- set the new freeze status
            setElementFrozen ( playerVehicle, false )
        end
    end
end

function Exit(button, state)
    if source == btn_exit and button == "left" and state == "up" then 
        removeEventHandler("onClientDoubleClick", root, DoubleClick)
        removeEventHandler("onClientGUIClick", btn_acc, DoubleClick)
        removeEventHandler("onClientGUIClick", btn_exit, Exit)
        destroyElement(window)
        showCursor(false)
        
        triggerEvent("shipmentMarker", localPlayer)
        
        local playerVehicle = getPedOccupiedVehicle ( localPlayer )
        if (playerVehicle) then
            setElementFrozen ( playerVehicle, false )
        end
    end
end

function reward()
    for i=1,#Locations do
        if Name == Locations[i][4] then
            destroyElement(marker)
            destroyElement(blip)
            triggerServerEvent("truckerReward", localPlayer, cash)
            triggerEvent ("TruckerStart", localPlayer)
        end
    end
end

function trailerSpawn(hitElement, matchingDimension)
    if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then 
    local checkTeam = getTeamFromName("Trucker") 
        if ( checkTeam ) then 
        local playerTeam = getPlayerTeam(hitElement) 
            if ( playerTeam == checkTeam ) then 
                if not isPedInVehicle ( hitElement ) then 
                    outputChatBox("You must be in a truck, get a new one from the job spawn! (yellow blip on map)", 255,0,0 )
                    return
                else
                    Vehicle = getPedOccupiedVehicle(hitElement)
                    if  getElementModel ( Vehicle ) == 403 or getElementModel ( Vehicle ) == 514 or getElementModel ( Vehicle ) == 515 then 
                    triggerEvent ("TruckerStart", hitElement)
                    end
                end
            end    
        end
    end
end

function destroyMarker()
    if isElement (marker) then
        removeEventHandler("onClientMarkerHit", marker, reward)
        destroyElement(marker)
        destroyElement(blip)
    end
end

addEvent("destroyMarker",true)
addEventHandler("destroyMarker",getRootElement(),destroyMarker)

function makeGoodsMarker()
    if #shipmentMarkerVault ~= 0 then
        for index = 1, #shipmentMarkerVault do
            destroyElement(shipmentMarkerVault[index])
            shipmentMarkerVault[index] = nil
        end
    end
    if #shipmentBlipVault ~= 0 then
        for index = 1, #shipmentBlipVault do
            destroyElement(shipmentBlipVault[index])
            shipmentBlipVault[index] = nil
        end
    end
    for i=1,#cargoMarkers do 
        local x,y,z = cargoMarkers[i][1],cargoMarkers[i][2],cargoMarkers[i][3]--x = key 1, y = key 2, z = key 3        
        GoodsMarker = createMarker( x,y,z-1,"cylinder", 5, 0, 200, 55, 255 )
        TruckerJobBlip = createBlipAttachedTo ( GoodsMarker, 36 )
        shipmentMarkerVault[i] = GoodsMarker
        shipmentBlipVault[i] = TruckerJobBlip
        addEventHandler("onClientMarkerHit", GoodsMarker, trailerSpawn)
    end
end
addEvent("shipmentMarker", true)
addEventHandler("shipmentMarker", getRootElement(), makeGoodsMarker)

function destroyAllMarkersAndBlips()
    if #shipmentMarkerVault ~= 0 then
        for index = 1, #shipmentMarkerVault do
            destroyElement(shipmentMarkerVault[index])
            shipmentMarkerVault[index] = nil
        end
    end
    
    if #shipmentBlipVault ~= 0 then
        for index = 1, #shipmentBlipVault do
            destroyElement(shipmentBlipVault[index])
            shipmentBlipVault[index] = nil
        end
    end
    
    if isElement (marker) then
        removeEventHandler("onClientMarkerHit", marker, reward)
        destroyElement(marker)
        destroyElement(blip)
    end
end
addEvent("destroyTruckerStuff", true)
addEventHandler("destroyTruckerStuff", getRootElement(), destroyAllMarkersAndBlips)



server
local TruckerTeam = createTeam("Trucker", 20, 100, 150)
    
    removeWorldModel (985 , 7.3802581, 2497.2419, 2774.2747, 10.7167)
    removeWorldModel (986, 7.4280729, 2497.2119, 2768.4243, 11.38819)
    RGate = createObject (986, 2497.3999, 2769.0991, 11.53, 0, 0, 90)
    LGate = createObject (985, 2497.3999, 2777.0701, 11.53, 0, 0, 90)
    ColGate = createColCuboid (2487.15, 2765.28, 10, 20, 15.75, 5)

function KACC_Open ( thePlayer, matchingDimension )
    if getElementType ( thePlayer ) == "player" then --if the element that entered was player
        moveObject(RGate, 1000, 2497.3999, 2769.0991-5, 11.53, 0, 0, 0)
        moveObject(LGate, 1000, 2497.3999, 2777.0701+5, 11.53, 0, 0, 0)
    end
end

addEventHandler ( "onColShapeHit", ColGate, KACC_Open )    

function KACC_Close ( thePlayer, matchingDimension )
    if getElementType ( thePlayer ) == "player" then --if the element that entered was player
        if not isElementWithinColShape ( thePlayer, ColGate ) then
            moveObject (RGate, 1000, 2497.3999, 2769.0991, 11.53, 0, 0, 0)
            moveObject (LGate, 1000, 2497.3999, 2777.0701, 11.53, 0, 0, 0)    
        end
    end
end

addEventHandler ( "onColShapeLeave", ColGate, KACC_Close )

--[[Remove gates in LV
    removeWorldModel (985 , 7.3802581, 2497.2419, 2774.2747, 10.7167)
    removeWorldModel (986, 7.4280729, 2497.2119, 2768.4243, 11.38819)
    --createObject (986, 2493.3999, 2766.7, 11.53, 0, 0, 160)
    --createObject (985, 2493.3999, 2779.6, 11.53, 0, 0, 20)
    RGate = createObject (986, 2497.3999, 2769.0991, 11.53, 0, 0, 90)
    LGate = createObject (985, 2497.3999, 2777.0701, 11.53, 0, 0, 90)
    ColGate = createColCuboid (2487.15, 2765.28, 10, 20, 15.75, 5)

isGateOpen = false
local OpenTimer
local CloseTimer

function KACC_Open ( thePlayer, matchingDimension )
    if getElementType ( thePlayer ) == "player" then --if the element that entered was player
        if isTimer(OpenTimer) then
            outputChatBox("Znaleziono licznik czasu",thePlayer)
        end
        if isGateOpen == false then
            x,y,z = getElementRotation(LGate)
            if not z == 20 then
                return
            end
            moveObject(RGate, 1500, 2493.3999, 2766.7, 11.53, 0, 0, 70)
            moveObject(LGate, 1500, 2493.3999, 2779.6, 11.53, 0, 0, -70)
            OpenTimer = setTimer(function() isGateOpen = true end,2000,1)
        end    
    end
end

addEventHandler ( "onColShapeHit", ColGate, KACC_Open )    

function KACC_Close ( thePlayer, matchingDimension )
    if getElementType ( thePlayer ) == "player" then --if the element that entered was player
        if isGateOpen == true then
            x,y,z = getElementRotation(LGate)
            if not z == 90 then
                return
            end
            moveObject (RGate, 1500, 2497.3999, 2769.0991, 11.53, 0, 0, -70)
            moveObject (LGate, 1500, 2497.3999, 2777.0701, 11.53, 0, 0, 70)
            CloseTimer = setTimer(function() isGateOpen = false end,2000,1)
        end    
    end
end

addEventHandler ( "onColShapeLeave", ColGate, KACC_Close )]]


TruckerMarker = {--marker [x,y,z]   truck spawn point: [x,y,z,rotationx,rotationy,rotationz], [location]
{2179.841796875, -2263.6940917969, 13.8, 2167.4401855469, -2273.9362792969, 14 ,-0, 0, 220, "Ocean Docks"},
{-1737.9622802734, 20.285757064819, 2.7, -1710, 10, 4, 0, 0, 315, "Easter Basin"},
{1643, 2354, 10, 1634, 2365, 11, -0, 0, 90, "Redsands West"}
}--Above table is for the job markers, player walks into one, they become trucker and a truck is spawned, read above comment for info on spawning trucks.

Handler = false --DO NOT CHANGE, WILL NOT WORK IF IT'S NOT SET TO FALSE
timer = true --If your server has a script to automatically destroy vehicles when they explode you should set this to true
local isTrailerDetached = false --DO NOT CHANGE, WILL NOT WORK IF IT'S NOT SET TO FALSE
local markerStore = {} --Stores markers

function TruckerStart ( hitElement, matchingDimension )
    if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then
        if not (isGuestAccount (getPlayerAccount (hitElement))) then --First we want to check if player has made any shipments, if so, set there shipment data!
        local account = getPlayerAccount (hitElement)
            if (account) then
            local PlayerShipments = getAccountData( account, "Trucker.pres" )
                if (PlayerShipments) then
                    setElementData (hitElement, "Trucker.pres", PlayerShipments)
                else
                    setElementData (hitElement, "Trucker.pres", 0)
                end
                local marker_data = markerStore[source] --We get the marker data from an empty table, you will see why we do this in below function
                if marker_data then
                    --outputDebugString("Marker data found: "..tostring(marker_data))
                    triggerClientEvent ( hitElement, "spawnTruck", hitElement, marker_data)
                end
            end
        end
    end
end

function spawnNo(hitElement) --If player choses no in client side GUI, then they won't get a truck
    if isElement(hitElement) and getElementType(hitElement) == "player" then
        if ( TruckerTeam ) then --Then we want to check if the trucker team exists
            if isPedOnGround ( hitElement ) then --If so, check if player is on foot
                local playerTeam = getPlayerTeam ( hitElement ) --Get there team         
                if not ( playerTeam == TruckerTeam) then --If they are not on the trucker team
                    setPlayerTeam(hitElement, TruckerTeam) --Set there team
                end
                    triggerClientEvent ( hitElement, "destroyIron", hitElement) --Oherwise, we make the markers for them to get there goods    
                    triggerClientEvent ( hitElement, "shipmentMarker", hitElement) --Oherwise, we make the markers for them to get there goods    
            else 
                outputChatBox("Musisz isc pieszo!", hitElement, 255, 0, 0)
            end
        end 
    end
end

addEvent("spawnTruckNo", true)
addEventHandler("spawnTruckNo", getRootElement(), spawnNo)

addEvent("spawnTruckYes", true)
addEventHandler("spawnTruckYes", root, 
function (hitElement, marker_data)--If player choses yes in client side GUI, then they will get a truck
    if isElement(hitElement) and getElementType(hitElement) == "player" then
        if ( TruckerTeam ) then --Then we want to check if the trucker team exists
            if isPedOnGround ( hitElement ) then --If so, check if player is on foot
                local playerTeam = getPlayerTeam ( hitElement ) --Get there team         
                if not ( playerTeam == TruckerTeam) then --If they are not on the trucker team
                    setPlayerTeam(hitElement, TruckerTeam) --Set there team
                end
                        triggerClientEvent ( hitElement, "destroyIron", hitElement)
                        triggerClientEvent ( hitElement, "shipmentMarker", hitElement)
                        local x, y, z, rx, ry, rz, name
                        if marker_data then
                            x,y,z,rx,ry,rz,name = marker_data[4],marker_data[5],marker_data[6],marker_data[7],marker_data[8],marker_data[9],marker_data[10]
                        local spawnedTruck = getElementData( hitElement, "Trucker.truck" ) --Now we want to check if they have spawned a truck
                        if ( spawnedTruck ~= false ) then --(~= is not equal)
                            if isElement(spawnedTruck) then
                                destroyElement(spawnedTruck) --If they have, destroy the truck
                            end
                            setElementData(hitElement, "Trucker.truck", false) --And set there data to false
                        end
                        local spawnedTrailer = getElementData( hitElement, "Trucker.trailer" )    
                        if ( spawnedTrailer ~= false ) then 
                            if isElement(spawnedTrailer) then
                                destroyElement(spawnedTrailer)
                            end
                            setElementData(source, "Trucker.trailer", false) 
                        end
                            local Truck = createVehicle (515, x, y, z+1, rx, ry, rz)  
                            setElementData(hitElement, "Trucker.truck", Truck)
                            warpPedIntoVehicle (hitElement, Truck)
                            --[[This can give faster trucks, but not recommended.
                            setVehicleHandling( Truck, "engineAcceleration", "20" )
                            setVehicleHandling( Truck, "maxVelocity", "150" )
                            setVehicleHandling( Truck, "steeringLock", "40" )
                            setVehicleHandling( Truck, "brakeDeceleration", "10000" )
                            setVehicleHandling( Truck, "engineType", "petrol" )
                            setVehicleHandling( Truck, "driveType", "awd" )    
                            Truck = false]]
                        end  
            else 
                outputChatBox("Musisz isc pieszo!", hitElement, 255, 0, 0)
            end
        end 
    end
end)


function createMarkers()
    for i=1,#TruckerMarker do 
        local x,y,z = TruckerMarker[i][1],TruckerMarker[i][2],TruckerMarker[i][3]--x = key 1, y = key 2, z = key 3        
        local marker = createMarker( x,y,z,"cylinder", 1, 0, 200, 55, 255 )
        markerStore[marker] = TruckerMarker[i]
        TruckerJobBlip = createBlipAttachedTo ( marker, 42, 2, 0, 0, 0, 0, 0, 500 )
        addEventHandler("onMarkerHit", marker, TruckerStart)
    end
end

createMarkers()


function spawnTrailer()
    if getElementType(source) == "player" then 
        local spawnedTruck = getPedOccupiedVehicle( source )
        local spawnedTrailer = getElementData( source, "Trucker.trailer" )
        
        trx,try,trz = getElementRotation(spawnedTruck)
        
        if ( spawnedTrailer ~= false ) then 
            if isElement(spawnedTrailer) then
                destroyElement(spawnedTrailer)
            end
            setElementData(source, "Trucker.trailer", false) 
        end
        
        Trailer = createVehicle (584, 2759.53, -2393.11, 150000, 0, 0, trz) --435, 450, 584, 591 <<These are all acceptable trailer ID's for trucks
        setElementData(source, "Trucker.trailer", Trailer) 
        local spawnedTrailer = getElementData( source, "Trucker.trailer" )
        setTimer(function()attachTrailerToVehicle ( spawnedTruck, spawnedTrailer )end, 100, 1)
        
        if isTrailerDetached == true then
            removeEventHandler("onTrailerAttach", getRootElement(), TrailerAttach)
            isTrailerDetached = false
        end
        
        if Handler == false then
            setTimer(function()addEventHandler("onTrailerDetach", getRootElement(), TrailerDetach)end, 3000, 1)
            Handler = true
        else
            removeEventHandler("onTrailerDetach", root, TrailerDetach)
            setTimer(function()addEventHandler("onTrailerDetach", getRootElement(), TrailerDetach)end, 3000, 1)
        end
        
        setElementData(source, "Trucker.can-be-rewarded", true) 
    end
end
addEvent("createTrailer", true)
addEventHandler("createTrailer", getRootElement(), spawnTrailer)


function giveReward(cash)
    if getElementType(source) == "player" then 
        if not isPedInVehicle ( source ) then 
            outputChatBox("Kolego, gdzie pojazd?", source, 255,0,0 )
            return
        else
            if getElementData(source, "Trucker.can-be-rewarded") == true then
                Vehicle = getPedOccupiedVehicle(source)
                if getElementModel ( Vehicle ) == 403 or getElementModel ( Vehicle ) == 514 or getElementModel ( Vehicle ) == 515 then 
                    local spawnedTrailer = getElementData( source, "Trucker.trailer" )
                    givePlayerMoney(source, cash)
                    removeEventHandler("onTrailerDetach", getRootElement(), TrailerDetach)
                    removeEventHandler("onTrailerAttach", getRootElement(), TrailerAttach)
                    setElementData(source, "Trucker.can-be-rewarded", false)
                    destroyElement(spawnedTrailer) 
                    spawnedTrailer = nil 
                    setElementData(source, "Trucker.trailer", false)
                    setElementData (source, "Trucker.pres",(getElementData (source, "Trucker.pres")or 0 ) + 1)
                end
            else
                outputChatBox("Wyglada na to, ze zapomniales zabrac swoja przyczepe ... Coz! Wracaj po nia.", source, 255,0,0 )
            end
        end
    end    
end
addEvent("truckerReward", true)
addEventHandler("truckerReward", getRootElement(), giveReward)


function TrailerDetach(theTruck)
    thePlayer = getVehicleOccupant ( theTruck, 0 )  
    local spawnedTrailer = getElementData( thePlayer, "Trucker.trailer" )
    if source == spawnedTrailer then 
        setElementData(thePlayer, "Trucker.can-be-rewarded", false)
        removeEventHandler("onTrailerDetach", getRootElement(), TrailerDetach)
        addEventHandler("onTrailerAttach", getRootElement(), TrailerAttach)
        isTrailerDetached = true
        outputChatBox("Musisz zdobyc swoja przyczepe!", thePlayer, 100,100,50 )
        setElementData(thePlayer, "Trucker.detached", true) 
    end
end


function TrailerAttach(theTruck)
    thePlayer = getVehicleOccupant ( theTruck, 0 )  
    local spawnedTrailer = getElementData( thePlayer, "Trucker.trailer" )
    if source == spawnedTrailer then 
        setElementData(thePlayer, "Trucker.can-be-rewarded", true)
        addEventHandler("onTrailerDetach", getRootElement(), TrailerDetach)
        removeEventHandler("onTrailerAttach", getRootElement(), TrailerAttach)
        setElementData(thePlayer, "Trucker.detached", false)
    end
end

local TruckTimer
local TrailerTimer

function ExitVehicle(thePlayer)
    if getPlayerTeam(thePlayer) == (TruckerTeam) then
        local spawnedTruck = getElementData( thePlayer, "Trucker.truck" )
        local theTrailer = getElementData( thePlayer, "Trucker.trailer" ) --Name changed from spawnedTrailer to prevent conflict
        if source == spawnedTruck then
            outputChatBox("Masz 20 sekund na powrot do ciezarowki!", thePlayer)
        end
            TruckTimer = setTimer(function()
                    if ( spawnedTruck ~= false ) and ( isElement(spawnedTruck) ) then --(~= is not equal) 
                        destroyElement(spawnedTruck)
                        setElementData(thePlayer, "Trucker.truck", false)
                    end
                    if (theTrailer) ~= false and isElement(theTrailer) then
                        destroyElement(theTrailer)
                        setElementData(thePlayer, "Trucker.trailer", false)
                    end
                    triggerClientEvent(thePlayer, "destroyMarker", thePlayer)
                    triggerClientEvent(thePlayer, "shipmentMarker", thePlayer)
                end,20000,1)
        if not (spawnedTruck) and (theTrailer) then
            outputChatBox("Masz 20 sekund na powrot do ciezarowki!", thePlayer)
            TrailerTimer = setTimer(function()
                if not isElement(spawnedTruck) and isElement(theTrailer) then
                    destroyElement(theTrailer)
                    triggerClientEvent(thePlayer, "destroyMarker", thePlayer)
                    setElementData(thePlayer, "Trucker.trailer", false)
                    triggerClientEvent(thePlayer, "shipmentMarker", thePlayer)
                end
            end,20000,1)
        end
    end
end

addEventHandler("onVehicleExit",getRootElement(),ExitVehicle)

function EnterVehicle(thePlayer)
    if getPlayerTeam(thePlayer) == (TruckerTeam) then
        local spawnedTruck = getElementData( thePlayer, "Trucker.truck" )
        if source == spawnedTruck then
            if isTimer(TruckTimer) then 
                killTimer(TruckTimer)
            end
        end
        if source == spawnedTruck or getElementModel ( source ) == 403 or getElementModel ( source ) == 514 or getElementModel ( source ) == 515 then
            if isTimer(TrailerTimer) then 
                killTimer(TrailerTimer)
            end
        end
    end
end

addEventHandler("onVehicleEnter",getRootElement(),EnterVehicle)

function SaveShipments(quitType, reason, responsibleElement)
    if not (isGuestAccount (getPlayerAccount (source))) then
        local account = getPlayerAccount (source)
        if (account) then
            local PlayerShipments = getElementData( source, "Trucker.pres" )
            if (PlayerShipments) then
                setAccountData (account, "Trucker.pres", PlayerShipments)
            end
        end
    end
end

addEventHandler("onPlayerQuit", getRootElement(), SaveShipments)


function GetShipments(quitType, reason, responsibleElement)
    if not (isGuestAccount (getPlayerAccount (source))) then
        local account = getPlayerAccount (source)
        if (account) then
            local PlayerShipments = getAccountData( account, "Trucker.pres" )
            if (PlayerShipments) then
            setElementData (source, "Trucker.pres", PlayerShipments)
            end
        end
    end
end

addEventHandler("onPlayerLogin", getRootElement(), GetShipments)


--When vehicles explode the players data will be removed
function explodingTruck()
    if timer == true then
        for _,player in ipairs(getElementsByType("player")) do --LOOP through all Vehicles
            local spawnedTruck = getElementData( player, "Trucker.truck" )
            local theTrailer = getElementData( player, "Trucker.trailer" )
            if source == spawnedTruck then 
                setElementData(player, "Trucker.truck", false)
            end
            if source == theTrailer then
                setElementData(player, "Trucker.trailer", false)
                triggerClientEvent(player, "destroyMarker", player)
                triggerClientEvent(player, "shipmentMarker", player)
            end
        end
    end
end
addEventHandler("onVehicleExplode",getRootElement(),explodingTruck)


function tellShipments(thePlayer)
    PlayerShipments = getElementData( thePlayer, "Trucker.pres" )
    if (PlayerShipments) then
        outputChatBox("Wykonales juz kilka dostaw, gratulacje!", thePlayer, 20, 140, 50)
    end
end

addCommandHandler("shipments", tellShipments)


function bbTrucker(thePlayer)
    triggerClientEvent(thePlayer, "destroyTruckerStuff", thePlayer)
end

addCommandHandler("byetwucker", bbTrucker)


Ostatnio zmieniony przez Wilq 2020-11-03, 14:28, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-11-03, 14:47


VVirmex

Sgrypter luja






Wiek: 21
Na forum: 3506 dni
Posty: 284
Nick w MP: AxyZ

Piwa: 235

Respekt: 110
Respekt: 110


triggerServerEvent("truckerReward", localPlayer, cash)

^
Tu masz linijk? po stronie clienta.


        local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z)
        cash = math.floor(distance*3)

^
Tu masz ustalanie kasy

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-11-03, 16:43


kazet12383







Wiek: 30
Na forum: 2340 dni
Posty: 14
Nick w MP: toja



Respekt: 50

"VVirmex" napisał/a:


triggerServerEvent("truckerReward", localPlayer, cash)

^
Tu masz linijk? po stronie clienta.


        local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z)
        cash = math.floor(distance*3)

^
Tu masz ustalanie kasy


local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z)
cash = math.floor(distance*3)
zmieniam ta 3jke przy distance i caly czas dostaje to samo wynagrodzenie, co mam zmienic zeby powiekszyc zarobki?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-11-03, 17:14


VVirmex

Sgrypter luja






Wiek: 21
Na forum: 3506 dni
Posty: 284
Nick w MP: AxyZ

Piwa: 235

Respekt: 110
Respekt: 110

Przede wszystkim ustalaj d?ugie trasy - pieni?dze nalicza na podstawie d?ugo?ci trasy.

Postaw piwo autorowi tego posta
 

 
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku