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

Wysłany: 2016-02-18, 15:43


Snapig

Amator LUA






Wiek: 28
Na forum: 3793 dni
Posty: 43
Nick w MP: Rother

Piwa: 129

Respekt: 50

Ostrzeżeń: 20%
Witam, mam kolejny problem otwoz chcialbym by wybieralo mi losowo markery. Czyli no dodaje do skryptu markery i chce zeby jeden z nich sie uruchomil a potem drugi i tak ciagle ale nie po kolei :>. Opis: Chodzi o to zeby losowalo mi do jakiego markeru mam dojechac :>>
kod
Client

local districtsBus = {
{
-2405.13671875, -95.52148437534.900238037109},
{-2404.3330078125, -112.38085937534.90013885498},
{-2399.6416015625, -122.270507812534.900146484375},
{-2395.865234375, -141.034179687534.899978637695},
{-2386.4521484375, -118.262695312534.899925231934},
{-2400.99609375, -150.04101562534.900268554688},
{-2386.1005859375, -144.9023437534.900054931641},
{-2387.5693359375, -175.416992187534.89246368408},
{-2403.7236328125, -186.96289062534.892444610596},
{-2408.5576171875, -168.554687534.900157928467},

}

local jobTarget
local jobMarker
local jobVehicle
local maxTarget #districtsBus

function finishJob()
if jobMarker and isElement(jobMarkerthen
destroyElement(jobMarker)
jobMarker nil
end

if jobTarget and isElement(jobTargetthen
destroyElement(jobTarget)
jobTarget nil
jobTarget 0

end

triggerServerEvent("destroyVeh"localPlayer)

end


function busDriver(elmd)
if el ~= localPlayer or not md then return end
if jobTarget maxTarget and getPedOccupiedVehicle(elthen return end
if jobTarget == maxTarget and not getPedOccupiedVehicle(elthen return end

if jobTarget == #districtsBus then
finishJob()
playSoundFrontEnd(5)
outputChatBox("[Informacja] Zako?czy?e?/a? prac? kosiarek!")
else
showMarker()
playSoundFrontEnd(12)
triggerServerEvent("givePlayerMoney"localPlayer15)
end
end

function showMarker()
if jobMarker and isElement(jobMarkerthen
destroyElement(jobMarker)
destroyElement(jobBlip)
jobMarker nil
jobBlip nil
end

jobTarget jobTarget 1
jobMarker createMarker(districtsBus[jobTarget][1], districtsBus[jobTarget][2], districtsBus[jobTarget][3], "cylinder"400255)

if districtsBus[jobTarget+1then
ile districtsBus[jobTarget+1]
setMarkerTarget(jobMarkerile[1], ile[2], ile[3])
end

addEventHandler("onClientMarkerHit"jobMarkerbusDriver)
end

addEvent("STARTJobBus"true)
addEventHandler("STARTJobBus"resourceRoot, function(veh)
outputChatBox("[Informacja] Rozpocz??e?/a? prac? kosiarek!")
jobVehicle veh
jobTarget 0
showMarker()
end)

addEventHandler("onClientResourceStop"resourceRoot, function()
if jobVehicle and getElementData(localPlayer"gracz_praca"then
setElementData(localPlayer"gracz_praca"false)
end
end)

addEventHandler("onClientVehicleExit"resourceRoot, function(plrseat)
if seat == 0 then
if plr == localPlayer then
finishJob()
outputChatBox("[Informacja] Zako?czy?e? prac?")
end
end
end)


Server

local m1 createMarker( -2405.86,-78.18,33.20"cylinder"4.025500)
vehs = {}

local blip createBlip( -2405.86,-78.18,35.2052)

addEvent("givePlayerMoney"true)
addEventHandler("givePlayerMoney"getRootElement(),function(ile)
givePlayerMoney(sourcetonumber(ile))
end)

function removePreviousVehicles(plr)
for i,v in ipairs(getElementsByType("vehicle"resourceRoot)) do
local sby getElementData(v"zrespilGracz")
if sby and sby == plr and getPedOccupiedVehicle(plr) ~= v then
destroyElement(v)
end
end
end

addEventHandler("onMarkerHit"m1, function(elmd)
if getElementData(el"zrespilGracz"then
outputChatBox("[Informacja] Praca w trakcie poprawek"el)
return
end

if not md or getElementType(el) ~= "player" or getPedOccupiedVehicle(elthen return end

local x,y,getElementPosition(el)
local bus createVehicle(572, -2405.22,-82.63,35.20)

setElementData(bus"zrespilGracz"el)
setElementData(bus"pojazd_paliwo"50)
setElementData(bus"pojazd_przebieg"100)

warpPedIntoVehicle(elbus)
removePreviousVehicles(el)
triggerClientEvent(el"STARTJobBus"resourceRootbus)

vehs[el] = bus
end)

addEvent("STOPJobBus"true)
addEventHandler("STOPJobBus"resourceRoot, function()
local pojazd getPedOccupiedVehicle(localPlayer)
if pojazd then
destroyElement(pojazd)
end
end)

addEvent("destroyVeh"true)
addEventHandler("destroyVeh"getRootElement(),
function()
if vehs[sourcethen
if isElement(vehs[source]) then destroyElement(vehs[source]) end
end
end)

Bardzo bym prosil o przyklad kodu. Z gory dzieki. Dla poprawnej odpowiedzi dam :piwko:

Ostatnio zmieniony przez Snapig 2016-02-18, 15:54, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-18, 15:46


Axmell

E-Commerce






Wiek: 24
Na forum: 3810 dni
Posty: 279
Nick w MP: %Axmell

Piwa: 224

Respekt: 50

Snapig, nie pro? o to, aby pisano gdzie go umiescic, tak sie nie nauczysz,
Nie, Nie wiem jak. :P

Podpis
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-18, 15:53


mati2409

Uczę się LUA!






Wiek: 33
Na forum: 3800 dni
Posty: 97
Nick w MP: mati2409

Piwa: 73

Respekt: 50

Sam nie potrafi? lua ,ale my?l? ,?e to b?dzie co? z match.random ,ale nie wiem nie znam si? !

Podpis
Mapping <3
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-18, 16:01


Fanciak

BOT






Wiek: 25
Na forum: 4446 dni
Posty: 728
Nick w MP: Fanciak

Piwa: 1572

Respekt: 500
Respekt: 500

Dok?adnie, tyle, ?e to si? nazywa math.random. Pobierasz numery z tablicy, kt?re ma losowa? i wio.

http://lua-users.org/wiki/MathLibraryTutorial

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-18, 16:55


Snapig

Amator LUA






Wiek: 28
Na forum: 3793 dni
Posty: 43
Nick w MP: Rother

Piwa: 129

Respekt: 50

Ostrzeżeń: 20%
Mozna troche w przjezysty sposob bo tak to nic nie rozumiem :'<

EDIT:
Prosze powiedzcie to przejzysciej xd z tego co tam pisze wnioskuje ze

match.random(10,90) -- On ma od tego do tego losowac ale jak zrobic by losowalo pomiedzy kordami :<


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-18, 17:53


Fanciak

BOT






Wiek: 25
Na forum: 4446 dni
Posty: 728
Nick w MP: Fanciak

Piwa: 1572

Respekt: 500
Respekt: 500

Bardziej co? takiego:


math.random(1#tablica)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-19, 12:46


Snapig

Amator LUA






Wiek: 28
Na forum: 3793 dni
Posty: 43
Nick w MP: Rother

Piwa: 129

Respekt: 50

Ostrzeżeń: 20%
A wiec tak ja zrobilem takie :>


local losuj match.random(2,districtsBus)


Podpis
Jeżeli Ci pomogłem daj Piwko ;piwo;
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-02-19, 12:48


AteX







Wiek: 26
Na forum: 4015 dni
Posty: 927
Nick w MP: #AteX

Piwa: 8360

Respekt: 775,3
Respekt: 775,3Respekt: 775,3

Jak ju? to tak.
local losuj math.random(2,#districtsBus)

Gdy zaczniesz od 2 to pierwszy punkt w tabeli zostanie pomini?ty, ale mo?e tak chcesz nwm.

Podpis
MultiTheftAuto++ dla MTA 1.5.7 już dostępne.
Postaw piwo autorowi tego posta
 

 
Tagi: losowe :: markery
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

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