Reezmi Posted November 1, 2012 Share Posted November 1, 2012 Why this only affects me, not the zombies? function Magic1(source) local radius = 10 local zombies = getElementsByType ( "ped" ) local x, y, z = getElementPosition(source) local attackSphere = createColSphere(x, y, z, radius) nearbyZombies = getElementsWithinColShape(attackSphere, zombies) destroyElement(attackSphere) for index, nearbyZombies in ipairs( nearbyZombies ) do setElementHealth ( nearbyZombies, tonumber(getElementHealth(nearbyZombies) or 0) - 25 ) end outputDebugString('attack') end Link to comment
50p Posted November 1, 2012 Share Posted November 1, 2012 First advice, don't name variables with the same names (eg. nearbyZombies). Also, try to avoid naming parameters with predefined variable names like source, root, etc. since the function called from an event will also pass the hidden source variable. Before you set element's health, check if the element is not "you". Link to comment
Reezmi Posted November 1, 2012 Author Share Posted November 1, 2012 I tried checking if peds are not player with isElement but it doesnt work. But if I remove if isElement(ped) it does take health from peds but it also takes health from me. Its like peds and me are the same. I just dont get it. Here's current code: function Magic1(source) local radius = 10 local x, y, z = getElementPosition(source) local attackSphere = createColSphere(x, y, z, radius) nearbyZombies = getElementsWithinColShape(attackSphere, source) destroyElement(attackSphere) for index, nearbyZombies in ipairs( nearbyZombies ) do if isElement(ped) then setElementHealth ( nearbyZombies, tonumber(getElementHealth(nearbyZombies) or 0) - 25 ) else outputDebugString('yes') end end outputDebugString('attack') end Link to comment
TAPL Posted November 1, 2012 Share Posted November 1, 2012 Use getElementType instead of isElement. Link to comment
Reezmi Posted November 1, 2012 Author Share Posted November 1, 2012 Still the same effect if getElementType ( source ) == "ped" then Link to comment
Renkon Posted November 1, 2012 Share Posted November 1, 2012 function Magic1(source) local r = 10 local x, y, z = getElementPosition(source) local sp = createColSphere(x, y, z, r) local peds = getElementsWithinColShape(sp, "ped") destroyElement(sp) for _, p in ipairs (peds) do if (getElementType(p) ~= "player") then setElementHealth(p, (getElementHealth(p) or 0) - 25) end end end Link to comment
TAPL Posted November 1, 2012 Share Posted November 1, 2012 Still the same effect if getElementType ( source ) == "ped" then if getElementType ( nearbyZombies ) == "ped" then Link to comment
Reezmi Posted November 1, 2012 Author Share Posted November 1, 2012 YESS, FINALLY. Thank you very much. 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