• 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,150
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...
DGV7uKP.png


Code:
function onStepIn(cid, item, position, fromPosition)

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

    if player:getHouse(getPlayerGUID(cid)) then
        doTeleportThing(cid, getHouseEntry(player:getHouse(getPlayerGUID(cid))).entry)
        doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
        return true
    end


    if player:getHouse(getPlayerGUID(cid)) ~= nil then
        player:teleportTo(fromPosition, false)
    end
    return true
end
 
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
 
Code:
function onStepIn(cid, item, position, fromPosition)
    local monster = Monster(cid)
    if not monster or monster:getName():lower() ~= 'wolf' then
        return true
    end

    monster:remove()
    position:sendMagicEffect(CONST_ME_POFF)
    Item(item.uid):transform(13633)
    return true
end
 
Is it possible to make it come back after 5 minutes? Right now it captures the wolf and the trap disappears. I need the trap to reappear again after 5 minutes ;)
 
Code:
local function revertItem(position, itemId, transformId)
    local item = Tile(position):getItemById(itemId)
    if item then
        item:transform(transformId)
    end
end

addEvent(revertItem, 5 * 60 * 1000, position, 13633, 13632)
 
nLjnuWM.png


PHP:
function onStepIn(cid, item, position, fromPosition)
    local monster = Monster(cid)
    if not monster or monster:getName():lower() ~= 'wolf' then
        return true
    end

    monster:remove()
    position:sendMagicEffect(CONST_ME_POFF)
    Item(item.uid):transform(13633)
    addEvent(revertItem, 1 * 1 * 1000, position, 13633, 13632)
    return true
end
 
you have to put
Code:
local function revertItem(position, itemId, transformId)
local item = Tile(position):getItemById(itemId)
if item then
item:transform(transformId)
end
end

inside your onstepin script, as it is a local function, or erase the "local" infront of the function whereever you put it :p
 
I want the summon to give exp:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Sight of Annihilation" nameDescription="total annihilation" race="undead" experience="0" speed="0" manacost="0">
    <health now="9950" max="9950"/>
    <look typeex="6972"/>
    <targetchange interval="5000" chance="20"/>
    <flags>
        <flag summonable="0"/>
        <flag attackable="0"/>
        <flag hostile="1"/>
        <flag illusionable="0"/>
        <flag convinceable="0"/>
        <flag pushable="0"/>
        <flag canpushitems="0"/>
        <flag canpushcreatures="1"/>
        <flag targetdistance="1"/>
        <flag staticattack="90"/>
        <flag runonhealth="100"/>
        <flag hidehealth="0"/>
    </flags>
    <immunities>
        <immunity physical="1"/>
        <immunity energy="1"/>
        <immunity fire="1"/>
        <immunity poison="1"/>
        <immunity ice="1"/>
        <immunity holy="1"/>
        <immunity death="1"/>
        <immunity lifedrain="1"/>
        <immunity manadrain="1"/>
        <immunity paralyze="1"/>
        <immunity drunk="1"/>
        <immunity outfit="1"/>
        <immunity invisible="1"/>
    </immunities>
    <summons maxSummons="1">
        <summon name="demon" interval="2000" chance="1"/>
    </summons>
</monster>
 
I want the summon to give exp:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Sight of Annihilation" nameDescription="total annihilation" race="undead" experience="0" speed="0" manacost="0">
    <health now="9950" max="9950"/>
    <look typeex="6972"/>
    <targetchange interval="5000" chance="20"/>
    <flags>
        <flag summonable="0"/>
        <flag attackable="0"/>
        <flag hostile="1"/>
        <flag illusionable="0"/>
        <flag convinceable="0"/>
        <flag pushable="0"/>
        <flag canpushitems="0"/>
        <flag canpushcreatures="1"/>
        <flag targetdistance="1"/>
        <flag staticattack="90"/>
        <flag runonhealth="100"/>
        <flag hidehealth="0"/>
    </flags>
    <immunities>
        <immunity physical="1"/>
        <immunity energy="1"/>
        <immunity fire="1"/>
        <immunity poison="1"/>
        <immunity ice="1"/>
        <immunity holy="1"/>
        <immunity death="1"/>
        <immunity lifedrain="1"/>
        <immunity manadrain="1"/>
        <immunity paralyze="1"/>
        <immunity drunk="1"/>
        <immunity outfit="1"/>
        <immunity invisible="1"/>
    </immunities>
    <summons maxSummons="1">
        <summon name="demon" interval="2000" chance="1"/>
    </summons>
