• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

NPC [TFS 1.0] Summon any creature in the game for a bloody price.

Jack Parsons

Member
Joined
Mar 8, 2016
Messages
32
Reaction score
12
Location
São Paulo State, Brazil
I've just created a "Summoner" NPC. I've never seen anything like it in any OT that I've played, so I thought it would be interesting to implement one.

Instructions:
  1. Say 'hi'.
  2. Say 'Summon Creature' (Where "Creature" is Demon or any other creature, no quotes)
  3. Say 'yes'
The price depends on your level. The formula is (getPlayerLevel(cid) * getPlayerLevel(cid)) * 3. The higher your level, the higher the price (The lower your level, the greater your death by the insane monsters you choose).

Summoner.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Summoner" script="summoner.lua" walkinterval="5000" speed="100" walkradius="1" floorchange="0">
    <health max="100" now="100"/>
    <look type="133" head="114" body="114" legs="114" feet="114" addons="2" mount="0"/>
    <parameters>
        <parameter key="message_greet" value="Which creature would you like me to {summon}? But beware, you'll be punished if you misspell the creature's name."/>
    </parameters>
</npc>

summoner.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)
    npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
    npcHandler:onCreatureDisappear(cid) 
end
function onCreatureSay(cid, type, msg)
    npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
    npcHandler:onThink()
end

function split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

local creatureName = nil

function getPrice(cid, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("getPrice called without any npcHandler instance.")
    end
    if not npcHandler:isFocused(cid) then
        return false
    end
    creatureName = split(message, ' ')
    local price = (getPlayerLevel(cid) * getPlayerLevel(cid)) * 3
    if #creatureName == 2 then
        local c = Creature(creatureName[2])
        npcHandler:say("Would you like me to summon a {" .. creatureName[2] .. "} for {" .. price .. "} gold coins?", cid)
    elseif #creatureName == 3 then
        npcHandler:say("Would you like me to summon a {" .. creatureName[2] .. ' ' .. creatureName[3] .. "} for {" .. price .. "} gold coins?", cid)
    else
        npcHandler:say("I can't summon a creature with such a name.", cid)
        npcHandler:resetNpc(cid)
    end
    return true
end

function summonCreature(cid, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("summonCreature called without any npcHandler instance.")
    end
    if not npcHandler:isFocused(cid) then
        return false
    end
    npcHandler:say("Be happy! I hope you die.", cid)
    local summonPos = getPlayerPosition(cid)
    if getPlayerLookDir(cid) == NORTH then
        summonPos.y = summonPos.y + 1
    elseif getPlayerLookDir(cid) == SOUTH then
        summonPos.y = summonPos.y - 1
    elseif getPlayerLookDir(cid) == EAST then
        summonPos.x = summonPos.x - 1
    elseif getPlayerLookDir(cid) == WEST then
        summonPos.x = summonPos.x + 1
    end
    local price = (getPlayerLevel(cid) * getPlayerLevel(cid)) * 3
    if #creatureName == 2 then
        doPlayerRemoveMoney(cid, price)
        Game.createMonster(creatureName[2], summonPos)
    elseif #creatureName == 3 then
        doPlayerRemoveMoney(cid, price)
        Game.createMonster(creatureName[2] .. ' ' .. creatureName[3], summonPos)
    end
    npcHandler:resetNpc(cid)
    return true
end

function nope(cid, message, keywords, parameters, node)
    local npcHandler = parameters.npcHandler
    if npcHandler == nil then
        error("nope called without any npcHandler instance.")
    end
    if not npcHandler:isFocused(cid) then
        return false
    end
    npcHandler:say("Then get the fuck out of here!!", cid)
    npcHandler:resetNpc(cid)
    return true
end

local node = keywordHandler:addKeyword({"summon"}, getPrice, {npcHandler = npcHandler, onlyFocus = true})
node:addChildKeyword({"yes"}, summonCreature, {npcHandler = npcHandler})
node:addChildKeyword({"no"}, nope, {npcHandler = npcHandler})

npcHandler:addModule(FocusModule:new())
 
Back
Top