• 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 Wedding / Marriage Script refit with more RPG features

Anghelos

Member
Joined
Nov 1, 2014
Messages
30
Reaction score
10
Hi all :) as I wrote days ago i wanted to redo the script that i found here:
http://otland.net/threads/tfs-1-0-marriage-system.206206/ coz it was lacking some stuff, so basically i added the following stuff:
1) Wedding Outfits when u give the wedding outfit box
2) Instead of a common priest, I used Lynda (priest of thais)
3) I used the common rite words for the celebration, they can be heard by all the attendant to the marriage, to make it more roleplay (u can adjust the delay of the sentences)
4) When both of the players accepted to be married, u can celebrate when all ur friends (or ur soulmate) is online and in the 'church'.

I give the script to the admin of server where I play (i'm just a player, but also a programmer :D) but i decided to share with u, also to have feedback, coz since it's my first script might be buggy, I tested in local and also in the main server, but u know...the more we are... :)
Installation:

DB Side - SQL Query:
Code:
ALTER TABLE `players` ADD `marriage_status` tinyint(1) NOT NULL DEFAULT 0, ADD `marriage_spouse` int(11) NOT NULL DEFAULT -1

Server Side - global.lua:
Code:
PROPOSED_STATUS = 1
MARRIED_STATUS = 2
PROPACCEPT_STATUS = 3
LOOK_MARRIAGE_DESCR = TRUE
ITEM_WEDDING_RING = 2121
ITEM_ENGRAVED_WEDDING_RING = 10502

function getPlayerSpouse(id)
    local resultQuery = db.storeQuery("SELECT `marriage_spouse` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_spouse")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerSpouse(id, val)
    db.query("UPDATE `players` SET `marriage_spouse` = " .. val .. " WHERE `id` = " .. id)
end

function getPlayerMarriageStatus(id)
    local resultQuery = db.storeQuery("SELECT `marriage_status` FROM `players` WHERE `id` = " .. db.escapeString(id))
    if resultQuery ~= false then
        local ret = result.getDataInt(resultQuery, "marriage_status")
        result.free(resultQuery)
        return ret
    end
    return -1
end

function setPlayerMarriageStatus(id, val)
    db.query("UPDATE `players` SET `marriage_status` = " .. val .. " WHERE `id` = " .. id)
end

function Player:getMarriageDescription(thing)
    local descr = ""
    if getPlayerMarriageStatus(thing:getGuid()) == MARRIED_STATUS then
        playerSpouse = getPlayerSpouse(thing:getGuid())
        if self == thing then
            descr = descr .. " You are "
        elseif thing:getSex() == PLAYERSEX_FEMALE then
            descr = descr .. " She is "
        else
            descr = descr .. " He is "
        end
        descr = descr .. "married to " .. getPlayerNameById(playerSpouse) .. '.'
    end
    return descr
end

-- The following 2 functions can be used for delayed shouted text

function say(param)
selfSay(text)
doCreatureSay(param.cid, param.text, 1)
end

function delayedSay(text, delay)
local delay = delay or 0
local cid = getNpcCid()
addEvent(say, delay, {cid = cid, text = text})
end

Server Side - compat.lua:
Code:
function getPlayerNameById(id)
local resultName = db.storeQuery("SELECT `name` FROM `players` WHERE `id` = " .. db.escapeString(id))
if resultName ~= false then
local name = result.getDataString(resultName, "name")
result.free(resultName)
return name
end
return 0
end

Server Side - On events/scripts/player.lua, add the following piece of code after the local description variable is initialized in the method Player: onLook.

Code:
if LOOK_MARRIAGE_DESCR and thing:isCreature() then
if thing:isPlayer() then
description = description .. self:getMarriageDescription(thing)
end
end

end of part 1.
 
Part 2.

And finally, lynda.lua under npc/scripts

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

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "angelina") then
        if player:getStorageValue(Storage.OutfitQuest.MageSummonerWandAddon) == 1 then
            npcHandler:say({
                "Angelina had been imprisoned? My, these are horrible news, but I am so glad to hear that she is safe now. ...",
                "I will happily carry out her wish and reward you, but I fear I need some important ingredients for my blessing spell first. ...",
                "Will you gather them for me?"
            }, cid)
            npcHandler.topic[cid] = 1
        end
    elseif msgcontains(msg, "wand") or msgcontains(msg, "rod") then
        if player:getStorageValue(Storage.OutfitQuest.MageSummonerWandAddon) == 2 then
            npcHandler:say("Did you bring a sample of each wand and each rod with you?", cid)
            npcHandler.topic[cid] = 3
        end
    elseif msgcontains(msg, "sulphur") then
        if player:getStorageValue(Storage.OutfitQuest.MageSummonerWandAddon) == 3 then
            npcHandler:say("Did you obtain 10 ounces of magic sulphur?", cid)
            npcHandler.topic[cid] = 4
        end
    elseif msgcontains(msg, "soul stone") then
        if player:getStorageValue(Storage.OutfitQuest.MageSummonerWandAddon) == 4 then
            npcHandler:say("Were you actually able to retrieve the Necromancer's soul stone?", cid)
            npcHandler.topic[cid] = 5
        end
    elseif msgcontains(msg, "ankh") then
        if player:getStorageValue(Storage.OutfitQuest.MageSummonerWandAddon) == 5 then
            npcHandler:say("Am I sensing enough holy energy from ankhs here?", cid)
            npcHandler.topic[cid] = 6
        end
    elseif msgcontains(msg, "yes") then
        if npcHandler.topic[cid] == 1 then
            npcHandler:say({
                "Thank you, I promise that your efforts won't be in vain! Listen closely now: First, I need a sample of five druid rods and five sorcerer wands. ...",
                "I need a snakebite rod, a moonlight rod, a necrotic rod, a terra rod and a hailstorm rod. Then, I need a wand of vortex, a wand of dragonbreath ...",
                "... a wand of decay, a wand of cosmic energy and a wand of inferno. Please bring them all at once so that their energy will be balanced. ...",
                "Secondly, I need 10 ounces of magic sulphur. It can absorb the elemental energy of all the wands and rods and bind it to something else. ...",
                "Next, I will need a soul stone. These can be used as a vessel for energy, evil as well as good. They are rarely used nowaday though. ...",
                "Lastly, I need a lot of holy energy. I can extract it from ankhs, but only a small amount each time. I will need about 20 ankhs. ...",
                "Did you understand everything I told you and will help me with my blessing?"
            }, cid)
            npcHandler.topic[cid] = 2
        elseif npcHandler.topic[cid] == 2 then
            npcHandler:say("Alright then. Come back to with a sample of all five wands and five rods, please.", cid)
            player:setStorageValue(Storage.OutfitQuest.MageSummonerWandAddon, 2)
            npcHandler.topic[cid] = 0
        elseif npcHandler.topic[cid] == 3 then
            if  player:getItemCount(2181) > 0 and player:getItemCount(2182) > 0 and player:getItemCount(2183) > 0 and player:getItemCount(2185) > 0 and player:getItemCount(2186) > 0 and player:getItemCount(2187) > 0 and player:getItemCount(2188) > 0 and player:getItemCount(2189) > 0 and player:getItemCount(2190) > 0 and player:getItemCount(2191) > 0 then
                npcHandler:say("Thank you, that must have been a lot to carry. Now, please bring me 10 ounces of magic sulphur.", cid)
                player:removeItem(2181, 1)
                player:removeItem(2182, 1)
                player:removeItem(2183, 1)
                player:removeItem(2185, 1)
                player:removeItem(2186, 1)
                player:removeItem(2187, 1)
                player:removeItem(2188, 1)
                player:removeItem(2189, 1)
                player:removeItem(2190, 1)
                player:removeItem(2191, 1)
                player:setStorageValue(Storage.OutfitQuest.MageSummonerWandAddon, 3)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 4 then
            if player:getItemCount(5904) >= 10 then
                npcHandler:say("Very good. I will immediately start to prepare the ritual and extract the elemental energy from the wands and rods. Please bring me the Necromancer's soul stone now.", cid)
                player:removeItem(5904, 10)
                player:setStorageValue(Storage.OutfitQuest.MageSummonerWandAddon, 4)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 5 then
            if player:getItemCount(5809) > 0 then
                npcHandler:say("You have found a rarity there, " .. player:getName() .. ". This will become the tip of your blessed wand. Please bring me 20 ankhs now to complete the ritual.", cid)
                player:removeItem(5809, 1)
                player:setStorageValue(Storage.OutfitQuest.MageSummonerWandAddon, 5)
                npcHandler.topic[cid] = 0
            end
        elseif npcHandler.topic[cid] == 6 then
            if player:getItemCount(2193) >= 20 then
                npcHandler:say("The ingredients for the ritual are complete! I will start to prepare your blessed wand,... I'm glad to tell you that I have finished the ritual, " .. player:getName() .. ". Here is your new wand. I hope you carry it proudly for everyone to see.", cid)
                player:removeItem(2193, 20)
                player:setStorageValue(Storage.OutfitQuest.MageSummonerWandAddon, 6)
                player:addOutfitAddon(141, 1)
                player:addOutfitAddon(130, 1)
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                npcHandler.topic[cid] = 0
            end
        end
    elseif msgcontains(msg, "wedding") or msgcontains(msg, "marriage") then
        local playerStatus = getPlayerMarriageStatus(player:getGuid())
        local playerSpouse = getPlayerSpouse(player:getGuid())
        if (playerStatus == MARRIED_STATUS) then
            msg = msg .. ' I see that you are a happily married ' .. ((player:getSex() == PLAYERSEX_FEMALE) and 'woman' or 'man') .. '. What brings you here? Looking for a {divorce}?'
        elseif (playerStatus == PROPOSED_STATUS) then
            msg = msg .. ' You are still waiting for the wedding proposal you made to {' .. (getPlayerNameById(playerSpouse)) .. '}. Would you like to {remove} it?'
        else
            msg = msg .. ' So this is a good news! You want to {marry} someone?'
        end
        npcHandler:say(msg,cid)
        --selfSay(msg,cid)
        npcHandler:addFocus(cid)
        return false
    end
    return true
