Jump to content

Marker table problem


swedishboy

Recommended Posts

Hello. I cant see the markers and im getting this warning in debugscript

Bad argument @ 'addEventHandler' [expected element at argument 2, got nil]

	local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595},
}
    
function getHp (player)
    for k,v in ipairs (spots) do
    marker1 = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22)
    end    
    local money = getPlayerMoney(player)
    local hpp = getElementHealth(player)
    if money >= 1000 and hpp < 100 then
       setElementHealth(player, 100)
       takePlayerMoney(player, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", player, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", player, 222, 44, 22)
    end
end
addEventHandler("onMarkerHit", marker1, getHp)
	

Link to comment
local spots = {
	{2488.32886, -1670.63599, 12.33595},
	{2490.92886, -1670.63599, 12.33595},
	{2495.92886, -1670.63599, 12.33595}
}

for k,v in ipairs (spots) do
	marker1 = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22) -- Creating the markers when the resource is started.
	addEventHandler("onMarkerHit", marker1, getHp) -- Handling markerhits for every marker which is created.
end

function getHp (player)
	local money = getPlayerMoney(player)
	local hpp = getElementHealth(player)
	if money >= 1000 and hpp < 100 then
		setElementHealth(player, 100)
		takePlayerMoney(player, 1000)
	elseif money >= 1000 and hpp >= 100 then
		outputChatBox("Your HP is already full", player, 222, 44, 22)
	elseif money < 1000 then
		outputChatBox("You don't have enough money", player, 222, 44, 22)
	end
end

I think this one should work.

Link to comment

I can see the markers with this code but still not working.. getting this warning Bad argument @ 'addEventHandler' [expected element at argument 3, got nil]

	local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595}
}
	for k,v in ipairs (spots) do
    marker1 = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22)
    addEventHandler("onMarkerHit", marker1, getHp)
end    
function getHp (player)
    local money = getPlayerMoney(player)
    local hpp = getElementHealth(player)
    if money >= 1000 and hpp < 100 then
       setElementHealth(player, 100)
       takePlayerMoney(player, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", player, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", player, 222, 44, 22)
    end
end
	

Link to comment

Like this?

	local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595}
}
	function getHp (player)
    for k,v in ipairs (spots) do
    marker1 = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22)
    addEventHandler("onMarkerHit", marker1, getHp)
    end    
	    local money = getPlayerMoney(player)
    local hpp = getElementHealth(player)
    if money >= 1000 and hpp < 100 then
       setElementHealth(player, 100)
       takePlayerMoney(player, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", player, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", player, 222, 44, 22)
    end
end
	

Link to comment
markers = {}

local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595}
}



for k,v in ipairs (spots) do
    markers[k] = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22)
    addEventHandler("onMarkerHit", markers[k], function()
    local money = getPlayerMoney(hitElement)
    local hpp = getElementHealth(hitElement)
    if money >= 1000 and hpp < 100 then
       setElementHealth(hitElement, 100)
       takePlayerMoney(hitElement, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", hitElement, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", hitElement, 222, 44, 22)
    end
    end)
end	

	

This gonna work

Edited by Oussema
  • Like 1
Link to comment
markers = {}

local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595}
}



for k,v in ipairs (spots) do
    markers[k] = createMarker(v[1],v[2],v[3], "cylinder", 1.2, 22, 22, 22)
    addEventHandler("onMarkerHit", markers[k], function(hitElement, mtd)
    local money = getPlayerMoney(hitElement)
    local hpp = getElementHealth(hitElement)
    if money >= 1000 and hpp < 100 then
       setElementHealth(hitElement, 100)
       takePlayerMoney(hitElement, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", hitElement, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", hitElement, 222, 44, 22)
    end
    end

i don't see them :v anyway thx xD now it's gonna work i'm sure

  • Like 1
Link to comment

I made this and it works but only on 1 marker not on all markers in the table..

	local spots = {
{2488.32886, -1670.63599, 12.33595},
{2490.92886, -1670.63599, 12.33595},
{2495.92886, -1670.63599, 12.33595}
}
	for  k,v in ipairs (spots) do
    marker1 = createMarker(v[1], v[2], v[3], "cylinder", 1.2, 22, 22, 22)
end
    
function getHp (player)
    local money = getPlayerMoney(player)
    local hpp = getElementHealth(player)
    if money >= 1000 and hpp < 100 then
       setElementHealth(player, 100)
       takePlayerMoney(player, 1000)
    elseif money >= 1000 and hpp >= 100 then
       outputChatBox("Your HP is already full", player, 222, 44, 22)
    elseif money < 1000 then
       outputChatBox("You don't have enough money", player, 222, 44, 22)
    end
end
addEventHandler("onMarkerHit", marker1, getHp)
	

Link to comment
local markers={}
local spots = {
    {2488.32886, -1670.63599, 12.33595},
    {2490.92886, -1670.63599, 12.33595},
    {2495.92886, -1670.63599, 12.33595}
}

for  k,v in ipairs (spots) do
    local m = createMarker(v[1], v[2], v[3], "cylinder", 1.2, 22, 22, 22)
    markers[m] = true
end
    
function getHp (player)
    local money = getPlayerMoney(player)
    local hpp = getElementHealth(player)
    if markers[source] and money >= 1000 then
        if hpp < 100 then
            setElementHealth(player, 100)
            takePlayerMoney(player, 1000)
        elseif money >= 1000 and hpp >= 100 then
            outputChatBox("Your HP is already full", player, 222, 44, 22)
        end
    else
       outputChatBox("You don't have enough money", player, 222, 44, 22)
    end
end
addEventHandler("onMarkerHit", resourceRoot, getHp)

 

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