Wysłany: 2020-04-16, 19:43
Irvs
Wiek: 30 Na forum: 2680 dni Posty: 48
Piwa : 3
Cze?? wszystkim,
Mam problem z u?yciem onMarkerHit.
Kod wygl?da nast?puj?co:
marker1 = createMarker
function start ()
marker2 = createMarker
end
addEventHandler ( "onMarkerHit" , marker1 , start )
function step ( plr )
if not isElementWithinMarker ( plr , marker2 ) then return end
co ? si ? tutaj dzieje
end
addEventHandler ( "onMarkerHit" , marker2 , step )
I teraz problem jest nast?puj?cy, skrypt po uruchomieniu stwierdza, ?e argument 2 nie ma warto?ci czyli marker2 i faktycznie tak jest, bo uzyskuje j? gdy funkcja start si? wype?ni.
Ale ten marker nie mo?e si? utworzy?(nie chce tego) nim funkcja start si? nie wype?ni
Z tego te? powodu w momencie wype?nienia funkcji start i pr?bie wej?cia w marker2 nic si? nie dzieje (powinien uruchomi? funkcje step)
Dodam tylko, ?e funkcja 2 tworzy te? marker u?ywany przez funkcje 3 a trzecia tworzy dla czwartej.
Jak to rozwi?za??
Wysłany: 2020-04-16, 20:36
kamison
Przyszły programista .lua
Wiek: 25 Na forum: 3302 dni Posty: 391
Nick w MP: kamison
Piwa : 594
Tak jest!
Zobacz na wiki co daje funkcja onMarkerHit, ja widz?, ?e source to marker w kt?ry wejdzie gracz, a wi?c!
marker1 = createMarker
function start ()
if source == marker1 then -- albo zamiast tego i enda na ko ? cu ifa u ? yj po prostu if source ~= marker1 then return end
marker2 = createMarker
end
end
addEventHandler ( "onMarkerHit" , root , start ) -- mo ? liwe , ? e pod resourceRoot te ? zadzia ? a
function step ( plr )
if source == marker2 then -- albo zamiast tego i enda na ko ? cu ifa u ? yj po prostu if source ~= marker2 then return end
if not isElementWithinMarker ( plr , marker2 ) then return end
co ? si ? tutaj dzieje
end
end
addEventHandler ( "onMarkerHit" , root , step )-- czytaj up kom w addEventHandler
Je?li zadzia?a nie obra?? si? na piwo
Więcej szczegółów
Wystawiono 1 piw(a):Irvs
Wysłany: 2020-04-16, 20:41
Wilq
Wiek: 24 Na forum: 4428 dni Posty: 3410
Piwa : 739
Po co podpina? event bo wszystkie markery, skoro mo?na pod konkretny?
Po prostu w chwili startu pr?bujesz przypisa? event do jeszcze nie istniej?cego markeru.
Dopiero po wej?ciu w marker1, stworzy si? marker2.
Rozwi?zanie: zmie? kolejno?? tworzenia marker?w
albo dodaj event onMarkerHit do marker2 dopiero w funkcji podpi?tej do eventu marker1.
marker1 = createMarker
function step ( plr )
-- co ? si ? tutaj dzieje
end
function start ()
marker2 = createMarker
addEventHandler ( "onMarkerHit" , marker2 , step )
end
addEventHandler ( "onMarkerHit" , marker1 , start )
Sprawdzanie funkcji isElementWithinMarker w evencie onMarkerHit jest zb?dne, bo wiadomo ?e zwr?ci true, no chyba wtedy event by si? nie wykona?.
Mam nadziej?, ?e funkcj? createMarker u?ywasz poprawnie, bo brakuje tutaj praktycznie wszystkich argument?w, go?a funkcja.
Wysłany: 2020-04-16, 22:36
Irvs
Wiek: 30 Na forum: 2680 dni Posty: 48
Piwa : 3
"kamison" napisał/a :
Je?li zadzia?a nie obra?? si? na piwo
Piwo polecia?o, dzia?a po cz??ci, lecz wykonuje wszystkie funkcje po kolei niewa?ne czy wejd? w kolejny marker czy nie.
Ciekawe jest to, ?e wykonuje w funkcji podcar to
setVehicleLocked ( cvech , false )
destroyElement ( mcar )
destroyElement ( blip )
Zanim wejd? do markera, kt?ry powinien t? funkcje aktywowa?, wystarczy, ?e b?d? ok 50m od niego i si? wykona, je?li b?d? daleko to nie... Ju? sam nie rozumiem, a debug nie pokazuje nic.
Poni?ej ca?y kod wraz z tworzeniem marker?w
start = createMarker (- 1686.53 , - 93.69 , 3.58 - 0.90 , "cylinder" , 1 , 12 , 23 , 32 )
stanm = createMarker (- 1697.63 , - 82.24 , 3.57 - 0.90 , "cylinder" , 1 , 12 , 23 , 32 )
pojazdystan = 0
hajs = 5000
local spawncar = {
{ - 2205.80 , 61.14 , 35.32 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2462.56 , - 98.95 , 25.90 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2146.58 , 1218.88 , 47.27 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2176.35 , 1223.10 , 33.93 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1702.36 , 10.94 , 3.55 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2221.79 , - 137.13 , 35.32 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2218.54 , 607.81 , 35.17 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2738.88 , 126.45 , 4.54 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2589.03 , 309.82 , 4.85 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2440.62 , 1037.22 , 50.40 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2324.78 , 989.00 , 50.70 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2188.56 , 969.31 , 80.00 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2045.72 , 1010.57 , 54.67 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1668.95 , 1019.10 , 7.92 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2071.44 , 971.34 , 62.88 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2524.45 , 316.24 , 27.77 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2563.35 , 851.87 , 55.88 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1916.81 , 304.05 , 41.05 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1839.12 , - 13.30 , 15.12 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1820.01 , - 152.13 , 9.40 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2059.41 , 89.44 , 28.39 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 };
}
function startpr ( thePlayer )
--if source == start then
-- if not isElementWithinMarker ( thePlayer , start ) then return end
matchs = math . random ( 1 , #spawncar)
mcar = createMarker ( spawncar [ matchs ][ 1 ], spawncar [ matchs ][ 2 ], spawncar [ matchs ][ 3 ]- 0.90 , "cylinder" , 6 , 255 , 255 , 255 , 10 )
blip = createBlipAttachedTo ( mcar , 41 )
cvech = createVehicle ( spawncar [ matchs ][ 7 ], spawncar [ matchs ][ 1 ], spawncar [ matchs ][ 2 ], spawncar [ matchs ][ 3 ])
setVehicleLocked ( cvech , true )
outputChatBox ( "*Informacje*" , thePlayer , 255 , 255 , 255 )
outputChatBox ( "Klasa: " .. spawncar [ matchs ][ 4 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "Marka: " .. spawncar [ matchs ][ 5 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "W?a?ciel: " .. spawncar [ matchs ][ 6 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "=>Na GPS zosta? oznaczony pojazd" , thePlayer , 255 , 30 , 30 )
-- end
end
addCommandHandler ( "namierz" , startpr )
function podcar ( thePlayer )
if source == mcar then
outputChatBox ( "Pr?bujesz z?ama? zabezpieczenie..." , thePlayer , 255 , 255 , 255 )
-- setTimer ( function()
odjmakrer = createMarker (- 1693.93 , - 90.17 , 3.56 - 0.90 , "cylinder" , 4 , 255 , 255 , 255 , 50 )
odjblip = createBlip (- 1693.93 , - 90.17 , 3.56 , 41 )
outputChatBox ( "Dobra pojazd jest tw?j, zabierz go do kryj?wki!" , thePlayer , 255 , 255 , 255 )
setVehicleLocked ( cvech , false )
destroyElement ( mcar )
destroyElement ( blip )
-- end , 5000 , 1 )
end
end
addEventHandler ( "onMarkerHit" , root , podcar )
function magazyn ( thePlayer )
if source == odjmakrer then
destroyElement ( odjmakrer )
destroyElement ( odjblip )
destroyElement ( cvech )
pojazdystan = pojazdystan + 1
outputChatBox ( "Pojazd schowany! Ilo?? pojazd?w w magazynie to: " .. pojazdystan , thePlayer , 255 , 255 , 255 )
end
end
addEventHandler ( "onMarkerHit" , root , magazyn )
Wysłany: 2020-04-17, 15:25
kamison
Przyszły programista .lua
Wiek: 25 Na forum: 3302 dni Posty: 391
Nick w MP: kamison
Piwa : 594
Sprawdzi?em to w tym przyk?adzie i dzia?a
marker1 = createMarker (- 301.6572265625 , 1313.037109375 , 54.010417938232 , "cylinder" , 1 )
function start ()
if source == marker1 and not isElement ( marker2 ) then -- albo zamiast tego i enda na ko ? cu ifa u ? yj po prostu if source ~= marker1 then return end
marker2 = createMarker (- 297.7412109375 , 1314.8525390625 , 54.10551071167 , "cylinder" , 1 )
outputChatBox ( "zrob marker 2" )
end
if source == marker1 then outputChatBox ( "Marker 1" ) end
end
addEventHandler ( "onMarkerHit" , root , start ) -- mo ? liwe , ? e pod resourceRoot te ? zadzia ? a
function step ( plr )
if source == marker2 then -- albo zamiast tego i enda na ko ? cu ifa u ? yj po prostu if source ~= marker2 then return end
outputChatBox ( "marker 2" )
end
end
addEventHandler ( "onMarkerHit" , root , step )-- czytaj up kom w addEventHandler
Więcej szczegółów
Wystawiono 1 piw(a):Irvs
Wysłany: 2020-04-17, 16:28
Irvs
Wiek: 30 Na forum: 2680 dni Posty: 48
Piwa : 3
"kamison" napisał/a :Sprawdzi?em to w tym przyk?adzie i dzia?a
Tylko nie dzia?a poprawnie w kodzie kt?ry przes?a?em powy?ej.
Funkcja podcar uruchamia si? zanim wejd? do markera mcar
Wystarczy, ?e b?d? w odleg?o?ci 50m od niego a funkcja si? uruchomi zanim zd??e nawet do niego wej??.
(outputchatBox si? nie poka?e, ale reszta si? wykona)
Poni?ej film jak to dzia?a, a raczej nie dzia?a.
https://youtu.be/0-Fwr5EZdjo
Jak wida? marker znika jak i blip nim do niego zd??e wej??, wi?c funkcja si? wykonuje... A powinna w momencie wej?cia do markera
Wysłany: 2020-04-17, 16:54
kamison
Przyszły programista .lua
Wiek: 25 Na forum: 3302 dni Posty: 391
Nick w MP: kamison
Piwa : 594
A zobacz bez latania
[ Dodano : 2020-04-17, 16:57 ]
A i mo?esz podpi?? pod resourceRoot b?dzie bardziej optymalny skrypt
Ostatnio zmieniony przez kamison 2020-04-17, 16:58, w całości zmieniany 1 raz
Więcej szczegółów
Wystawiono 1 piw(a):Irvs
Wysłany: 2020-04-17, 16:57
Irvs
Wiek: 30 Na forum: 2680 dni Posty: 48
Piwa : 3
To samo, w momencie gdy doje?dzam na oko?o 50-100m od wyznaczonego punktu funkcja si? uruchamia, jakie? czary...
Edit. Po zmianie na resourceRoot dalej to samo.
Wysłany: 2020-04-17, 17:19
kamison
Przyszły programista .lua
Wiek: 25 Na forum: 3302 dni Posty: 391
Nick w MP: kamison
Piwa : 594
Dobra, wilq poda? fajne wykorzystanie. Marker znika? bo bez wzgl?du na to jaki element uderza? w marker powodowa? jego zadzia?anie, dlatego mog?y znika?.
start = createMarker (- 2139.5478515625 , 918.3427734375 , 79.8515625 - 0.90 , "cylinder" , 1 , 12 , 23 , 32 )
stanm = createMarker (- 297.7412109375 , 1314.8525390625 , 54.10551071167 , "cylinder" , 1 , 12 , 23 , 32 )
pojazdystan = 0
hajs = 5000
local spawncar = {
{ - 2205.80 , 61.14 , 35.32 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2462.56 , - 98.95 , 25.90 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2146.58 , 1218.88 , 47.27 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2176.35 , 1223.10 , 33.93 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1702.36 , 10.94 , 3.55 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2221.79 , - 137.13 , 35.32 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2218.54 , 607.81 , 35.17 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2738.88 , 126.45 , 4.54 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2589.03 , 309.82 , 4.85 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2440.62 , 1037.22 , 50.40 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2324.78 , 989.00 , 50.70 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2188.56 , 969.31 , 80.00 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2045.72 , 1010.57 , 54.67 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1668.95 , 1019.10 , 7.92 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2071.44 , 971.34 , 62.88 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2524.45 , 316.24 , 27.77 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2563.35 , 851.87 , 55.88 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1916.81 , 304.05 , 41.05 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1839.12 , - 13.30 , 15.12 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 1820.01 , - 152.13 , 9.40 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 },
{ - 2059.41 , 89.44 , 28.39 , "wysoka" , "Banshee" , "Daniel Cortez" , 429 };
}
function startpr ( thePlayer )
--if source == start then
-- if not isElementWithinMarker ( thePlayer , start ) then return end
matchs = math . random ( 1 , #spawncar)
mcar = createMarker ( spawncar [ matchs ][ 1 ], spawncar [ matchs ][ 2 ], spawncar [ matchs ][ 3 ]- 0.90 , "cylinder" , 6 , 255 , 255 , 255 , 10 )
blip = createBlipAttachedTo ( mcar , 41 )
cvech = createVehicle ( spawncar [ matchs ][ 7 ], spawncar [ matchs ][ 1 ], spawncar [ matchs ][ 2 ], spawncar [ matchs ][ 3 ])
setVehicleLocked ( cvech , true )
outputChatBox ( "*Informacje*" , thePlayer , 255 , 255 , 255 )
outputChatBox ( "Klasa: " .. spawncar [ matchs ][ 4 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "Marka: " .. spawncar [ matchs ][ 5 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "W?a?ciel: " .. spawncar [ matchs ][ 6 ], thePlayer , 255 , 255 , 255 )
outputChatBox ( "=>Na GPS zosta? oznaczony pojazd" , thePlayer , 255 , 30 , 30 )
addEventHandler ( "onMarkerHit" , mcar , podcar )
-- end
end
addCommandHandler ( "namierz" , startpr )
function podcar ( thePlayer )
if getElementType ( thePlayer ) ~= "player" then return end
if source == mcar then
outputChatBox ( "Pr?bujesz z?ama? zabezpieczenie..." , thePlayer , 255 , 255 , 255 )
-- setTimer ( function()
odjmakrer = createMarker (- 1693.93 , - 90.17 , 3.56 - 0.90 , "cylinder" , 6 , 255 , 255 , 255 , 50 )
odjblip = createBlip (- 1693.93 , - 90.17 , 3.56 , 41 )
outputChatBox ( "Dobra pojazd jest tw?j, zabierz go do kryj?wki!" , thePlayer , 255 , 255 , 255 )
setVehicleLocked ( cvech , false )
destroyElement ( mcar )
destroyElement ( blip )
-- end , 5000 , 1 )
addEventHandler ( "onMarkerHit" , odjmakrer , magazyn )
end
end
function magazyn ( thePlayer )
if getElementType ( thePlayer ) ~= "player" then return end
if source == odjmakrer then
destroyElement ( odjmakrer )
destroyElement ( odjblip )
destroyElement ( cvech )
pojazdystan = pojazdystan + 1
outputChatBox ( "Pojazd schowany! Ilo?? pojazd?w w magazynie to: " .. pojazdystan , thePlayer , 255 , 255 , 255 )
end
end
[ Dodano : 2020-04-17, 17:19 ]
Kordy od startu zmieni?em(te dwa markery)
[ Dodano : 2020-04-17, 17:19 ]
I szeroko?ci marker?w przy aucie
[ Dodano : 2020-04-17, 17:19 ]
Wi?c zmie? jak chcesz
[ Dodano : 2020-04-17, 17:21 ]
Tylko we? pod uwag?, ?e je?li kto? to rozpocznie to ka?demu si? pojawi (przez to, ?e jest po stronie serwera) i nie definiuj w onMarkerHit pierwszego elementu jako thePlayer, lepiej jako element(bo tak wynika ze sk?adni) nie b?dzie p??niej ci??ko zweryfikowa? co trzeba zrobi?.
[ Dodano : 2020-04-17, 17:22 ]
Mam nadziej?, ?e b?dzie dzia?a? i b?dziesz zadowolony!
Więcej szczegółów
Wystawiono 1 piw(a):Irvs
Wysłany: 2020-04-17, 18:58
Irvs
Wiek: 30 Na forum: 2680 dni Posty: 48
Piwa : 3
Tagi: onmarkerhit
Anonymous
Na forum: 245 dni
Posty: 1
Anonymous Koniecznie zajrzyj na: