- Joined
- Jul 7, 2007
- Messages
- 4,049
- Reaction score
- 238
Hey
I present to you all a simple trap system:
[video=youtube_share;Tnh9JVwj5Hg]
I initially placed 4 traps with 10 seconds delay, then I disabled that delay(so I wouldn't have to change windows all the time) and placed the others to show them working, whenever I stood still was because I was messing around with the controls to make it easy and simple to show everything as fast as possible.
The traps activate either by stepping on them or if they reach the time limit defined in the config
Note: The damage didn't show because since I had a God I was unable to damage normal players, but it does do damage, it also works on monsters and summons!
How to use this:
Write the code above in a Lua file and put it in the data/libs folder
Make your own traps on the configs, they can be whatever you want, from simple damages like the Fire/Energy/Ice/Earth traps, to other fun and more complex functions, very simple to configure, the rest of the configs are obvious I think
To make use of the system you need to use the function placeMine(cid, trapType) where cid is the player that placed the trap and trapType is the number of the trap you want to use, so if you want to make a spell to place a fire trap, its as simple as:
I think that's it, like I said simple =)
Thoughts? Comments? Suggestions?
I present to you all a simple trap system:
[video=youtube_share;Tnh9JVwj5Hg]
I initially placed 4 traps with 10 seconds delay, then I disabled that delay(so I wouldn't have to change windows all the time) and placed the others to show them working, whenever I stood still was because I was messing around with the controls to make it easy and simple to show everything as fast as possible.
The traps activate either by stepping on them or if they reach the time limit defined in the config
Note: The damage didn't show because since I had a God I was unable to damage normal players, but it does do damage, it also works on monsters and summons!
Code:
local config = {
itemRequired = 2579, --0 to not require an item
recoverItem = 2578, --0 to disable
trapLimit = 3, --0 to disable
checkInterval = 100, --How often it checks if someone is on the tile, lower values increase accuracy(incase a player but may increase lag
timeToActivate = (10 * 1000), --How long until they automatically activate (0 to disable, only activates when stepped, NOT RECOMMENDED because it might generate lag since they will only disappear when someone steps on them!)
timeToDestroyItem = (60 * 1000), -- How long until the item is removed from game if it's not picked up
types = {
[1] = function(cid, pos) --Fire Trap
doCombatAreaHealth(cid, COMBAT_FIREDAMAGE, pos, nil, 100, 200, CONST_ME_FIREAREA)
return true
end,
[2] = function(cid, pos) --Energy Trap
doCombatAreaHealth(cid, COMBAT_ENERGYDAMAGE, pos, nil, 100, 200, CONST_ME_ENERGYHIT)
return true
end,
[3] = function(cid, pos) --Ice Trap
doCombatAreaHealth(cid, COMBAT_ICEDAMAGE, pos, nil, 100, 200, CONST_ME_ICEATTACK)
return true
end,
[4] = function(cid, pos) --Earth Trap
doCombatAreaHealth(cid, COMBAT_EARTHDAMAGE, pos, nil, 100, 200, CONST_ME_CARNIPHILA)
return true
end,
[5] = function(cid, pos) --Fake Demon Trap
for i = 1, 8, 1 do
local mob = doCreateMonster("Rat", pos)
doSetMonsterOutfit(mob, "Demon")
end
return true
end,
[6] = function(cid, pos) --Blabber Trap
local creature = getTopCreature(pos).uid
local talks = {
"OTLand rocks!", "Scarlet Ayleid sucks!!1!11", "fri itens plzz",
"br?", "pl?", "no ks", "hauhauhahuahahua", "help plzz", "pk pk pk pk pk pk",
"pandas own", "Rep me++"
}
doSendMagicEffect(pos, CONST_ME_CRAPS)
for i = 1, 20, 1 do
addEvent(doCreatureSay, i * 1000, creature, talks[math.random(1, 6)], TALKTYPE_MONSTER)
end
return true
end
}
}
local players = {
--[cid] = 0
}
local function removeTrap(pos)
local item = getTileItemById(pos, config.recoverItem)
if(item) then
doRemoveItem(item.uid)
end
return true
end
local function activateTrap(cid, pos, trapType)
if(not isPlayer(cid)) then
return false
end
players[cid] = players[cid] - 1
config.types[trapType](cid, pos)
if(config.recoverItem > 0) then
doCreateItem(config.recoverItem, 1, pos)
if(config.timeToDestroyItem > 0) then
addEvent(removeTrap, config.timeToDestroyItem, pos)
end
end
return true
end
local function trapCheck(cid, pos, trapType, timer)
local creature = getTopCreature(pos).uid
if(((config.timeToActivate > 0) and (timer >= config.timeToActivate)) or (creature > 0 and (cid ~= creature))) then
return activateTrap(cid, pos, trapType)
end
addEvent(trapCheck, config.checkInterval, cid, pos, trapType, timer + config.checkInterval)
return true
end
function placeMine(cid, trapType)
if(config.trapLimit > 0 and players[cid] and players[cid] >= config.trapLimit) then
sendCancelMessage(cid, "You can only place " .. config.trapLimit .. " traps at once.")
return false
end
local pos = getCreaturePosition(cid)
if(config.itemRequired == 0 or doPlayerRemoveItem(cid, config.itemRequired, 1)) then
addEvent(trapCheck, config.checkInterval, cid, pos, trapType, config.checkInterval)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Trap has been placed!")
doSendMagicEffect(pos, CONST_ME_BLOCKHIT, cid)
if(players[cid]) then
players[cid] = players[cid] + 1
else
players[cid] = 1
end
else
local itemInfo = getItemInfo(config.itemRequired)
sendCancelMessage(cid, "You need " .. itemInfo.article .. " " .. itemInfo.name .. " to be able to place a trap.")
end
return true
end
Write the code above in a Lua file and put it in the data/libs folder
Make your own traps on the configs, they can be whatever you want, from simple damages like the Fire/Energy/Ice/Earth traps, to other fun and more complex functions, very simple to configure, the rest of the configs are obvious I think
To make use of the system you need to use the function placeMine(cid, trapType) where cid is the player that placed the trap and trapType is the number of the trap you want to use, so if you want to make a spell to place a fire trap, its as simple as:
Code:
function onCastSpell(cid, var)
return placeMine(cid, 1)
end
I think that's it, like I said simple =)
Thoughts? Comments? Suggestions?
Last edited: