• 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 [ULTRA Release] !EXCLUSIVE! Marriage System!

Godely

Member
Joined
Aug 19, 2007
Messages
233
Reaction score
16
Hi everyone. After almost 7 months, here I am. I realize that many of you are having doubts. As I've already told you, this version DOES not works anymore on the newest versions. The following topic is the remake of the script, that works the same way it does and for version 8.5.
http://otland.net/f83/marriage-system-forgotten-server-0-3-5-a-39702/
Thank you all! And thank you ScorpiOOn93 for remaking it!

Hello! Well, I spend 2 days doing this scripts, and since nobody have ever posted something like that, I decided to be the first. Please, if you find any bugs, report here, and do not say bad things about this since the purpose of this post is to help those who want this script and not to hear bad things about my job.

Let's begin!

Add to your function.lua:

Code:
function getPlayerMarriage(player)
	local rows = db.getResult("SELECT `marriage` FROM `players` WHERE `id` = " .. player .. ";")
	local marry = rows:getDataInt("marriage")
	if marry ~= 0 then
		return marry
	else
		return 0
	end
end

function addMarryStatus(player,partner)
	db.executeQuery("UPDATE `players` SET `marrystatus` = " .. partner .. " WHERE `id` = " .. player .. ";")
end

function doCancelMarryStatus(player)
	db.executeQuery("UPDATE `players` SET `marrystatus` = 0 WHERE `id` = " .. player .. ";")
end

function getMarryStatus(player)
	local stat = db.getResult("SELECT `id` FROM `players` WHERE `marrystatus` = " .. player .. ";")
	if(stat:getID() == -1) then
		return 0
	else
		local info = stat:getDataInt("id")
		return info
	end
end

function getOwnMarryStatus(player)
	local stat = db.getResult("SELECT `marrystatus` FROM `players` WHERE `id` = " .. player .. ";")
	if(stat:getID() == -1) then
		return 0
	else
		local info = stat:getDataInt("marrystatus")
		return info
	end
end

function isOnline(player)
	local rows = db.getResult("SELECT `online` FROM `players` WHERE `id` = " .. player .. ";")
	local on = rows:getDataInt("online")
	if on ~= 0 then
		return 1
	else
		return 0
	end
end

Now, create an NPC.xml (anything you want) and on its .lua file you put:
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 get married?', 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('You already set a wedding date with {' .. newpartner .. '}, now I must talk to your partner. Do you want to {cancel} it?', cid)
				talkState[talkUser] = 5
			else
				setPlayerStorageValue(cid,3066,-1)
				selfSay('Would you like to get married?', cid)
				talkState[talkUser] = 1
			end
		elseif getPlayerStorageValue(cid,3066) == 2 then
			selfSay('You are already married. If you want to {divorce}, just say it.', cid)
			talkState[talkUser] = 0
		end

	elseif msgcontains(msg, 'divorce') then
		if getPlayerStorageValue(cid,3066) == 2 then
			selfSay('Would you like to divorce of your partner?', cid)
			talkState[talkUser] = 6
		else
			selfSay('You are not married. If you want to get married, just say {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\'s the name of your future partner?', cid)
				talkState[talkUser] = 2
			else
				local marryname = getPlayerNameByGUID(marrystatus)
				selfSay('{' .. marryname .. '} has set a wedding date with you. Do you want to {proceed} 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 sid == 0 then
			selfSay('A player with that name does not exists.', cid)
			talkState[talkUser] = 0
		elseif sid == fid then
			selfSay('Don\'t worry, you will always be married with yourself, kid.', cid)
			talkState[talkUser] = 0
		else
			local marrystatus = getMarryStatus(fid)
			local pmarriage = getPlayerMarriage(sid)
			local ownstatus = getOwnMarryStatus(sid)
			if pmarriage == FALSE then
				if marrystatus == FALSE then
					if ownstatus == FALSE then
						setPlayerStorageValue(cid,3066,1)
						addMarryStatus(fid,sid)
						selfSay('You\'ve just set a wedding date with {' .. p .. '}.', cid)
						talkState[talkUser] = 0
					else
						local partnername = getPlayerNameByGUID(ownstatus)
						selfSay('{' .. p .. '} has already set a wedding date with {' .. partnername .. '}.', cid)
						talkState[talkUser] = 0
					end
				else
					local marryname = getPlayerNameByGUID(marrystatus)
					selfSay('{' .. marryname .. '} has set a wedding date with you. Do you want to {proceed} or {cancel} the wedding?', cid)
					talkState[talkUser] = 4
				end
			else
				local pname = getPlayerNameByGUID(pmarriage)
				selfSay('Sorry, but {' .. p .. '} is already married to {' .. pname .. '}.', cid)
				talkState[talkUser] = 0
			end
		end

	elseif talkState[talkUser] == 4 then
		if msgcontains(msg, 'proceed') then
			local fid = getPlayerGUID(cid)
			local sid = getMarryStatus(fid)
			local marryname = getPlayerNameByGUID(sid)
			local pid = getPlayerByNameWildcard(marryname)
			if isOnline(fid) == TRUE and isOnline(sid) == TRUE then
				local tmf = getCreaturePosition(cid)
				local	tms = getCreaturePosition(pid)
				local text = {'I love you!','My love!','Baby dear!'}
				local chance1 = math.random(1,table.getn(text))
				local chance2 = math.random(1,table.getn(text))
				if getDistanceBetween(tmf, tms) <= 3 then
					setPlayerStorageValue(cid,3066,2)
					setPlayerStorageValue(pid,3066,2)
					doCancelMarryStatus(fid)
					doCancelMarryStatus(sid)
					setPlayerPartner(cid,sid)
					setPlayerPartner(pid,fid)
					doCreatureSay(cid, text[chance1], TALKTYPE_ORANGE_1)
					doCreatureSay(pid, text[chance2], TALKTYPE_ORANGE_1)
					doSendMagicEffect(tmf, 35)
					doSendMagicEffect(tms, 35)
					selfSay('Congratulations! Now you may kiss your partner! Everytime you wanna make this effect, just say {love}. You must be close to your partner.', cid)
					talkState[talkUser] = 0
				else
					selfSay('Your partner must be close to you so you can marry!', cid)
					talkState[talkUser] = 0
				end
			else
				selfSay('You and your new partner must 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 just canceled 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)
				selfSay('You\'ve just divorced of your old partner.', cid)
				talkState[talkUser] = 0
			else
				selfSay('You and your new 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())

Now, add to your MySQL database the following table:
Code:
ALTER TABLE `players` ADD `marrystatus` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `marriage` ;

Everything done? Nop, almost done. The following code is an OPTIONAL one, just to make the marriage system something "useful".

Add to your talkactions.xml:
Code:
<talkaction words="love" script="love.lua"/>

Now create a file named love.lua and put inside it:
Code:
function onSay(cid, words, param)
	local text = {'I love you!','My love!','Baby dear!'}
	local chance1 = math.random(1,table.getn(text))
	local chance2 = math.random(1,table.getn(text))
	local sid = getPlayerPartner(cid)
	if sid > 0 then
		if isOnline(sid) == TRUE then
			local sname = getPlayerNameByGUID(sid)
			local pid = getPlayerByNameWildcard(sname)
			local tmf = getCreaturePosition(cid)
			local	tms = getCreaturePosition(pid)
			if getDistanceBetween(tmf, tms) <= 3 then
				doCreatureSay(cid, text[chance1], TALKTYPE_ORANGE_1)
				doCreatureSay(pid, text[chance2], TALKTYPE_ORANGE_1)
				doSendMagicEffect(tmf, 35)
				doSendMagicEffect(tms, 35)
				return TRUE
			end
		end
	end
end

Now, everything is done.
I will explain how it works:

PLAYER1 goes to the NPC and start a conversation.
PLAYER1: Hi
PLAYER1: marry
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
Now, it will be sent heart effect to both of the players, and the marriage will be completed. I've put some exceptions, of course, like both players must be online at the same time and they must be close (max. 3 sqms of distance between each other).

Believe me, the script is perfect (or almost perfect if you find a small bug), I tested it with all the possibilities, like a player try to marry with a already married player, etc.

EDIT: I have made some modifications on the script. Now, the players won't get kicked anymore at any part, and I'm using some original functions like setPlayerPartner and getPlayerPartner (Also removed 2 own made functions: doSetPlayerPartner and doDivorcePlayer). Remember, however, that there are some parts of the script that I HAD to keep using the getPlayerMarriage, since getPlayerPartner just return a value if the mentioned player is online.

If you like it, some rep++ wouldn't make bad ;) Enjoy the script!

Yours,
Godely.
 
Last edited:
huh a stupid question i never tried to do this or use it in my server so...
Is it giving anything to players that got married?
 
huh a stupid question i never tried to do this or use it in my server so...
Is it giving anything to players that got married?

Zaja, if the meaning of "giving anything to players" is adding items to them when they marry, nop, they are not receiving any items :). But if you want them to get items, just add a doPlayerAddItem(cid, ID, 1) and doPlayerAddItem(pid, ID, 1) before the "removeCreature(cid) and removeCreature(pid)"
 
I am just wondering... why do u kick players ?;p Can't u just set temporary storagevalue and marriage will be 'completed' after relogin :> I know it will be a bit longer (using creaturescripts, etc.). Does the player1 has to stay offline while player2 is talking to npc?:>
 
I am just wondering... why do u kick players ?;p Can't u just set temporary storagevalue and marriage will be 'completed' after relogin :> I know it will be a bit longer (using creaturescripts, etc.). Does the player1 has to stay offline while player2 is talking to npc?:>

If a character is online and you edit its marriage, it won't have any effect. It will only have affect if the character is offline while you put set its marriage. Another things: It would be easy making with storagevalue (I actually thought about that), but there are 2 problems: The first is what I've said, the problem that it only affect the player if he is offline, and the second is that a "storagevalue" has a limit of 60000 (60k), so if your player has a id 74024 for example, it wouldn't be able to set a value for him (Since I would storage a value with his id).

And no, player1 has not to stay offline while player2 talk to the NPC.
 
I am wondering why do you actually use live queries where you have out there setPlayerPartner(cid, guid) and getPlayerPartner(cid)...
 
I really didn't realize the existence of those functions o_o'
 
.... so Godely, will you use these functions on a NPC or not xd? im using this for test but it would be cool with these functions =)
 
As soon as I have time for it, I will remake the NPC. Gtg to school now, see u
 
Yey kkthxbb u roxors pwnzingalingalong >.>

Remake also elf's sex system, that only those who are married with someone can have sex only with his partner xD
 
Was enough to open doc/LUA_FUNCTIONS and hit 'CTRL + F'.

I remade the scripts (But I had to keep using getPlayerMarriage on some parts), already edited my post. Now, answering to your question, I don't have the duty to know how your function is written, so how would I search for something I didn't realize? I assume I tried searching something like "Wedding" or "Marriage", but the word "partner" I just knew when I was scripting this with the help of google translator :)
 
Back
Top