end
End of part 2.
 
Part 3.

Code:
local function tryEngage(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local player = Player(cid)
   
    local playerStatus = getPlayerMarriageStatus(player:getGuid())
    local playerSpouse = getPlayerSpouse(player:getGuid())
    if playerStatus == MARRIED_STATUS then -- check if the player is already married
        npcHandler:say('You are already married to {' .. getPlayerNameById(playerSpouse) .. '}.', cid)
    elseif playerStatus == PROPOSED_STATUS then --check if the player already made a proposal to some1 else
        npcHandler:say('You already made a wedding proposal to {' .. getPlayerNameById(playerSpouse) .. '}. You can always remove the proposal by saying {remove} proposal.', cid)
    else
        local candidate = getPlayerGUIDByName(message)
        if candidate == 0 then -- check if there is actually a player called like this
            npcHandler:say('A player with this name does not exist.', cid)
        elseif candidate == player:getGuid() then -- if it's himself, cannot marry
            npcHandler:say('You REALLY want to marry yourself? c\'mon, be serious.', cid)
        else
            if player:getItemCount(ITEM_WEDDING_RING) == 0 or player:getItemCount(10503) == 0 then -- check for items (wedding ring and outfit box)
                npcHandler:say('As I said, you need a wedding ring and the wedding outfit box in order to marry.', cid)
            else
                local candidateStatus = getPlayerMarriageStatus(candidate)
                local candidateSpouse = getPlayerSpouse(candidate)
                if candidateStatus == MARRIED_STATUS then -- if the player you want to marry is already married and to whom
                    npcHandler:say('{' .. getPlayerNameById(candidate) .. '} is already married to {' .. getPlayerNameById(candidateSpouse) .. '}.', cid)
        elseif candidateStatus == PROPACCEPT_STATUS then -- if the player you want to marry is already going to marry some1 else
                    npcHandler:say('{' .. getPlayerNameById(candidate) .. '} is already engaged to {' .. getPlayerNameById(candidateSpouse) .. '} and they will going to marry soon.', cid)
        elseif candidateStatus == PROPOSED_STATUS then -- if he/she already made a proposal to some1
                    if candidateSpouse == player:getGuid() then -- if this someone is you.
            npcHandler:say('Since both of you are willing to marry, I accept to celebrate your marriage, go prepare yourself, and tell me when you are ready for the {celebration}',cid)
                        player:removeItem(ITEM_WEDDING_RING,1)
                        player:removeItem(10503,1) -- wedding outfit box
            player:addOutfit(329) --Wife
            player:addOutfit(328) --Husb
                        setPlayerMarriageStatus(player:getGuid(), PROPACCEPT_STATUS)
                        setPlayerMarriageStatus(candidate, PROPACCEPT_STATUS)
            setPlayerSpouse(player:getGuid(), candidate)
            local player = Player(getPlayerNameById(candidate))
            player:addOutfit(329)
            player:addOutfit(328)
           else -- if this some1 is not you
                        npcHandler:say('{' .. getPlayerNameById(candidate) .. '} already made a wedding proposal to {' .. getPlayerNameById(candidateSpouse) .. '}.', cid)
                    end
                else -- if the player i want to propose doesn't have other proposal
                    npcHandler:say('Ok, now let\'s wait and see if {' ..  getPlayerNameById(candidate) .. '} accepts your proposal. I\'ll give you back your wedding ring as soon as {' ..  getPlayerNameById(candidate) .. '} accepts your proposal or you {remove} it.', cid)
                    player:removeItem(ITEM_WEDDING_RING,1)
                    player:removeItem(10503,1)
                    setPlayerMarriageStatus(player:getGuid(), PROPOSED_STATUS)
                    setPlayerSpouse(player:getGuid(), candidate)
                end
            end
        end
    end
    keywordHandler:moveUp(1)
    return false
end

local function confirmWedding(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local player = Player(cid)
    local playerStatus = getPlayerMarriageStatus(player:getGuid())
    local candidate = getPlayerSpouse(player:getGuid())
    if playerStatus == PROPACCEPT_STATUS then
        local item3 = Item(doPlayerAddItem(cid,ITEM_Meluna_Ticket,2))
        setPlayerMarriageStatus(player:getGuid(), MARRIED_STATUS)
        setPlayerMarriageStatus(candidate, MARRIED_STATUS)
        setPlayerSpouse(player:getGuid(), candidate)
        setPlayerSpouse(candidate, player:getGuid())
        delayedSay('Dear friends and family, we are gathered here today to witness and celebrate the union of ' .. getPlayerNameById(candidate) .. ' and ' .. player:getName() .. ' in marriage.')
        delayedSay('Through their time together, they have come to realize that their personal dreams, hopes, and goals are more attainable and more meaningful through the combined effort and mutual support provided in love, commitment, and family;',5000)
        delayedSay('and so they have decided to live together as husband and wife. And now, by the power vested in me by the Gods of Tibia, I hereby pronounce you husband and wife.',15000)
        delayedSay('*After a whispered blessing opens an hand towards ' .. player:getName() .. '* Take these two engraved wedding rings and give one of them to your spouse.',22000)
        delayedSay('You may now kiss your bride.',28000)
        local item1 = Item(doPlayerAddItem(cid,ITEM_ENGRAVED_WEDDING_RING,1))
        local item2 = Item(doPlayerAddItem(cid,ITEM_ENGRAVED_WEDDING_RING,1))
        item1:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, player:getName() .. ' & ' .. getPlayerNameById(candidate) .. ' forever - married on ' .. os.date('%B %d, %Y.'))
        item2:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, player:getName() .. ' & ' .. getPlayerNameById(candidate) .. ' forever - married on ' .. os.date('%B %d, %Y.'))
    else
        npcHandler:say('Your partner didn\'t accept your proposal, yet', cid)
    end
    return true
