swedishboy Posted April 15, 2017 Share Posted April 15, 2017 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
Gordon_G Posted April 15, 2017 Share Posted April 15, 2017 It can not works because "marker1" is created inside the fonction who is handled. You can not handle a marker who do not exist. So, you'll need to create "marker1" before handling it. Link to comment
NeXuS™ Posted April 15, 2017 Share Posted April 15, 2017 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
swedishboy Posted April 15, 2017 Author Share Posted April 15, 2017 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
Gordon_G Posted April 15, 2017 Share Posted April 15, 2017 Move the fonction gethp to the top Link to comment
swedishboy Posted April 15, 2017 Author Share Posted April 15, 2017 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
Oussema Posted April 15, 2017 Share Posted April 15, 2017 (edited) 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 April 15, 2017 by Oussema 1 Link to comment
Oussema Posted April 15, 2017 Share Posted April 15, 2017 ye all right 16 minutes ago, DNL291 said: That will not work. Edited now it's gonna work , simple fail ahaha 1 Link to comment
DNL291 Posted April 16, 2017 Share Posted April 16, 2017 'hitElement' paramenter is missing in the function. Link to comment
Oussema Posted April 16, 2017 Share Posted April 16, 2017 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 now it's gonna work i'm sure 1 Link to comment
swedishboy Posted April 16, 2017 Author Share Posted April 16, 2017 Thanks but that wont work Link to comment
swedishboy Posted April 16, 2017 Author Share Posted April 16, 2017 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
Mr.Loki Posted April 16, 2017 Share Posted April 16, 2017 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
swedishboy Posted April 16, 2017 Author Share Posted April 16, 2017 @mr.Loki Thanks alot! 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