</monster>

u can do it with creatureevents :)
 
Starting this thread back up, and now I'm wondering if it's possible to make a weapon that can only be used by X level or lower.
Code:
<distance id="19390" breakchance="3" /> <!-- beginner spear -->
Code:
    <item id="19390" article="a" name="beginner spear">
        <attribute key="description" value="Weighs much less than a normal spear but does less damage and it can only be wielded properly by players of level 30 or lower." />
        <attribute key="weight" value="500" />
        <attribute key="attack" value="23" />
        <attribute key="weaponType" value="distance" />
        <attribute key="shootType" value="spear" />
        <attribute key="maxHitChance" value="74" />
        <attribute key="range" value="3" />
    </item>
 
Last edited:
If its a spear put in weapons.xml
XML:
    <distance id="19390" breakchance="6" unproperly="1" script="beginnerspear.lua" />
then in beginnerspear.lua put
Lua:
function onUseWeapon(cid, var)
    local level = 20
    if cid:getLevel() > level then
        return false
    end
    return true
end
 
why not just
Code:
level ="20"
He wants to make it properly for levels lower than 30. Level attribute sets it for lvl 30+.

If its a spear put in weapons.xml
XML:
    <distance id="19390" breakchance="6" unproperly="1" script="beginnerspear.lua" />
then in beginnerspear.lua put
Lua:
function onUseWeapon(cid, var)
    local level = 20
    if cid:getLevel() > level then
        return false
    end
    return true
end
You have to return combat and add combat parameters. It won't work like this.
 
PHP:
addEvent(player:teleportTo({x = 2071, y = 2186, z = 7}), 5000)
Is it possible to do something like this? Basically I want this NPC to say stuff and then teleport the player to X position after 5 seconds. Maybe I'm overthinking this.

Nevermind, fixed it;
PHP:
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

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
   
-- Deserted Island Quest

local player = Player(cid)

local function teleportPlayer()
        player:teleportTo({x = 2071, y = 2186, z = 7})
    end


    if msgcontains(msg, "sizaro") then
        if player:getStorageValue(57002) ~= 1 then
            npcHandler:say({
                    "Wait a second ... you\'re a ... you\'re not Sizaro!!! ...",
                    "Wait! This is perfect! Now you're stuck here with me! Now we can play!. ...",
                    "So what do you wanna do first? Wanna go play with Alice? Alice is my cat, shes adorable! Actually let's pick flowers together! YES! ...",
                    "But first, you have to bring me something ... hmm ... bring me a ... a {doll}! GO!"
                }, cid)
            player:setStorageValue(57002, 1)
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, "doll") then
        if player:getStorageValue(57002) == 1 then
            npcHandler:say("Do you have the doll?", cid)
            npcHandler.topic[cid] = 1
        end
    elseif msgcontains(msg, "yes") then 
        if npcHandler.topic[cid] == 1 then
            if player:removeItem(12666, 1) then
                npcHandler:say("*Hugs the doll* ... Now, do you wanna play with me? Wait! I almost forgot, take this, you might need it in the future, who knows.", cid)
                player:setStorageValue(57002, 2)
                player:addItem(12508, 1)
            else
                npcHandler:say({
                "*She inspects your backpack violently.*",
                "You don't actually have it do you? ... Go away!"
                }, cid)
                addEvent(teleportPlayer, 8000)
                npcHandler.topic[cid] = 0
            end
        end
    elseif msgcontains(msg, "doll") then
        if player:getStorageValue(57002) >= 2 then
            npcHandler:say("Do you wanna play with me now?", cid)
        end
    end
end

   
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top