Jump to content

[Help] Warning


Daniels69

Recommended Posts

Hello , lately i was making something like an house system. and i stopped at this warning. which i can't really solve , or my lua experience is too small.

it appears that the code below doesn't seem to get the housemark variable.. and that's why the warning comes , and the script doesn't really work any more , any ideas how to solve it? Thanks

CODE:

  
  
function addhouses(thePlayer,command,arg) 
    local x,y,z = getElementPosition(thePlayer) 
    local r,g,b = 255,255,0 
     housemark = createMarker ( x , y, z+1, "arrow", 1.5, r, g, b, 170 ) 
    if (housemark) then outputDebugString("house created") 
        setElementData(housemark,"mtasa-house",true) 
        setElementData(housemark,"mtasa-housename",arg) 
    --  if getElementData(house,"mtasa-housesold") == false  
end 
end 
addCommandHandler("addhouse",addhouses) 
  
function househit(player) 
      if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then 
   if not isGuestAccount( getPlayerAccount( player ) ) then 
     --some stuff happens here 
        else 
          outputChatBox( 'You must be logged in', player, 255, 51, 36 ); 
        end; 
      end; 
  end  
addEventHandler("onMarkerHit",housemark,househit) 

ERROR:

WARNING: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Link to comment

Use the addEventHandler when you create it (= use it after line 6).

Also you can use local for the housemarker after you did that.

Explanation:

You create the marker after using the command.

So you can't attach the addEventHandler before using the command, cause the marker isn't even created.

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