• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Marriage Script for TFS 0.3.6 Working

Forsaken13126

Scripter
Joined
Feb 4, 2010
Messages
224
Reaction score
3
Location
New York
All credits go to Godely i just fixed it up and make it workable for 0.3.6

First, Go to data/npc and make a new xml file called priest.xml and add this in there:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Priest" script="wedding.lua" walkinterval="2000" floorchange="0">
	<health now="800" max="800"/>
	<look type="57" head="20" body="30" legs="40" feet="50"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|, Would you like to get married?"/>
	</parameters>
</npc>

Second open up data/npc/scripts and make a new lua file and name it wedding.lua and add this into that:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if msgcontains(msg, 'marry') or msgcontains(msg, 'marriage') then
		if getPlayerStorageValue(cid,3066) == -1 then
			selfSay('Would you like to marry?', cid)
			talkState[talkUser] = 1
		elseif getPlayerStorageValue(cid,3066) == 1 then
			local fid = getPlayerGUID(cid)
			local marrystatus = getOwnMarryStatus(fid)
			if marrystatus ~= 0 then
				local newpartner = getPlayerNameByGUID(marrystatus)
				selfSay('Have you ever set a wedding date with{' .. newpartner .. '}, now I need to talk to your partner. you want{cancel}?', cid)
				talkState[talkUser] = 5
			else
				setPlayerStorageValue(cid,3066,-1)
				selfSay('Would you like to marry?', cid)
				talkState[talkUser] = 1
			end
		elseif getPlayerStorageValue(cid,3066) == 2 then
			selfSay('You are already married. If you want{divorce}, suffice it to say.', cid)
			talkState[talkUser] = 0
		end

	elseif msgcontains(msg, 'divorce') then
		if getPlayerStorageValue(cid,3066) == 2 then
			selfSay('Are you sure you want to divorce your partner?', cid)
			talkState[talkUser] = 6
		else
			selfSay('You are not married. Would you like to{marry}?', cid)
			talkState[talkUser] = 0
		end
	end

	if talkState[talkUser] == 1 then
		if msgcontains(msg, 'yes') then
			local fid = getPlayerGUID(cid)
			local marrystatus = getMarryStatus(fid)
			if marrystatus == FALSE then
				selfSay('And what is the name of your future partner?', cid)
				talkState[talkUser] = 2
			else
				local marryname = getPlayerNameByGUID(marrystatus)
				selfSay('{' .. marryname .. '} marks the wedding date with you. Do you want to {continue} or {cancel the wedding?}', cid)
				talkState[talkUser] = 4
			end
		end

	elseif talkState[talkUser] == 2 then
		local p = msg
		local player = getPlayerName(cid)
		local fid = getPlayerGUID(cid)
		local sid = getPlayerGUIDByName(p)
		if not sid or sid == 0 then
			selfSay('There is no player with this name.', cid)
			talkState[talkUser] = 0
		elseif sid == fid then
			selfSay('Do not worry, you will always be married to yourself, boy.', cid)
			talkState[talkUser] = 0
		else
			local marrystatus = getMarryStatus(fid)
			local pmarriage = getPlayerMarriage(sid)
			local ownstatus = getOwnMarryStatus(cid)
			if pmarriage == FALSE then
				if marrystatus == FALSE then
					if ownstatus == FALSE then
						setPlayerStorageValue(cid,3066,1)
						addMarryStatus(fid,sid)
						selfSay('You just dial a marriage {' .. p .. '}.', cid)
						talkState[talkUser] = 0
					else
						local partnername = getPlayerNameByGUID(ownstatus)
						selfSay('{' .. p .. '} already marked the date of marriage {' .. partnername .. '}.', cid)
						talkState[talkUser] = 0
					end
				else
					local marryname = getPlayerNameByGUID(marrystatus)
					selfSay('{' .. marryname .. '} marks the wedding date with you. You want to {continue} or {cancel the wedding?}', cid)
					talkState[talkUser] = 4
				end
			else
				local pname = getPlayerNameByGUID(pmarriage)
				selfSay('Sorry, but {' .. p .. '} is married {' .. pname .. '}.', cid)
				talkState[talkUser] = 0
			end
		end

	elseif talkState[talkUser] == 4 then
		if msgcontains(msg, 'continue') then
			local fid = getPlayerGUID(cid)
			local sid = getMarryStatus(fid)
			local marryname = getPlayerNameByGUID(sid)
			local pid = getPlayerByNameWildcard(marryname)
				local tmf = getCreaturePosition(cid)
				local	tms = getCreaturePosition(pid)
				local text = {'I love you ',' My love! "," My passion!'}
				local chance1 = math.random(1,table.getn(text))
				local chance2 = math.random(1,table.getn(text))
				local dateFormat = "%A %d"..getMonthDayEnding(os.date("%d")).." %B %Y"
                                local ring = doPlayerAddItem(cid,10502,1)
                                local ring2 = doPlayerAddItem(pid,10502,1)

			if isOnline(fid) == TRUE and isOnline(sid) == TRUE then
			if getDistanceBetween(tmf, tms) <= 3 then
					setPlayerStorageValue(cid,3066,2)
					setPlayerStorageValue(pid,3066,2)
					doCancelMarryStatus(fid)
					doCancelMarryStatus(sid)
					setPlayerPartner(cid,sid)
					setPlayerPartner(pid,fid)
                                        doPlayerAddOutfitId(cid,23,0)
                                        doPlayerAddOutfitId(pid,23,0)
                                        doItemSetAttribute(ring, "description", "" .. getCreatureName(cid) .. " & " .. getCreatureName(pid) .. " forever - married on " ..os.date(dateFormat).. ".")
                                        doItemSetAttribute(ring2, "description", "" .. getCreatureName(cid) .. " & " .. getCreatureName(pid) .. " forever - married on " ..os.date(dateFormat).. ".")
					doCreatureSay(cid, text[chance1], TALKTYPE_ORANGE_1)
					doCreatureSay(pid, text[chance2], TALKTYPE_ORANGE_1)
					doSendMagicEffect(tmf, 35)
					doSendMagicEffect(tms, 35)
					selfSay('Congratulations! By now, you can kiss it! Whenever you want this effect, just say {love}. You need to be close to your partner.', cid)
					talkState[talkUser] = 0

				else
					selfSay('Your partner should be close to you so you can get married!', cid)
					talkState[talkUser] = 0
				end
			else
				selfSay('You and your new partner should be online at the same time.', cid)
				talkState[talkUser] = 0
			end
			


		elseif msgcontains(msg, 'cancel') then
			local fid = getPlayerGUID(cid)
			local sid = getMarryStatus(fid)
			local marryname = getPlayerNameByGUID(sid)
			local pid = getPlayerByNameWildcard(marryname)
			if isOnline(sid) == TRUE then
				setPlayerStorageValue(pid,3066,-1)
			end
			doCancelMarryStatus(sid)
			selfSay('You cancel your wedding date with {' .. marryname .. '}.', cid)
			talkState[talkUser] = 0
		end

	elseif talkState[talkUser] == 5 then
		if msgcontains(msg, 'cancel') or msgcontains(msg, 'yes') then
			local fid = getPlayerGUID(cid)
			setPlayerStorageValue(cid,3066,-1)
			doCancelMarryStatus(fid)
			talkState[talkUser] = 0
		end

	elseif talkState[talkUser] == 6 then
		if msgcontains(msg, 'yes') then
			local fid = getPlayerGUID(cid)
			local sid = getPlayerPartner(cid)
			local marryname = getPlayerNameByGUID(sid)
			local pid = getPlayerByNameWildcard(marryname)
			if (isOnline(fid) == TRUE and isOnline(sid) == TRUE) then
				setPlayerStorageValue(cid,3066,-1)
				setPlayerStorageValue(pid,3066,-1)
				setPlayerPartner(cid,0)
				setPlayerPartner(pid,0)
                                doPlayerAddOutfitId(cid,23,-1)
                                doPlayerAddOutfitId(pid,23,-1)
				selfSay('You just divorcing your former partner.', cid)
				talkState[talkUser] = 0
			else
				selfSay('You and your partner must be online at the same time.', cid)
				talkState[talkUser] = 0
			end
		end

	end


	return TRUE
end

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

Add this into your MySQL database :D:
Code:
  ALTER TABLE `players` ADD `marrystatus` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `marriage` ;

how it works?
PLAYER1 goes to the NPC and start a conversation.
PLAYER1: Hi
PLAYER1: marry or he can say marriage
PLAYER1: yes
PLAYER1: NAME_OF_PLAYER2
Now, a "marry status" will be set to PLAYER1 with the ID of the PLAYER2. Now, the PLAYER2 go to the NPC and start a conversation:
PLAYER2: Hi
PLAYER2: marry
PLAYER2: yes
PLAYER2: proceed

FEATURES:
-You can get a wedding with another player
-You need 2 wedding rings to get a wedding
-After a wedding you get a wedding outfit, special description when onLook, information about your partner in acc maker and a wedding ring like in Rl tibia (playername & playername forever - married on date)
-You can get a divorce
-When you get a divorce you'll lose your wedding outfit (you must relog to loose it), you loose your special description on onLook and information in acc maker that you are a single.


You now have a working NPC Marriage script for TFS 0.3.6 i have not tested it on any other TFS or releases so test at your own risk if u have any questions post back and ill help the best i can!! REP+++++ if i helped :D
All Credits Go To Godely
 
Last edited:
Yea go forsaken!!!!! Ur awesome bro u helped me so much (simon) xd ty this will also rlly help me :d
 
:( i know u work hard but still doesnt work for me the priest says: would u like to get marry and this happens:

[Error - Npc interface]
data/npc/scripts/wedding.lua nCreatureSay
Description:
data/npc/scripts/wedding.lua:52: attempt to call global 'getMarryStatus' (a nil value)
stack traceback:
data/npc/scripts/wedding.lua:52: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/wedding.lua:8: in function <data/npc/scripts/wedding.lua:8>
 
:( i know u work hard but still doesnt work for me the priest says: would u like to get marry and this happens:

[Error - Npc interface]
data/npc/scripts/wedding.lua nCreatureSay
Description:
data/npc/scripts/wedding.lua:52: attempt to call global 'getMarryStatus' (a nil value)
stack traceback:
data/npc/scripts/wedding.lua:52: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
data/npc/scripts/wedding.lua:8: in function <data/npc/scripts/wedding.lua:8>

make sure u added the new thing i added at the bottom that u must make the new table in MySQL database :p
 
:/

I have tried everything you have told me, I have made sure I have the priest.xml the lua and I triple checked the new field on the table player and still nothing.

If you have anything other suggestion it will be highly appreciate it.
 
Last edited:
Yes it doesn't works, this is my dialoge.

Priest: Hello Player, Would you like to get married?
Player: marry
Priest: Would you like to marry?
Player: yes

and he don't say nothing more
 
I fixed it.

My friend got me this lua which work perfectly

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

local Topic, Partner = {}, {}

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end

function say(msg, cid)
local npc, _msg = getNpcId(), msg:gsub('{', ''):gsub('}', '')
local pos = getThingPos(npc)
for _, tid in ipairs(getSpectators(pos, 7, 5, false) or {}) do
if isPlayer(tid) then
doCreatureSay(npc, tid ~= cid and _msg or msg, tid == cid and TALKTYPE_PRIVATE_NP or TALKTYPE_SAY, false, tid, pos)
end
end
end

local function marry(cid, msg, ext)
msg = msg:gsub('my heart belongs to ', '')
local player = getPlayerByName(msg)
if player then
if player ~= cid then
if getPlayerPartner(player) == 0 then
if getPlayerStorageValue(cid, 46000) == 1 then
if getPlayerStorageValue(player, 46001) == getPlayerGUID(cid) then
doCreatureSay(cid, msg, TALKTYPE_SAY)
say('By the powers of the Gods your souls are now bound together for eternity. As a symbol of your love, receive your engraved wedding rings and festive clothes. ...', cid)
say('May the Gods watch with grace over your future life as a married couple. Go now and celebrate your honeymoon on the peaceful island of Meluna!', cid)
for _, pid in ipairs({cid, player}) do
doPlayerAddOutfitId(pid, 34, 0)
local v = getCreatureOutfit(pid)
v.lookType = getPlayerSex(pid) == 0 and 329 or 328
doCreatureChangeOutfit(pid, v)
doSendMagicEffect(getThingPos(pid), CONST_ME_HEARTS)
setPlayerStorageValue(pid, 46002, os.time() + 86400)
end
doSendMagicEffect(getNpcPos(), CONST_ME_MAGIC_BLUE)
local nc, np = getCreatureName(cid), getCreatureName(player)
doItemSetAttribute(doPlayerAddItem(cid, 10502, 1), 'description', np .. ' & ' .. nc .. ' forever - married on ' .. os.date('%b ' .. os.date('*t').day .. ', %Y') .. '.')
doItemSetAttribute(doPlayerAddItem(player, 10502, 1), 'description', nc .. ' & ' .. np .. ' forever - married on ' .. os.date('%b ' .. os.date('*t').day .. ', %Y') .. '.')
doPlayerSetPartner(cid, getPlayerGUID(player))
doPlayerSetPartner(player, getPlayerGUID(cid))
Topic[cid] = nil
return true
elseif ext == 1 then
say(getCreatureName(cid) .. ', are you sure of your love to ' .. getCreatureName(player) .. ' and wish to bind your souls together for eternity?', cid)
Topic[cid] = 5
Partner[cid] = getPlayerGUID(player)
end
else
say('Oh no! Your ring and outfit box are missing! I hope you didn\'t forget them! Can you please give them to me now?', cid)
Topic[cid] = 8
return true
end
else
if ext then say('This person is already married to someone.', cid) end
end
else
if ext then say('You cannot marry yourself.', cid) end
end
else
if ext then say('This person is not online.', cid) end
end
if ext then doCreatureSay(cid, msg, TALKTYPE_SAY) end
end

function creatureSayCallback(cid, type, msg)
if msgcontains(msg, 'my heart belongs to') and not npcHandler:isFocused(cid) then
local v = marry(cid, msg)
if v then
npcHandler:addFocus(cid)
return true
end
elseif (msgcontains(msg, 'hello') or msgcontains(msg, 'hi')) and (not npcHandler:isFocused(cid)) then
npcHandler:say('Welcome in the name of the Gods, pilgrim '..getCreatureName(cid)..'!', cid)
npcHandler:addFocus(cid)
Topic[cid] = nil
elseif not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
npcHandler:say('Good bye, '..getCreatureName(cid)..'. May the Gods watch over you, my child!', cid)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
elseif msgcontains(msg, 'marriage') or msgcontains(msg, 'marry') or msgcontains(msg, 'ceremony') or msgcontains(msg, 'wedding') then
if getPlayerPartner(cid) ~= 0 then
say('Yes, indeed, you are married, ' .. getCreatureName(cid) .. '. I hope your love is still blooming and flourishing.', cid)
Topic[cid] = nil
elseif getPlayerStorageValue(cid, 46000) < 1 then
say('Before we can start the marriage ceremony, each of you need to hand me a blank wedding ring and a box with a wedding outfit. ' .. getCreatureName(cid) .. ', do you have these items with you and are you willing to give them to me now?', cid)
Topic[cid] = 6
else
say('Do you wish me to initiate the marriage ceremony now?', cid)
Topic[cid] = 1
end
doCreatureSay(cid, msg, TALKTYPE_SAY)
elseif Topic[cid] == 1 then
if msgcontains(msg, 'yes') or (msgcontains(msg, 'i') and msgcontains(msg, 'will')) then
say('In the name of the Gods of Benevolence, I ask you, ' .. getCreatureName(cid) .. ': are both of you ready and eager to be bound in marriage?', cid)
Topic[cid] = 2
else
say('Perhaps another time, marriage isn\'t a step one should consider without love in the heart.', cid)
Topic[cid] = nil
end
doCreatureSay(cid, msg, TALKTYPE_SAY)
elseif Topic[cid] == 2 then
if msgcontains(msg, 'yes') or (msgcontains(msg, 'i') and msgcontains(msg, 'will')) then
say('A moment of silence please... I hereby invoke the eternal powers who watch over our souls and lives. Please repeat after me: {May the gods bless us}!', cid)
doSendMagicEffect(getNpcPos(), CONST_ME_MAGIC_BLUE)
Topic[cid] = 3
end
doCreatureSay(cid, msg, TALKTYPE_SAY)
elseif Topic[cid] == 3 then
if msgcontains(msg, 'may') and msgcontains(msg, 'gods') and msgcontains(msg, 'bless') and msgcontains(msg, 'us') then
say('I ask thee, ' .. getCreatureName(cid) .. ', what is the name of the person your {heart belongs to}?', cid)
Topic[cid] = 4
else
--
end
doCreatureSay(cid, msg, TALKTYPE_SAY)
elseif Topic[cid] == 4 then
marry(cid, msg, 1)
elseif Topic[cid] == 5 then
if msgcontains(msg, 'yes') or (msgcontains(msg, 'i') and msgcontains(msg, 'will')) then
say('So by the powers of the Gods, your soul is now bound to your beloved. ' .. getPlayerNameByGUID(Partner[cid]) .. ', now step forward and tell me if your heart belongs to ' .. getCreatureName(cid) .. ' too.', cid)
setPlayerStorageValue(cid, 46001, Partner[cid])
Topic[cid] = nil
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
elseif msgcontains(msg, 'no') then
say('Your neglection of love hurts my heart. Leave now!', cid)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
end
doCreatureSay(cid, msg, TALKTYPE_SAY)
elseif Topic[cid] == 6 then
if msgcontains(msg, 'yes') or (msgcontains(msg, 'i') and msgcontains(msg, 'will')) then
if getPlayerItemCount(cid, 2121) ~= 0 and doPlayerRemoveItem(cid, 10503, 1) then
doPlayerRemoveItem(cid, 2121, 1)
say('Thank you. I\'ll give them back to you when the time is right. Please make sure that BOTH of you have handed me your items before we start the {ceremony}.', cid)
setPlayerStorageValue(cid, 46000, 1)
else
say('I\'m sorry, but you don\'t seem to have a ring and an outfit. I fear you need to visit a jeweller and the tailor in Venore.', cid)
end
else
say('Hm, then not.', cid)
end
Topic[cid] = nil
elseif msgcontains(msg, 'meluna') then
if getPlayerPartner(cid) ~= 0 then
if getPlayerSex(cid) == 1 then
say('You can travel to Meluna with Kamil who you will find to the south of Fibula, but only on the day of your wedding. This island is protected by the Gods. They will not allow violence there. But on your honeymoon your thoughts should be on things other than violence. ...', cid)
say(getCreatureName(cid) .. ', just so that you won\'t have to fear an ambush on your wedding day, would you like me to bring you to the boat on Fibula, from where you can travel to Meluna?', cid)
else
say('You can travel to Meluna with Kamil south of Fibula, but only on the day of your wedding. This island is protected by the Gods. They will not allow violence there. ...', cid)
say(getCreatureName(cid) .. ', since you might not want to get your new clothes dirty, would you like me to bring you to the boat on Fibula, from where you can travel to Meluna?', cid)
end
Topic[cid] = 7
else
npcHandler:say('You can travel to Meluna with Kamil south of Fibula, but only on the day of your wedding. This island is protected by the Gods. They will not allow violence there.', cid)
Topic[cid] = nil
end
elseif Topic[cid] == 7 then
if msgcontains(msg, 'yes') then
say(getPlayerSex(cid) == 1 and 'Take care of yourselves!' or 'Enjoy yourselves!', cid)
Topic[cid] = nil
doSendMagicEffect(getThingPos(cid), CONST_ME_HEARTS)
doTeleportThing(cid, {x=32154, y=32456, z=7})
doSendMagicEffect({x=32154, y=32456, z=7}, CONST_ME_HEARTS)
else
say('Hm, then not.', cid)
end
Topic[cid] = nil
elseif Topic[cid] == 8 then
if msgcontains(msg, 'yes') then
if getPlayerItemCount(cid, 2121) ~= 0 and doPlayerRemoveItem(cid, 10503, 1) then
doPlayerRemoveItem(cid, 2121, 1)
say('Thank you. Now let\'s continue - please tell me again whom your heart belongs to!', cid)
setPlayerStorageValue(cid, 46000, 1)
Topic[cid] = 9
return true
else
say('I\'m sorry, but you don\'t seem to have a ring and an outfit. I fear you need to visit a jeweller and the tailor in Venore.', cid)
end
else
say('Hm, then not.', cid)
end
Topic[cid] = nil
elseif Topic[cid] == 9 then
marry(cid, msg, true)
elseif msgcontains(msg, 'ring') then
npcHandler:say('You can buy wedding rings from many jewellers. I recommend Carina in Venore though, since the tailor in Venore also has wedding {outfits} in stock. Or - from Hanna, right here in Thais!', cid)
Topic[cid] = nil
elseif msgcontains(msg, 'outfit') then
npcHandler:say('You can buy a box with your wedding outfit from the tailor Norbert in Venore.', cid)
Topic[cid] = nil
elseif msgcontains(msg, 'divorce') then
npcHandler:say('Oh, what a shameful thought! Marriage is meant to be for eternity! Only the most unscrupulous or drunken priests would carry out a divorce.', cid)
Topic[cid] = nil
end
return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, 'May the Gods be with you!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'May the Gods be with you!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Credits to whoever made the lua. And my friend for finding it.
 
umm it might be 0.4 then :/ hmm idk atm my files are not working what so ever so i have to wait untill i get new ones and then i can try them and mess with it
 
Using 0.3.6pl1
Im having the same problem as Dyker did......I say hi, marry,yes and then npc stops responding. I get an error at this point about nil value(forgot to copy it).
The second script just crashes my server if I use it.
I'd like to use the marriage system in my server, can we get this working?
 
Well Im going to give you 1 more opportunity , I helped you in the other server, if you need any help testing just ask cya. GL
ht3.jpg
jh.jpg
bh.jpg
 
Back
Top