Hello, well i thougt about release a christmas present to everyone in otland. Here you go guys:
Cheers @Ninja and @Limos for the help
Features:
Then go to data/actions/scripts and create new lua and name it "twdHammer" and paste this:
Now go into data/creaturescripts/creaturescripts.xml and paste these lines:
And now go to data/creaturescripts/scripts and create new folder and name it twdEvent and now create these lua's files:
twdBuildWindow.lua
twdDeath.lua
twdHealthChange.lua
twdOnLose.lua
twdOtherWindow.lua
Cheers @Ninja and @Limos for the help
Features:
- Unlimited waves can be configured!
- Monsters health, gold drop and speed can be configured!
- Different monsters, counts and space between the monster can be configred!
- Unlimited turrets can be added!
- Turrets cost, upgrade, sell, range, color and attackSpeed can be also easily configured!
- Reward of wining a wave can also be configured, exp and gold wise
Code:
<action itemid="2557" script="twdHammer.lua" allowfaruse="1"/>
Then go to data/actions/scripts and create new lua and name it "twdHammer" and paste this:
Code:
dofile('data/libs/TWD/towerDefenseLib.lua')
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(playingGameStorage) ~= 1 then
return false
end
local tile = toPosition:getTile()
if tile then
if not tile:hasFlag(TILESTATE_PROTECTIONZONE) or tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then
player:sendCancelMessage("You cannot place the turret here.")
return true
end
end
if target:isItem() then
local modalWindow = ModalWindow(100, "Build Turret", "Here you can select variations of turrets to build.")
local turret, cfgTable = turrets.allTurretsId
for i = 1, #turret do
turret = turrets.allTurretsId[i]
cfgTable = turrets[turret].cfg
modalWindow:addChoice(turret, string.format("%s [%s coins]", cfgTable.turretName, cfgTable[1].buildPrice))
end
modalWindow:addButton(0, "Build")
modalWindow:setDefaultEnterButton(0)
modalWindow:addButton(1, "Cancel")
modalWindow:setDefaultEscapeButton(1)
modalWindow:sendToPlayer(player)
turretPosition = toPosition
elseif target:isNpc() and target:getName() == "Turret" then
local table = turrets[target:getOutfit().lookType]
local lvl = target:getTurretLevel()
local cfg, cfgCombat = table.cfg[lvl], table.combat[lvl]
local turrentInfo = string.format("Turret Information\n----------------------------\nTurret Level: %s\nAttack Type: %s\nRange SQM: %sx%s\nTurret Damage: [%s - %s]\nAttack Speed: %s\nSell/Upgrade Price: [%s / %s]", lvl, string.upper(cfgCombat.attackType), cfg.rangeX, cfg.rangeY, cfgCombat.dmgValues[1], cfgCombat.dmgValues[2], cfg.attackSpeed, cfg.sellPrice, cfg.upgradePrice)
local playerInfo = string.format("Player Information\n----------------------------\nWave Level: %s\nYour Coins: %s", getWaveLevel(), player:getCoins())
local modalWindow = ModalWindow(101, "Information", string.format("%s\n\n%s", turrentInfo, playerInfo))
if lvl < 3 then
modalWindow:addChoice(0, "Upgrade")
end
modalWindow:addChoice(1, "Sell")
modalWindow:addButton(0, "Yes")
modalWindow:setDefaultEnterButton(0)
modalWindow:addButton(0x01, "Cancel")
modalWindow:setDefaultEscapeButton(1)
modalWindow:sendToPlayer(player)
targetTurret = target
end
return true
end
Now go into data/creaturescripts/creaturescripts.xml and paste these lines:
Code:
<event type="death" name="TWDDeath" script="twdEvent/twdDeath.lua"/>
<event type="preparedeath" name="TWDOnLose" script="twdEvent/twdOnLose.lua"/>
<event type="modalwindow" name="TWDBuildWindow" script="twdEvent/twdBuildWindow.lua"/>
<event type="modalwindow" name="TWDOtherWindow" script="twdEvent/twdOtherWindow.lua"/>
<event type="healthchange" name="TWDHealthChange" script="twdEvent/twdHealthChange.lua"/>
And now go to data/creaturescripts/scripts and create new folder and name it twdEvent and now create these lua's files:
twdBuildWindow.lua
Code:
dofile('data/libs/TWD/towerDefenseLib.lua')
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId ~= 100 then -- Not our window
return false
elseif buttonId == 1 then -- Cancel
return false
end
local choice = turrets[choiceId]
if not choice then
return false
end
local table = choice.cfg[1]
if player:getCoins() < choice.cfg[1].buildPrice then
player:sendCancelMessage("You don't have enough of coins.")
return false
end
local npc = Game.createNpc("Turret", turretPosition, false, true)
if not npc then
return false
end
player:addCoins(-choice.cfg[1].buildPrice)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have total ".. player:getCoins() .." coins.")
local setColor = table.colorId
npc:setOutfit({lookType = choiceId, lookHead = setColor , lookBody = setColor, lookLegs = setColor, lookFeet = setColor})
npc:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
return true
end
twdDeath.lua
Code:
dofile('data/libs/TWD/towerDefenseLib.lua')
local function sendToNextWave(cid)
local player = Player(cid)
if not player then
return false
end
local waveLevel = getWaveLevel()
setWaveLevel(waveLevel + 1) -- Let's add + 1 to our current wave
waveLevel = getWaveLevel() -- Let's refresh the variable
if waveLevel <= waves.maxWaveLevel then -- Let's make sure there is more waves / Else end the event
local waveTable = waves[waveLevel]
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have advanced to wave level %s, gained %s coins and %s experience points.", waveLevel, waveTable.goldBonus, waveTable.expBonus))
startNextWave(waveLevel, twdConfig.startNextWaveTime)
Game.setStorageValue(totalMonsterKillCountGlobalStorage, 0)
player:addCoins(waveTable.goldBonus)
player:addExperience(waveTable.expBonus, true)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have now total ".. player:getCoins() .." coins.")
else
sendReward(cid)
resetEvent()
end
end
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
local player = getPlayerInEvent(20, 20)
if not player then -- Make sure that the players exsist in the arena, to prevent errors
return true
end
if killer and killer:isNpc() then
local cfg = monsters[creature:getName()]
creature:say("+" ..cfg.coins, TALKTYPE_MONSTER_SAY)
player:addCoins(cfg.coins)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have total ".. player:getCoins() .." coins.")
end
Game.setStorageValue(totalMonsterKillCountGlobalStorage, Game.getStorageValue(totalMonsterKillCountGlobalStorage) + 1)
if Game.getStorageValue(totalMonsterKillCountGlobalStorage) >= Game.getStorageValue(totalMonsterCountGlobalStorage) then
sendToNextWave(player:getId())
end
return true
end
twdHealthChange.lua
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if primaryType == COMBAT_HEALING then
return false
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
twdOnLose.lua
Code:
dofile('data/libs/TWD/towerDefenseLib.lua')
function onPrepareDeath(player, killer)
if player:getStorageValue(playingGameStorage) ~= 1 then
return true
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have lost the Tower Of Defence Event.")
player:resetValues()
addEvent(resetEvent, twdConfig.resetEventTime * 1000)
return false
end
twdOtherWindow.lua
Code:
dofile('data/libs/TWD/towerDefenseLib.lua')
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId ~= 101 then -- Not our window
return false
elseif buttonId == 1 then -- Cancel
return false
end
local npc = targetTurret
local npcLvl = npc:getTurretLevel()
local table = turrets[npc:getOutfit().lookType].cfg[npcLvl]
if choiceId == 0 then
if player:getCoins() < table.upgradePrice then
player:sendCancelMessage("You don't have enough of coins.")
return false
end
npcLvl = npcLvl + 1
local setColor = table.colorId
npc:setOutfit({lookType = npc:getOutfit().lookType, lookHead = setColor , lookBody = setColor, lookLegs = setColor, lookFeet = setColor, lookAddons = npcLvl})
npc:getPosition():sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
player:addCoins(-table.upgradePrice)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have total ".. player:getCoins() .." coins.")
targetTurret = nil
else
player:addCoins(table.sellPrice)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have total ".. player:getCoins() .." coins.")
npc:say("+" ..table.sellPrice, TALKTYPE_MONSTER_SAY)
player:addCoins(table.sellPrice)
npc:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
npc:remove()
targetTurret = nil
end
return true
end
Part 2 can be founded below!
Last edited: