Re: AI Switcher
Posted: Wed May 08, 2013 2:37 am
but it's not what they drop, it's what drops when it hits the monster, which happens when you mouse-toss something
This ?Komag wrote:You can take a look at my snail king fight code (in snailWallScript on level 7) which solves this by counting all projectiles (they don't all count the same way either) and spawning the ones that are stuck "inside" the monster on the floor at the time of "teleport" or destroying the monster. I used onDie and onProjectileHit hooks. Part of the code has to account for possible "mouse thrown" projectiles which don't stick but do register as projectile hits.
Code: Select all
function snailDie()
_restoreProj()
end
function projHit(proj) -- trig by snail_king onProjectileHit hook
pr.nt("snail king hit by "..proj.name)
local p = {"cold_arrow", "fire_arrow", "poison_arrow", "shock_arrow", "arrow"}
local q = {"cold_quarrel","fire_quarrel","poison_quarrel","shock_quarrel","quarrel"}
local r = {"throwing_knife","shuriken","throwing_axe"}
for i=1,5 do
if proj.name == p[i] then snailArrows = snailArrows + 1 end
if proj.name == q[i] then snailQurrls = snailQurrls + 1 end
end
if proj.name == r[1] then snailKnives = snailKnives +1 end
if proj.name == r[2] then snailShrkns = snailShrkns +1 end
if proj.name == r[3] then snailAxes = snailAxes +1 end
end
snailArrows = 0
snailQurrls = 0
snailKnives = 0
snailShrkns = 0
snailAxes = 0
function _restoreProj() -- trig by snailDie()
local cArws = 0
local cQrls = 0
local cKnvs = 0
local cShks = 0
local cAxes = 0
for i in entitiesAt(7,10,31) do
if i.name == "arrow" then cArws = cArws + 1
elseif i.name == "quarrel" then cQrls = cQrls + 1
elseif i.name == "throwing_knife" then cKnvs = cKnvs + 1
elseif i.name == "shuriken" then cShks = cShks + 1
elseif i.name == "throwing_axe" then cAxes = cAxes + 1
end
end
local a = snailArrows - cArws
local b = snailQurrls - cQrls
local c = snailKnives - cKnvs
local d = snailShrkns - cShks
local e = snailAxes - cAxes
local t1 = {"arrow","quarrel","throwing_knife","shuriken","throwing_axe"}
local t2 = {a,b,c,d,e}
for h=1,5 do
if t2[h] > 0 then for i = 1,t2[h] do
local c=math.random(1,2) local d=1 if c==1 then d=-1 end
local e=math.random(1,2) local f=1 if e==1 then f=-1 end
local g=math.random(1,2) local z=1 if g==1 then z= 3 end
spawn(t1[h],7,10,31,z)
:setSubtileOffset(math.random()*d,math.random()*f)
end end
end
end
Code: Select all
onDie = function(self)
snailWallScript.snailDie()
return false
end,
onProjectileHit = function(self,proj,amt,type)
snailWallScript.projHit(proj)
end,
That's why I have the script count any on the ground first and subtract that from the total. If the monster can move around a lot it's harder, but the ground could be searched a moment after every projectile hit registers, to see if a new item is found, indicated the player threw it instead of shooting it, and not add it to the total.Xanathar wrote:...This seem to work but is cheatable. For example take a shuriken, throw (not shoot!) to the monster, now the shuriken is duplicated (as if thrown with the mouse and not by an attack, it still counts as a projectile but does not stuck in the monster).