Jump to content

Weird problem


WhoAmI

Recommended Posts

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

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

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

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
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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...