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

[LUA] & possibly [C++] requests - Sizaro

Sizaro

Advanced OT User
Joined
Aug 20, 2007
Messages
5,151
Solutions
5
Reaction score
209
Location
Sweden
GitHub
coldensjo
So I've been playing around with a new server of mine for a while now and I need a few things, thought I'd request them.

(If you have a better idea that works the same way please let me know)

[DONE] #1: onLogin add outfit (once) based on gender and vocation.
Thanks Ninja
Heres the code:

data\creaturescripts\Actions.xml
Code:
    <event type="login" name="FirstOutfit" script="firstoutfit.lua"/>

data\creaturescripts\scripts\firstoutfit.lua
Code:
local config = {
[1] = {female = 575, male = 574},
[2] = {female = 269, male = 268},
[3] = {female = 142, male = 134},
[4] = {female = 138, male = 130},
[5] = {female = 148, male = 144},
[6] = {female = 137, male = 129}
}

function onLogin(cid)
local player = Player(cid)
local targetVocation = config[player:getVocation():getBase():getId()]
if not targetVocation then
return true
end

if player:hasOutfit(player:getSex() == 0 and targetVocation.female or targetVocation.male) then
return true
end

player:addOutfit(targetVocation.female)
player:addOutfit(targetVocation.male)
return true
end

\data\global or compat.lua
bottom add:

Code:
add this to your global/compat.lua, credits goes to dalkon
function Vocation.getBase(self)
local demotion = self:getDemotion()
while demotion do
local tmp = demotion:getDemotion()
if not tmp then
return demotion
end
demotion = tmp
end
return self
end



[DONE] #2: Dual-Wielding daggers (Swords)

Thanks hakeee

IHgvn3a.png


[DONE] #3: Teleport to house exit function StepIn.
Thanks Ninja
Heres the code:

data\movements\movements.xml
Code:
<movevent event="StepIn" actionid="x" script="houseTeleport.lua" />

data\movements\scripts\houseTeleport.lua
Code:
function onStepIn(cid, item, position, fromPosition)
local player = Player(cid)
if not player then
return true
end

local house = player:getHouse()
if not house then
player:teleportTo(fromPosition, true)
fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
return true
end

