WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9] local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) local marker = createMarker ( x + 1, y, z - 1, "cylinder", 1, 255, 51, 255, 50 ) addEventHandler ( "onPlayerMarkerHit", marker, function ( hitMarker ) outputChatBox ( "test" ) if ( hitMarker == marker ) then if ( isElement ( source ) and getElementType ( source ) == "player" ) then outputChatBox ( "test1" ) podejmijPrace ( source, skin ) end end end ) end end ) Well, when I hit the marker nothing happens. No errors, no warnings... Even before "if" things i put output in chat "test" and it doesn't work. What is the problem? Link to comment
WhoAmI Posted March 28, 2015 Author Share Posted March 28, 2015 It's strange tho. I changed code to addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9] local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) local marker = createMarker ( x + 1, y, z - 1, "cylinder", 1, 255, 51, 255, 50 ) setElementInterior ( marker, int ) setElementDimension ( marker, dim ) setElementData ( marker, "modelka", skin ) end end ) addEventHandler ( "onPlayerMarkerHit", root, function ( hitMarker, matchingDimension ) outputChatBox ( "test" ) local skin = getElementData ( hitMarker, "modelka" ) if ( tonumber ( skin ) and matchingDimension ) then podejmijPrace ( source, skin ) end end ) And it outputs "test" when I'm entering the markers created in the same resource, but not this file. When I'm entering those created here, chat outputs nothing. C'mon... Link to comment
xXMADEXx Posted March 28, 2015 Share Posted March 28, 2015 Try using this: addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9] local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) local marker = createMarker ( x + 1, y, z - 1, "cylinder", 1, 255, 51, 255, 50 ) addEventHandler ( "onPlayerMarkerHit", root, function ( hitMarker ) outputChatBox ( "test" ) if ( hitMarker == marker ) then if ( isElement ( source ) and getElementType ( source ) == "player" ) then outputChatBox ( "test1" ) podejmijPrace ( source, skin ) end end end ) end end ) in onPlayerMarkerHit, the source is the player that hit, so I think if you use "root" rather than "marker," it should work. Link to comment
WhoAmI Posted March 28, 2015 Author Share Posted March 28, 2015 Nope, it doesn't work. But it outputs "test" when I enter another marker made in another file. Link to comment
xXMADEXx Posted March 28, 2015 Share Posted March 28, 2015 Ah, I didn't notice this. You're creating marker as a local variable, meaning it will only be accessible in that block of code, so it doesn't exist in the function that's being called by onPlayerMarkerHit. Maybe try using something like this: local markers = { } addEventHandler ( "onResourceStart", resourceRoot, function ( ) for index, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9] local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) markers [ index ] = createMarker ( x + 1, y, z - 1, "cylinder", 1, 255, 51, 255, 50 ) addEventHandler ( "onPlayerMarkerHit", root, function ( hitMarker ) outputChatBox ( "test" ) if ( table.isIn ( markers, hitMarker ) ) then if ( isElement ( source ) and getElementType ( source ) == "player" ) then outputChatBox ( "test1" ) podejmijPrace ( source, skin ) end end end ) end end ) function table.isIn ( tb, value ) for index, val in pairs ( tb ) do if ( value == val ) then return true end end return false; end Link to comment
WhoAmI Posted March 28, 2015 Author Share Posted March 28, 2015 Same as before. In other marker works, not in those created in this file. Link to comment
Mr-M3AND Posted March 29, 2015 Share Posted March 29, 2015 for _, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = unpack(d) addEventHandler ( "onResourceStart", resourceRoot, function ( ) local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) end ) local marker = createMarker ( x + 1, y, z - 1, "cylinder", 1, 255, 51, 255, 50 ) addEventHandler ( "onMarkerHit", marker, function ( hitMarker ) outputChatBox ( "test" ) if ( isElement ( hitMarker ) and getElementType ( hitMarker ) == "player" ) then outputChatBox ( "test1" ) podejmijPrace ( hitMarker, skin ) end end ) end Link to comment
TAPL Posted March 29, 2015 Share Posted March 29, 2015 Can't say what's wrong without seeing the rest of the code, also you shouldn't put event handler attached to root inside a loop. @Mr-M3AND, This is not even close, event onResourceStart inside a loop, seriously? Link to comment
WhoAmI Posted March 29, 2015 Author Share Posted March 29, 2015 That's main code, tho. In this file I got one more table and function which should be called after entering the marker. Link to comment
WhoAmI Posted March 29, 2015 Author Share Posted March 29, 2015 Solved. I just changed "cylinder" to "corona" and it works now. That's strange. Link to comment
Sasu Posted March 29, 2015 Share Posted March 29, 2015 (edited) Maybe it is under the ground. What about if you leave "z" instead of "z-1"? Edited March 29, 2015 by Guest Link to comment
WhoAmI Posted March 29, 2015 Author Share Posted March 29, 2015 I did it before posting code here. Link to comment
Ryancit2 Posted March 29, 2015 Share Posted March 29, 2015 I am 80% sure that its one same issue, the marker is created with player position with z-axis = one less right (?) Its probably creating marker under the ground so that marker won't be triggered until someone hits marker right on the base of marker, check this code and tell me if it works: addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, d in pairs ( modelki ) do local x, y, z, rx, ry, rz, int, dim, skin = d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9] local ped = createPed ( skin, x, y, z ) setElementRotation ( ped, rx, ry, rz ) setElementInterior ( ped, int ) setElementDimension ( ped, dim ) setElementFrozen ( ped, true ) setElementData ( ped, "modelka", true ) local marker = createMarker ( x + 1, y, z, "cylinder", 1, 255, 51, 255, 50 ) addEventHandler ( "onPlayerMarkerHit", marker, function ( hitMarker ) outputChatBox ( "test" ) if ( hitMarker == marker ) then if ( isElement ( source ) and getElementType ( source ) == "player" ) then outputChatBox ( "test1" ) podejmijPrace ( source, skin ) end end end ) end end ) Link to comment
WhoAmI Posted March 29, 2015 Author Share Posted March 29, 2015 Well, I have always been using "z-1" and it worked. In this case it didn't, don't know why. Problem is solved anyway, "corona" looks even better than normal cylinder. Link to comment
TAPL Posted March 29, 2015 Share Posted March 29, 2015 I guess it's the marker size, sometime it doesn't work with size 1, idk why. Link to comment
Ryancit2 Posted March 30, 2015 Share Posted March 30, 2015 I guess it's the marker size, sometime it doesn't work with size 1, idk why. That happens when marker is being made on Z+1 (axis height) and so, the marker with default size should start from ground but increasing size would also increase its height 'a bit' afaik that makes the event not trigger able because no one is able to touch the base of marker, which is attached with function to be called. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now