• 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!

TFS 1.X+ Simple CreatureScript Question.

God Nixez

Member
Joined
Sep 20, 2009
Messages
410
Reaction score
17
Hello there, Well iam trying to add this script to my own server
Orb Siphoning - New Looting Method - TFS 1.3/Otx3 - 8.6/10.98
the question is "What Line should i add to CreatureScripts.xml"
The one i use atm is this "<event type="death" name="orbs" script="orbs.lua" />"
but it dosn't work as i raised the chance to drop orb to 99%
Also i have registered it in Login.lua

Please Help me :D
Actual script code:
Lua:
function sendRandom(r)
    return math.random(-r, r)
end
local version = 1098
-- you can put these in global
ORB_TIME = 16
ORB_INCREMENTS = 1000
--
function cashRandom(min, max)
    return math.random(min, max)
end
function comma_value(amount)
  local formatted = amount
  while true do
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end
function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
function giveMoney(m)
    local g = m
    local nug, cc, plat, gold, t = 1000000, 10000, 100, 1, {}
    while(m ~= 0) do
        if m >= nug then
            local c = m / nug
            m = m - (c * nug)
            table.insert(t, {2157, c}) -- nuggets
        elseif m >= cc then
            local c = math.floor(m / cc)
            m = m - (c * cc)
            table.insert(t, {2160, c}) -- crystal coin
        elseif m >= plat then
            local c = math.floor(m / plat)
            m = m - (c * plat)
            table.insert(t, {2152, c}) -- plat coins
        elseif m >= gold then
            local c = math.floor(m / gold)
            m = m - (c * gold)
            table.insert(t, {2148, c}) -- gold coins
        end
    end
    return t, g
