Extrodus Administrator
Posts: 112 |
Tested by Extrodus on 0.4
Info: Use a NPC to allow players to get married in-game. Adds married outfits to player + Gives ring with name on it.
Execute MySQL code:
CREATE TABLE marriage_system (
player_id INTEGER NOT NULL,
partner VARCHAR( 255 ) NOT NULL,
marriage_date INTEGER NOT NULL,
PRIMARY KEY ( player_id )
);
marriagesystem.xml
<?xml version="1.0" encoding="UTF-8"?>
<mod name="MarriageSystem" version="1.0" author="Vodkart" contact="xtibia.com" enabled="yes">
<config name="marry_func"><![CDATA[
marry_config = {
OnlyDifferentSex = false,
Marry_Price = 100000,
Divorce_Price = 50000,
Level = 100,
MaxSqm = 7, -- to marry
Text = {'I love you!','My love!','Baby dear!'},
RingID = 10502,
TimeAccept = 60,
storage1 = 300235,
storage2 = 300236,
storage3 = 300237
}
function isMarried(cid)
local m = db.getResult("SELECT `player_id` FROM `marriage_system` WHERE `player_id` = '"..getPlayerGUID(cid).."';")
if(m:getID() == -1) then
local e = db.getResult("SELECT `partner` FROM `marriage_system` WHERE `partner` = '"..getPlayerGUID(cid).."';")
if(e:getID() == -1) then
return false
end
end
return true
end
function isPatner(cid)
local p = db.getResult("SELECT `partner` FROM `marriage_system` WHERE `player_id` = '"..getPlayerGUID(cid).."';")
if(p:getID() == -1) then
return true
end
return false
end
function Ponline(player)
local rows = db.getResult("SELECT `online` FROM `players` WHERE `id` = " .. player .. ";")
local on = rows:getDataInt("online")
if on ~= 0 then
return TRUE
else
return FALSE
end
end
function getPartner(cid)
if isPatner(cid) then
a = db.getResult("SELECT `player_id` FROM `marriage_system` WHERE `partner` = '"..getPlayerGUID(cid).."';")
b = "player_id"
else
a = db.getResult("SELECT `partner` FROM `marriage_system` WHERE `player_id` = '"..getPlayerGUID(cid).."';")
b = "partner"
end
local query = a
return getPlayerNameByGUID(query:getDataString(b))
end
function doMarry(cid, patner)
return db.executeQuery("INSERT INTO `marriage_system` (`player_id`, `partner`, `marriage_date`) VALUES ('".. getPlayerGUID(cid) .."', '"..patner.."', '".. os.time() .."');")
end
function doDivorcePlayer(cid)
if isPatner(cid) then
pid,player = getPlayerGUIDByName(getPartner(cid)),getPlayerByNameWildcard(getPartner(cid))
else
pid,player = getPlayerGUID(cid),cid
end
return db.executeQuery("DELETE FROM `marriage_system` WHERE `player_id` = '" .. pid .. "';")
end
function getMarryDate(cid)
local player = isPatner(cid) and getPlayerGUIDByName(getPartner(cid)) or getPlayerGUID(cid)
local date = db.getResult("SELECT `marriage_date` FROM `marriage_system` WHERE `player_id` = '"..player.."';")
return os.date("%d %B %Y %X ", date:getDataInt("marriage_date"))
end
]]></config>
<talkaction words="/marriage;!marriage" event="buffer"><![CDATA[
domodlib('marry_func')
param = string.lower(param)
if (param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"invalid command, for more information enter !marriage info")
elseif(param == "info") then
doShowTextDialog(cid,2160,"Marriage Info:\n\nLevel Minimum: "..marry_config.Level.."\nMarriage Cost: "..marry_config.Marry_Price.."\nDivorce Cost: "..marry_config.Divorce_Price.."\n\nMarried Players have a special buffs as a wedding gift given by the union\n\nThis bonus is only given if the married players are nearby.")
elseif(param == "status") then
doPlayerPopupFYI(cid,""..(isMarried(cid) and "Marriage Status".."\n\nMarried with: \n\nThe date of his marriage was: "..getMarryDate(cid).."" or "you are not married").."")
end
return true
]]></talkaction>
<event type="login" name="MarryRegister" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid, "MarryLook")
registerCreatureEvent(cid, "MarryNoAttack")
return true
end]]></event>
<event type="look" name="MarryLook" event="script"><![CDATA[
domodlib('marry_func')
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) and isMarried(thing.uid) then
doPlayerSetSpecialDescription(thing.uid,'.\n'..(getPlayerSex(thing.uid) == 0 and 'She' or 'He')..' is married to '..getPartner(thing.uid))
end
return true
end]]></event>
<event type="combat" name="MarryNoAttack" event="script"><![CDATA[
domodlib('marry_func')
if isPlayer(cid) and isPlayer(target) and isMarried(cid) and isMarried(target) then
if (getCreatureName(target) == getPartner(cid))then
doPlayerSendCancel(cid, "You may not attack this player.")
return false
end
end
return true
]]></event>
</mod>
Outfits.xml
<outfit id="23" premium="yes">
<list gender="0" lookType="329" name="Wedding"/>
<list gender="1" lookType="328" name="Wedding"/>
</outfit>
Celest.xml
<?xml version="1.0"?>
<npc name="Celest" script="data/npc/scripts/marriagesystem.lua" walkinterval="50000" floorchange="0">
<health now="1000" max="1000"/>
<look type="130" head="0" body="114" legs="114" feet="0" addons="0"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. You can {marriage} or may {divorce}."/>
</parameters>
</npc>
marriagesystem.lua
domodlib('marry_func')
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
msg,players = string.lower(msg), {getPlayerGUID(cid)}
if msgcontains(msg, 'marry') or msgcontains(msg, 'marriage') then
if isMarried(cid) then
npcHandler:say("Sorry, You are already married.", cid)
elseif getPlayerStorageValue(cid, marry_config.storage3) >= 1 then
npcHandler:say("You must sign the {divorce}.", cid)
elseif getPlayerStorageValue(cid, marry_config.storage1) >= os.time() then
local pid = getPlayerStorageValue(cid, marry_config.storage2)
npcHandler:say(getPlayerNameByGUID(pid).." has set a wedding date with you. Do you want to {proceed} or {cancel} the wedding?", cid)
talkState = 2
else
npcHandler:say("Would you like to get married?", cid)
talkState = 1
end
elseif msgcontains(msg, "yes") and talkState == 1 then
npcHandler:say("And what\'s the name of your future partner?", cid)
talkState = 3
elseif talkState == 3 then
local player = getPlayerByNameWildcard(msg)
if(not player)then
npcHandler:say(msg.." is offline or does not exist.", cid) return true
elseif isMarried(player) then
npcHandler:say("He is already wedded.", cid) return true
elseif getPlayerStorageValue(cid, marry_config.storage3) >= 1 or getPlayerStorageValue(player, marry_config.storage3) >= 1 then
npcHandler:say((getPlayerStorageValue(cid, marry_config.storage1) >= 1 and "You" or "He").." must sign the divorce.", cid) return true
elseif getPlayerLevel(cid) < marry_config.Level or getPlayerLevel(player) < marry_config.Level then
npcHandler:say("Players must to be level "..marry_config.Level, cid) return true
elseif getPlayerStorageValue(player, marry_config.storage1) >= os.time() then
npcHandler:say(msg.." already has a wedding invitation, try again later.", cid) return true
elseif getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(player)) > marry_config.MaxSqm then
npcHandler:say("you are far away from each other to get married.", cid) return true
elseif marry_config.OnlyDifferentSex and getPlayerSex(cid) == getPlayerSex(player) then
npcHandler:say("You can only marry the opposite sex", cid) return true
elseif not doPlayerRemoveMoney(cid, marry_config.Marry_Price) then
npcHandler:say("Sorry, but you do not have "..marry_config.Marry_Price.." gp(s) to ask "..msg.." in marriage.", cid) return true
end
setPlayerStorageValue(player, marry_config.storage1,os.time()+marry_config.TimeAccept)
setPlayerStorageValue(player, marry_config.storage2, getPlayerGUID(cid))
npcHandler:say("You asked "..msg.." to marry you, wait for an answer!", cid)
doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE,getCreatureName(cid).." asked you in marriage.")
talkState = 0
elseif msgcontains(msg, "proceed") and talkState == 2 then
player = getPlayerStorageValue(cid, marry_config.storage2)
if getPlayerStorageValue(cid, marry_config.storage1) >= os.time() then
if not isMarried(cid) then
if Ponline(player) then
x = getPlayerByNameWildcard(getPlayerNameByGUID(player))
if getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(x)) <= marry_config.MaxSqm then
table.insert(players, player)
doMarry(cid, player)
for i = 1, #players do
local ring = doPlayerAddItem(getPlayerByNameWildcard(getPlayerNameByGUID(players[i])), marry_config.RingID, 1)
doItemSetAttribute(ring, "description", getCreatureName(cid) .. " & " .. getPartner(cid) .. " forever - married on " ..getMarryDate(cid).. ".")
doCreatureSay(getPlayerByNameWildcard(getPlayerNameByGUID(players[i])), marry_config.Text, TALKTYPE_ORANGE_1)
doSendMagicEffect(getCreaturePosition(getPlayerByNameWildcard(getPlayerNameByGUID(players[i]))), 35)
setPlayerStorageValue(getPlayerByNameWildcard(getPlayerNameByGUID(players[i])), marry_config.storage3, 1)
setPlayerStorageValue(getPlayerByNameWildcard(getPlayerNameByGUID(players[i])), 150420, 1)
end
npcHandler:say("Congratulations! Now you may kiss your partner! To see the status of your marriage say !marriage status", cid)
talkState = 0
else
npcHandler:say("You are to far away from her.", cid)
end
else
npcHandler:say("Player offline.", cid)
end
else
npcHandler:say("You are not married.", cid)
talkState = 0
end
else
npcHandler:say("You do not have any wedding invitations.", cid)
talkState = 0
end
elseif msgcontains(msg, "cancel") and talkState == 2 then
player = getPlayerStorageValue(cid, marry_config.storage2)
if getPlayerStorageValue(cid, marry_config.storage1) >= os.time() then
if not isMarried(cid) then
setPlayerStorageValue(cid, marry_config.storage1, -1)
npcHandler:say("You just refused the wedding invitation from player "..getPlayerNameByGUID(player), cid)
if Ponline(player) then
doPlayerSendTextMessage(getPlayerByNameWildcard(getPlayerNameByGUID(player)), MESSAGE_STATUS_CONSOLE_ORANGE,getCreatureName(cid).." rejected his marriage proposal.")
end
else
npcHandler:say("You are already married.", cid)
talkState = 0
end
else
npcHandler:say("You have no wedding invitation.", cid)
talkState = 0
end
elseif msgcontains(msg, "divorce") then
if isMarried(cid) then
npcHandler:say("Would you like to divorce of your partner for "..marry_config.Divorce_Price.." gp(s) ? {yes}", cid)
talkState = 6
elseif getPlayerStorageValue(cid, marry_config.storage3) >= 1 then
npcHandler:say("You must sign here to end your marriage, ok? {yes}", cid)
talkState = 7
else
npcHandler:say("You are not married", cid)
talkState = 0
end
elseif msgcontains(msg, "yes") and talkState == 6 then
if isMarried(cid) then
if doPlayerRemoveMoney(cid, marry_config.Divorce_Price) then
npcHandler:say("Congratulations, you divorced from player: "..getPartner(cid), cid)
setPlayerStorageValue(cid, 150420, -1)
setPlayerStorageValue(cid, marry_config.storage3, -1)
pguid = getPlayerGUIDByName(getPartner(cid))
if Ponline(pguid) then
setPlayerStorageValue(getPlayerByNameWildcard(getPlayerNameByGUID(pguid)), 150420, -1)
else
db.executeQuery("DELETE FROM `player_storage` WHERE `player_id` = " .. pguid .. " AND `key` = 150420;")
end
doDivorcePlayer(cid)
else
npcHandler:say("Sorry, you do not have "..marry_config.Divorce_Price.." gp(s).", cid)
end
else
npcHandler:say("You are not married.", cid)
end
elseif msgcontains(msg, "yes") and talkState == 7 then
npcHandler:say("Congratulations, you ended up in a divorce.", cid)
setPlayerStorageValue(cid, marry_config.storage3, -1)
elseif msg == "no" and talkState >= 1 then
selfSay("tudo bem então.", cid)
talkState = 0
npcHandler:releaseFocus(cid)
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Created 21 December 2013 01:42:12#post-19 |