end

End of part 3.
 
Part 4.

Code:
local function confirmRemoveEngage(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local player = Player(cid)
    local playerStatus = getPlayerMarriageStatus(player:getGuid())
    local playerSpouse = getPlayerSpouse(player:getGuid())
    if playerStatus == PROPOSED_STATUS then
        npcHandler:say('Are you sure you want to remove your wedding proposal with {' .. getPlayerNameById(playerSpouse) .. '}?', cid)
        node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 3, text = 'Ok, let\'s keep it then.'})
       
        local function removeEngage(cid, message, keywords, parameters, node)
            doPlayerAddItem(cid,ITEM_WEDDING_RING,1)
       doPlayerAddItem(cid,10503,1)
            setPlayerMarriageStatus(player:getGuid(), 0)
            setPlayerSpouse(player:getGuid(), -1)
            npcHandler:say(parameters.text, cid)
            keywordHandler:moveUp(parameters.moveup)
        end
        node:addChildKeyword({'yes'}, removeEngage, {moveup = 3, text = 'Ok, your marriage proposal to {' .. getPlayerNameById(playerSpouse) .. '} has been removed. Take your wedding ring back.'})
    else
        npcHandler:say('You don\'t have any pending proposal to be removed.', cid)
        keywordHandler:moveUp(2)
    end
    return true
end

local function confirmDivorce(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
    local player = Player(cid)
    local playerStatus = getPlayerMarriageStatus(player:getGuid())
    local playerSpouse = getPlayerSpouse(player:getGuid())
    if playerStatus == MARRIED_STATUS then
        npcHandler:say('Are you sure you want to divorce of {' .. getPlayerNameById(playerSpouse) .. '}?', cid)
        node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 3, text = 'Great! Marriages should be an eternal commitment.'})
       
        local function divorce(cid, message, keywords, parameters, node)
            local player = Player(cid)
            local spouse = getPlayerSpouse(player:getGuid())
            setPlayerMarriageStatus(player:getGuid(), 0)
            setPlayerSpouse(player:getGuid(), -1)
            setPlayerMarriageStatus(spouse, 0)
            setPlayerSpouse(spouse, -1)
            npcHandler:say(parameters.text, cid)
            keywordHandler:moveUp(parameters.moveup)
        end
        node:addChildKeyword({'yes'}, divorce, {moveup = 3, text = 'Ok, you are now divorced of {' .. getPlayerNameById(playerSpouse) .. '}. Think better next time after marrying someone.'})
    else
        npcHandler:say('You aren\'t married to get a divorce.', cid)
        keywordHandler:moveUp(2)
    end
    return true
end

local node1 = keywordHandler:addKeyword({'marry'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to get married? Make sure you have a wedding ring and the wedding outfit box with you.'})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'That\'s fine.'})
local node2 = node1:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'And who would you like to marry?'})
node2:addChildKeyword({'[%w]'}, tryEngage, {})

local node3 = keywordHandler:addKeyword({'celebration'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Is your soulmate and friends here with you for the celebration?.'})
node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Then go bring them here!.'})
local node4 = node3:addChildKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Good, let\'s {begin} then!.'}) --, confirmWedding, {})
node4:addChildKeyword({'begin'}, confirmWedding, {})


keywordHandler:addKeyword({'remove'}, confirmRemoveEngage, {})

keywordHandler:addKeyword({'divorce'}, confirmDivorce, {})

--keywordHandler:addKeyword({'celebration'}, confirmwedding,{})

npcHandler:setMessage(MESSAGE_GREET, "Welcome in the name of the gods, pilgrim |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Be careful on your journeys.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Be careful on your journeys.")

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Uff, this forum is terrible =/ splitted in 4, pls mind that all this big thingie (from part 2 to here) goes all in the same lynda.lua script!
I want to thank Chris and the Main Creator of this script Godely. Thanks and enjoy :)
 
Very thanks man and sorry for up thread, but theres an error when player try to marry when the other is offline
Any fix? ^^

@Anghelos
 
Yes, but the other just down conection per example it will error and they can't marry again and no divorce, i tested

;s
 
Back
Top