Reezmi Posted November 1, 2012 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
50p Posted November 1, 2012 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".
Reezmi Posted November 1, 2012 Author 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
Reezmi Posted November 1, 2012 Author Posted November 1, 2012 Still the same effect if getElementType ( source ) == "ped" then
Renkon Posted November 1, 2012 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
TAPL Posted November 1, 2012 Posted November 1, 2012 Still the same effect if getElementType ( source ) == "ped" then if getElementType ( nearbyZombies ) == "ped" then
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