end
function sendOrbEffect(cid, tier)
    local player = Player(cid)
    if not player then
        return false
    end
    local colors = {5,30,35,95,108,129,143,155,180,198,210,215}
    local xp = player:getExperience()
    local exp = getExpForLevel(player:getLevel() + 1)
    local orbs = {
        {
            type_ = "cash",
            name = "~* gold *~",
            symbol = "$$",
            itemid = function(x)
                local tier = x or 1
                local cash = 0
                local min_coin = (tier * 5)
                local max_coin = (tier * 50)
                return cashRandom(min_coin, max_coin)
            end
        },
        {
            type_ = "loot",
            name = "~* loot *~",
            symbol = "fri itens plx!",
            itemid = function(n)
                local t = {
                    [1] = {
                        {6433, 1},
                        {2503, 1},
                        {2504, 1},
                        {2641, 1},
                        {2542, 1},
                        {6301, 1},
                        {2184, 1},
                        {2406, 1},
                        {2423, 1},
                        {2393, 1},
                        {2415, 1},
                        {5907, 1}
                    },
                    [2] = {
                        {2457, 1},
                        {2463, 1},
                        {2647, 1},
                        {2645, 1},
                        {2532, 1},
                        {2213, 1},
                        {8910, 1},
                        {2403, 1},
                        {7432, 1},
                        {7449, 1},
                        {2387, 1},
                        {2414, 1}
                    },
                    [3] = {
                        {2496, 1},
                        {2505, 1},
                        {2469, 1},
                        {3982, 1},
                        {2517, 1},
                        {2121, 1},
                        {2181, 1},
                        {8209, 1},
                        {8927, 1},
                        {2419, 1},
                        {3962, 1},
                        {8856, 1}
                    }
                }
                n = n > 3 and 3 or n
                return t[n][math.random(#t[n])]
            end,
        },
        {
            type_ = "xp",
            name = "~* exp *~",
            symbol = "Free XP!",
            itemid = function(n)
                return exp - xp
            end,
        }
    }
    local effects = {2, 5, 6, 7, 11, 12, 16, 18, 19, 20,27,37, 38}
    local loot = orbs[math.random(#orbs)]
    local msg = ''
    local p = player:getPosition()
    for i = 1, ORB_TIME do
        p.x = p.x + sendRandom(1)
        p.y = p.y + sendRandom(1)
        addEvent(function(x, n, cid, t)
            local player = Player(cid)
            if player then
                x:sendMagicEffect(effects[math.random(#effects)])
                if player:getPosition() == x then
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.symbol, x, colors[math.random(#colors)])
                    else
                        player:say(loot.symbol, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                    player:getPosition():sendMagicEffect(40)
                    local items = loot.itemid(t)
                    if loot.type_ == "loot" then
                        local id = items[1]
                        local name = ItemType(id):getName()
                        local amount = 1
                        if #items > 2 then
                            amount = math.random(items[2], items[3])
                        else
                            amount = items[2]
                        end
                        player:addItem(id, amount)
                        msg = "You've siphoned "..((amount == 1 and loot.type_ == "loot") and "" or amount).." "..name.." from the orb!"
                    elseif loot.type_ == "cash" then
                            local c, amount = giveMoney(items)
                            for k, v in pairs(c) do
                                player:addItem(v[1], v[2])
                            end
                            msg = "You've siphoned $"..comma_value(amount).. " gold from the orb!"
                    else
                        local comma = comma_value(items)
                        player:addExperience(items, false)
                        msg = "You siphoned "..comma.." experience from the orb!"
                    end
                    player:sendTextMessage(MESSAGE_INFO_DESCR, msg)
                else
                    if version == 860 then
                        -- uncomment to use in otx3 8.6
                        --Game.sendAnimatedText(loot.name, x, colors[math.random(#colors)])
                    else
                        player:say(loot.name, TALKTYPE_MONSTER_SAY, false, nil, x)
                    end
                end
            end
        end, i * ORB_INCREMENTS, p, 31, cid, tier
        )
    end
end
function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if killer:isPlayer() then
        local chance = 90
        local roll = math.random(100)
        killer:sendTextMessage(MESSAGE_INFO_DESCR, "you rolled a "..roll)
        if  chance > roll then
            local times = math.random(1, 3)
            for h = 1, times do
                sendOrbEffect(killer:getId(), 3)
            end
        end
    end
    return true
end

/Nixez
 
Solution
So what you are saying is the following
-After i added the file orbs.lua and registered it with the first line i already shew, am supposed to add this line to every monster that i want it to drop orbs instead of Normal LootingMethod
Code:
<script> <event name="orbs"/> </script>
Above line
With the monster file below
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<monster name="Giant Spider" nameDescription="a giant spider" race="venom" experience="900" speed="230" manacost="0">
    <health now="1300" max="1300" />
    <look type="38" corpse="5977" />
    <targetchange interval="4000" chance="10" />
    <flags>
        <flag summonable="0" />
        <flag attackable="1" />
        <flag hostile="1" />
        <flag illusionable="0"...
because it's either adding that and registering it that way or you go through all of your monster xml files and add this to each file
XML:
<script> <event name="orbs"/> </script>
 
because it's either adding that and registering it that way or you go through all of your monster xml files and add this to each file
XML:
<script> <event name="orbs"/> </script>

So what you are saying is the following
-After i added the file orbs.lua and registered it with the first line i already shew, am supposed to add this line to every monster that i want it to drop orbs instead of Normal LootingMethod
Code:
<script> <event name="orbs"/> </script>
Above line
With the monster file below
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<monster name="Giant Spider" nameDescription="a giant spider" race="venom" experience="900" speed="230" manacost="0">
    <health now="1300" max="1300" />
    <look type="38" corpse="5977" />
    <targetchange interval="4000" chance="10" />
    <flags>
        <flag summonable="0" />
        <flag attackable="1" />
        <flag hostile="1" />
        <flag illusionable="0" />
        <flag convinceable="0" />
        <flag pushable="0" />
        <flag canpushitems="1" />
        <flag canpushcreatures="1" />
        <flag targetdistance="1" />
        <flag staticattack="70" />
        <flag runonhealth="0" />
    </flags>
    <attacks>
        <attack name="melee" interval="2000" min="0" max="-300" poison="160" />
        <attack name="poisonfield" interval="2000" chance="10" range="7" radius="1" target="1">
            <attribute key="shootEffect" value="poison" />
        </attack>
        <attack name="earth" interval="2000" chance="10" range="7" radius="1" target="1" min="-40" max="-70">
            <attribute key="shootEffect" value="poison" />
        </attack>
    </attacks>
    <defenses armor="25" defense="25">
        <defense name="speed" interval="2000" chance="15" speedchange="390" duration="5000">
            <attribute key="areaEffect" value="redshimmer" />
        </defense>
    </defenses>
    <elements>
        <element energyPercent="20" />
        <element icePercent="20" />
        <element firePercent="-10" />
    </elements>
    <immunities>
        <immunity outfit="1" />
        <immunity drunk="1" />
        <immunity invisible="1" />
        <immunity earth="1" />
    </immunities>
    <summons maxSummons="2">
        <summon name="Poison Spider" interval="2000" chance="10" max="2" />
    </summons>
    <loot>
        <item name="gold coin" countmax="100" chance="50000" />
        <item name="gold coin" countmax="95" chance="50000" />
        <item id="2169" chance="710" /><!-- time ring -->
        <item name="platinum amulet" chance="280" />
        <item name="two handed sword" chance="5000" />
        <item name="steel helmet" chance="4545" />
        <item name="plate armor" chance="8333" />
        <item name="knight armor" chance="530" />
        <item name="knight legs" chance="870" />
        <item name="poison arrow" countmax="12" chance="12500" />
        <item name="plate legs" chance="8333" />
        <item name="spider silk" chance="2140" />
        <item name="strong health potion" chance="3571" />
        <item name="lightning headband" chance="220" />
    </loot>
</monster>

What would be The final Result ? If you ofc dont mind

/Nixez
 
So what you are saying is the following
-After i added the file orbs.lua and registered it with the first line i already shew, am supposed to add this line to every monster that i want it to drop orbs instead of Normal LootingMethod
Code:
<script> <event name="orbs"/> </script>
Above line
With the monster file below
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<monster name="Giant Spider" nameDescription="a giant spider" race="venom" experience="900" speed="230" manacost="0">
    <health now="1300" max="1300" />
    <look type="38" corpse="5977" />
    <targetchange interval="4000" chance="10" />
    <flags>
        <flag summonable="0" />
        <flag attackable="1" />
        <flag hostile="1" />
        <flag illusionable="0" />
        <flag convinceable="0" />
        <flag pushable="0" />
        <flag canpushitems="1" />
        <flag canpushcreatures="1" />
        <flag targetdistance="1" />
        <flag staticattack="70" />
        <flag runonhealth="0" />
    </flags>
    <attacks>
        <attack name="melee" interval="2000" min="0" max="-300" poison="160" />
        <attack name="poisonfield" interval="2000" chance="10" range="7" radius="1" target="1">
            <attribute key="shootEffect" value="poison" />
        </attack>
        <attack name="earth" interval="2000" chance="10" range="7" radius="1" target="1" min="-40" max="-70">
            <attribute key="shootEffect" value="poison" />
        </attack>
    </attacks>
    <defenses armor="25" defense="25">
        <defense name="speed" interval="2000" chance="15" speedchange="390" duration="5000">
            <attribute key="areaEffect" value="redshimmer" />
        </defense>
    </defenses>
    <elements>
        <element energyPercent="20" />
        <element icePercent="20" />
        <element firePercent="-10" />
    </elements>
    <immunities>
        <immunity outfit="1" />
        <immunity drunk="1" />
        <immunity invisible="1" />
        <immunity earth="1" />
    </immunities>
    <summons maxSummons="2">
        <summon name="Poison Spider" interval="2000" chance="10" max="2" />
    </summons>
    <loot>
        <item name="gold coin" countmax="100" chance="50000" />
        <item name="gold coin" countmax="95" chance="50000" />
        <item id="2169" chance="710" /><!-- time ring -->
        <item name="platinum amulet" chance="280" />
        <item name="two handed sword" chance="5000" />
        <item name="steel helmet" chance="4545" />
        <item name="plate armor" chance="8333" />
        <item name="knight armor" chance="530" />
        <item name="knight legs" chance="870" />
        <item name="poison arrow" countmax="12" chance="12500" />
        <item name="plate legs" chance="8333" />
        <item name="spider silk" chance="2140" />
        <item name="strong health potion" chance="3571" />
        <item name="lightning headband" chance="220" />
    </loot>
</monster>

What would be The final Result ? If you ofc dont mind

/Nixez
that's exactly what i'm saying
you can put it above the <health> tag
btw if you do this unregister it from login.lua because that would register the event to the player and will execute when that player dies which shouldn't happen
 
Solution
Back
Top