Hello, since noone answered on "how to make an attacking npc", I decided to make a non-attacking monster,
then I made a globalevent script that damages players nearby, and shoots from creature, the problem is, I think it's going to be too much code. Is there an easier way?
Thanks.
then I made a globalevent script that damages players nearby, and shoots from creature, the problem is, I think it's going to be too much code. Is there an easier way?
Thanks.
Code:
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
local pos1 = {x = 1001, y = 1005, z = 7}
function onThink(interval, lastExecution)
local redGuard1 = getTopCreature(pos1).uid
if(redGuard1 == 0) then
return true
end
for i = 2, 8, 1 do
topCreatureid1 = getTopCreature({x = pos1.x + i, y = pos1.y, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x + i, y = pos1.y, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x + i, y = pos1.y, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
for i = 2, 8, 1 do
topCreatureid1 = getTopCreature({x = pos1.x + i, y = pos1.y - 1, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x + i, y = pos1.y - 1, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x + i, y = pos1.y - 1, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
for i = 2, 8, 1 do
topCreatureid1 = getTopCreature({x = pos1.x + i, y = pos1.y - 2, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x + i, y = pos1.y - 2, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x + i, y = pos1.y - 2, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
for i = 1, 11, 1 do
topCreatureid1 = getTopCreature({x = pos1.x - 8 + i, y = pos1.y - 3, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x - 8 + i, y = pos1.y - 3, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x - 8 + i, y = pos1.y - 3, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
for i = 1, 11, 1 do
topCreatureid1 = getTopCreature({x = pos1.x - 8 + i, y = pos1.y - 2, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x - 8 + i, y = pos1.y - 2, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x - 8 + i, y = pos1.y - 2, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
for i = 1, 11, 1 do
topCreatureid1 = getTopCreature({x = pos1.x - 8 + i, y = pos1.y - 1, z = pos1.z}).uid
if(topCreatureid1 ~= 0) then
if(getPlayerGroupId(topCreatureid1) < 3) then
doCreatureAddHealth(topCreatureid1, -(getCreatureMaxHealth(topCreatureid1))/4)
doSendDistanceShoot({x = pos1.x, y = pos1.y, z = pos1.z}, {x = pos1.x - 8 + i, y = pos1.y - 1, z = pos1.z}, 30)
doSendAnimatedText({x = pos1.x - 8 + i, y = pos1.y - 1, z = pos1.z}, -round((getCreatureMaxHealth(topCreatureid1))/4, 0), 0)
end
end
end
return TRUE
end