Wysłany: 2016-02-18, 15:43
Snapig
Amator LUA
Wiek: 28 Na forum: 3793 dni Posty: 43
Nick w MP: Rother
Piwa : 129
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.521484375 , 34.900238037109 },
{- 2404.3330078125 , - 112.380859375 , 34.90013885498 },
{- 2399.6416015625 , - 122.2705078125 , 34.900146484375 },
{- 2395.865234375 , - 141.0341796875 , 34.899978637695 },
{- 2386.4521484375 , - 118.2626953125 , 34.899925231934 },
{- 2400.99609375 , - 150.041015625 , 34.900268554688 },
{- 2386.1005859375 , - 144.90234375 , 34.900054931641 },
{- 2387.5693359375 , - 175.4169921875 , 34.89246368408 },
{- 2403.7236328125 , - 186.962890625 , 34.892444610596 },
{- 2408.5576171875 , - 168.5546875 , 34.900157928467 },
}
local jobTarget
local jobMarker
local jobVehicle
local maxTarget = #districtsBus
function finishJob ()
if jobMarker and isElement ( jobMarker ) then
destroyElement ( jobMarker )
jobMarker = nil
end
if jobTarget and isElement ( jobTarget ) then
destroyElement ( jobTarget )
jobTarget = nil
jobTarget = 0
end
triggerServerEvent ( "destroyVeh" , localPlayer )
end
function busDriver ( el , md )
if el ~= localPlayer or not md then return end
if jobTarget > maxTarget and getPedOccupiedVehicle ( el ) then return end
if jobTarget == maxTarget and not getPedOccupiedVehicle ( el ) then return end
if jobTarget == #districtsBus then
finishJob ()
playSoundFrontEnd ( 5 )
outputChatBox ( "[Informacja] Zako?czy?e?/a? prac? kosiarek!" )
else
showMarker ()
playSoundFrontEnd ( 12 )
triggerServerEvent ( "givePlayerMoney" , localPlayer , 1 , 5 )
end
end
function showMarker ()
if jobMarker and isElement ( jobMarker ) then
destroyElement ( jobMarker )
destroyElement ( jobBlip )
jobMarker = nil
jobBlip = nil
end
jobTarget = jobTarget + 1
jobMarker = createMarker ( districtsBus [ jobTarget ][ 1 ], districtsBus [ jobTarget ][ 2 ], districtsBus [ jobTarget ][ 3 ], "cylinder" , 4 , 0 , 0 , 255 )
if districtsBus [ jobTarget + 1 ] then
ile = districtsBus [ jobTarget + 1 ]
setMarkerTarget ( jobMarker , ile [ 1 ], ile [ 2 ], ile [ 3 ])
end
addEventHandler ( "onClientMarkerHit" , jobMarker , busDriver )
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( plr , seat )
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.0 , 255 , 0 , 0 )
vehs = {}
local blip = createBlip ( - 2405.86 ,- 78.18 , 35.20 , 52 )
addEvent ( "givePlayerMoney" , true )
addEventHandler ( "givePlayerMoney" , getRootElement (),function( ile )
givePlayerMoney ( source , tonumber ( 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( el , md )
if getElementData ( el , "zrespilGracz" ) then
outputChatBox ( "[Informacja] Praca w trakcie poprawek" , el )
return
end
if not md or getElementType ( el ) ~= "player" or getPedOccupiedVehicle ( el ) then return end
local x , y , z = 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 ( el , bus )
removePreviousVehicles ( el )
triggerClientEvent ( el , "STARTJobBus" , resourceRoot , bus )
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 [ source ] then
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
Wysłany: 2016-02-18, 15:46
Axmell
E-Commerce
Wiek: 24 Na forum: 3810 dni Posty: 279
Nick w MP: %Axmell
Piwa : 224
Snapig , nie pro? o to, aby pisano gdzie go umiescic, tak sie nie nauczysz,
Nie, Nie wiem jak.
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
Sam nie potrafi? lua ,ale my?l? ,?e to b?dzie co? z match.random ,ale nie wiem nie znam si? !
Wysłany: 2016-02-18, 16:01
Fanciak
BOT
Wiek: 25 Na forum: 4446 dni Posty: 728
Nick w MP: Fanciak
Piwa : 1572
Wysłany: 2016-02-18, 16:55
Snapig
Amator LUA
Wiek: 28 Na forum: 3793 dni Posty: 43
Nick w MP: Rother
Piwa : 129
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 :<
Wysłany: 2016-02-18, 17:53
Fanciak
BOT
Wiek: 25 Na forum: 4446 dni Posty: 728
Nick w MP: Fanciak
Piwa : 1572
Bardziej co? takiego:
Wysłany: 2016-02-19, 12:46
Snapig
Amator LUA
Wiek: 28 Na forum: 3793 dni Posty: 43
Nick w MP: Rother
Piwa : 129
A wiec tak ja zrobilem takie :>
local losuj = match . random ( 2 , districtsBus )
Podpis
[you]
Jeżeli Ci pomogłem daj Piwko ;piwo;
Wysłany: 2016-02-19, 12:48
AteX
Wiek: 26 Na forum: 4016 dni Posty: 927
Nick w MP: #AteX
Piwa : 8360
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.
Tagi: losowe :: markery
Anonymous
Na forum: 245 dni
Posty: 1
Anonymous Koniecznie zajrzyj na: