Spike trap
Posted: Fri Apr 05, 2013 12:09 am
This is my little mod for adding Spike traps.
http://grimrock.nexusmods.com/mods/250

http://grimrock.nexusmods.com/mods/250
SpoilerShow

SpoilerShow



Code: Select all
----- Animation alcoves ----------------------------------------------------
----------------------- Functions for Ramp ------------------------------------
function GetKQ(ax,ay,bx,by)
local k,q
k = (by-ay)*1.0/(bx-ax)*1.0
q = 1.0*ay-(k*ax)
return k,q
end
function GetLV(ramp,i)
return ramp[i-1].x,ramp[i-1].y,ramp[i].x,ramp[i].y
end
function GetTableFromRamp(ramp,poc)
local ax,ay,bx,by,k,q,i,j,p,x
local tab = {}
p = 100.0 / (poc*1.0)
i = 2
ax,ay,bx,by = GetLV(TRamp,i)
for j = 1, poc do
x = (j*1.0)*(p*1.0)
while (x > bx) and (i < #TRamp) do
i = i+1
ax,ay,bx,by = GetLV(TRamp,i)
end
if x == bx then
y=by
else
ax,ay,bx,by = GetLV(TRamp,i)
k,q = GetKQ(ax,ay,bx,by)
y = k*x + q
end
tab[j]={["x"]=x,["y"]=y/100.0}
end
return tab
end
SpikeAnimCount = 20
--TRamp = {{x=0,y=0},{x=10,y=80},{x=20,y=50},{x=30,y=100},{x=50,y=100},{x=100,y=0}}
TRamp = {{x=0,y=0},{x=10,y=100},{x=20,y=80},{x=30,y=70},{x=100,y=0}}
TTRamp = GetTableFromRamp(TRamp,SpikeAnimCount)
for i = 1, #TTRamp do
defineObject{
name = "spikeTrap_socket_"..i-1,
class = "Alcove",
anchorPos = vec(0, (0.5*TTRamp[i].y)-0.5, -1.5),
anchorRotation = vec(0, 0, 0),
targetPos = vec(0, 5, 0),
targetSize = vec(1, 1, 1),
placement = "wall",
onInsertItem = function(self, item)
return item.name == "SpikeTrap_spikes" and self:getItemCount() == 0
end,
editorIcon = 92,
}
end
Ok I wos upload v1.1 with this function for youmsyblade wrote:So you got it animated, to see the spikes rise and slowly retract? GREAT work. Now we gotta get a playsound for it. Perhaps one of the weapon swings, [Scchhhwwiiiing!]