player:teleportTo(house:getExitPosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
return true
end

[DONE] #3: Summons following you
XML:
<talkaction words="utevo res" separator=" " script="summonmonster.lua" />
Lua:
local summonables = {
    'Rat',
    'Bat',
    'Cat'
}
local sum = {}
for _, mon in pairs(summonables) do -- LOWERCASE ALL MONSTER NAMES FOR COMPARISON WITH PARAMETER
    table.insert(sum,mon:lower())
end
function onSay(player, words, param)
    local name = param:match('%a+')
    if not name then
        player:sendCancelMessage('Invalid parameters.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if #player:getSummons() > 1 then
        player:sendCancelMessage('You cannot summon any more creatures.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if not isInArray(sum,name:lower()) then
        player:sendCancelMessage('You cannot summon this monster.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    local monster = Game.createMonster(name, player:getPosition())
    if not monster then
        player:sendCancelMessage('There is not enough room.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    monster:setMaster(player)
    monster:registerEvent('summonfollow')
    return false
end
and then in creaturescripts.xml
XML:
<event type="think" name="summonfollow" script="summonfollow.lua" />
and in summonfollow.lua
Lua:
function onThink(cid, interval)
    local cpos = cid:getPosition()
    local ppos = cid:getMaster():getPosition()
    if cpos.z ~= ppos.z or math.abs(cpos.x - ppos.x) > 8 or math.abs(cpos.y - ppos.y) > 6 then
        cid:teleportTo(ppos)
    end
    return true
end
don't forget to remove utevo res from spells.xml
 
Last edited:
Solution
It's probably best done in source code but I reckon you could handle all that in LUA
Ok so, if you handle utevo res as a talk action like this
XML:
<talkaction words="utevo res" separator=" " script="summonmonster.lua" />
Lua:
local summonables = {
    'Rat',
    'Bat',
    'Cat'
}
local sum = {}
for _, mon in pairs(summonables) do -- LOWERCASE ALL MONSTER NAMES FOR COMPARISON WITH PARAMETER
    table.insert(sum,mon:lower())
end
function onSay(player, words, param)
    local name = param:match('%a+')
    if not name then
        player:sendCancelMessage('Invalid parameters.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if #player:getSummons() > 1 then
        player:sendCancelMessage('You...
1.
Code:
local config = {
    [1] = {female = 575, male = 574},
    [2] = {female = 269, male = 268},
    [3] = {female = 142, male = 134},
    [4] = {female = 138, male = 130},
    [5] = {female = 148, male = 144},
    [6] = {female = 137, male = 129}
}

--[[ add this to your global/compat.lua, credits goes to dalkon
function Vocation.getBase(self)
    local demotion = self:getDemotion()
    while demotion do
        local tmp = demotion:getDemotion()
        if not tmp then
            return demotion
        end
        demotion = tmp
    end
    return self
end
]]

function onLogin(cid)
    local player = Player(cid)
    local targetVocation = config[player:getVocation():getBase():getId()]
    if not targetVocation then
        return true
    end

    if player:hasOutfit(player:getSex() == 0 and targetVocation.female or targetVocation.male) then
        return true
    end

    player:addOutfit(targetVocation.female)
    player:addOutfit(targetVocation.male)
    return true
end
 
Welcome to the club.

Anyone got the 10.50 monsters?

For example, Moohtant, Minotaur Amazon and Minotaur Hunter?

Heres a big idea of mine, maybe it's too much to ask but.

if actionid = x then decay tree (first stage) to tree (second stage) after 45-60 minutes
upon decaying once (second stage), grow 1 fruit around tree randomly placed 1 sq around tree (if bush = ontop) and decay to next stage after 45-60 minutes
upon decaying twice (third stage), grow (1-2) fruits around tree randomly placed 1 sq around tree (if bush = ontop) then decay to next stage (dead tree) after 45-60 min
upon decaying 4 times (fourth stage) grow (1-3) fruit around tree randomly placed 1 sq around tree or bush and decay back to tree (first stage) after 45-60 min
upon decaying back to first stage, remove all fruits within 1 sq

Decay should happen once every 45 - 60 minutes so a tree will go back to normal after 180-240 minutes of irl time.

A simple start would be to make just a tomato bush like shown in my example.

examples:
tDuO5Qx.png


Is it possible to doSendMagicEffect(frompos, topos, x) ?
(Using this as a support thread xD)
 
Last edited by a moderator:
Elaborate

PHP:
local pos = getPlayerPosition(cid)
local positions = {
    {x=pos.x+1,y=pos.y-1,z=pos.z},
    {x=pos.x-1,y=pos.y-1,z=pos.z},
}
    for i = 1, #positions do
        doSendMagicEffect(positions[i], 30)
        break
    end

play w it
ps. i dont know how to post lua codes
 
9ZeEutD.png


houseTeleport.lua
Code:
function onStepIn(cid, item, position, fromPosition)

    local playerPos = getCreaturePosition(cid)
    local player = Player(cid)

    if getHouseByPlayerGUID(getPlayerGUID(cid)) then
        doTeleportThing(cid, getHouseInfo(getHouseByPlayerGUID(getPlayerGUID(cid))).entry)
        doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
        return true
    end


    if getHouseByPlayerGUID(getPlayerGUID(cid)) ~= nil then
        player:teleportTo(fromPosition, false)
    end
    return true
end
 
9ZeEutD.png


houseTeleport.lua
Code:
function onStepIn(cid, item, position, fromPosition)

    local playerPos = getCreaturePosition(cid)
    local player = Player(cid)

    if getHouseByPlayerGUID(getPlayerGUID(cid)) then
        doTeleportThing(cid, getHouseInfo(getHouseByPlayerGUID(getPlayerGUID(cid))).entry)
        doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
        return true
    end


    if getHouseByPlayerGUID(getPlayerGUID(cid)) ~= nil then
        player:teleportTo(fromPosition, false)
    end
    return true
end

try with player:getHouse()
ps. https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp
 
Back
Top