Godely
Member
- Joined
- Aug 19, 2007
- Messages
- 233
- Reaction score
- 16
Almost 5 years since I released the Marriage System for TFS ~0.2-0.3, I took a day to remake it so that works with TFS 1.0. I still use live queries in the code since I didn't want to change any source code (and also to make it works with offline players).
Please, understand that TFS 1.0 is constantly changing and you should have the latest sources compiled to make it work (since some changes were made in events). Hope you like it!
Create a new NPC Priest.xml:
And the corresponding lua file priest.lua:
Now, on events/events.xml, enable the method onLook if it's not enabled. The line should be like this:
Continue on the next post...
Please, understand that TFS 1.0 is constantly changing and you should have the latest sources compiled to make it work (since some changes were made in events). Hope you like it!
Create a new NPC Priest.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Priest" script="priest.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="132" head="20" body="39" legs="45" feet="7" addons="0"/>
</npc>
And the corresponding lua file priest.lua:
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 greetCallback(cid)
local player = Player(cid)
local msg = 'Be welcome, ' .. player:getName() .. '.'
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 .. ' What brings you here? Wanting to {marry} someone?'
end
npcHandler:say(msg,cid)
npcHandler:addFocus(cid)
return false
end
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
npcHandler:say('You are already married to {' .. getPlayerNameById(playerSpouse) .. '}.', cid)
elseif playerStatus == PROPOSED_STATUS then
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
npcHandler:say('A player with this name does not exist.', cid)
elseif candidate == player:getGuid() then
npcHandler:say('You can\'t marry yourself, kid.', cid)
else
if player:getItemCount(ITEM_WEDDING_RING) == 0 then
npcHandler:say('As I said, you need a wedding ring in order to marry.', cid)
else
local candidateStatus = getPlayerMarriageStatus(candidate)
local candidateSpouse = getPlayerSpouse(candidate)
if candidateStatus == MARRIED_STATUS then
npcHandler:say('{' .. getPlayerNameById(candidate) .. '} is already married to {' .. getPlayerNameById(candidateSpouse) .. '}.', cid)
elseif candidateStatus == PROPOSED_STATUS then
if candidateSpouse == player:getGuid() then
npcHandler:say('Since both young souls are willing to marry, I now pronounce you and {' .. getPlayerNameById(candidate) .. '} married. {' .. player:getName() .. '}, take these two engraved wedding rings and give one of them to your spouse.', cid)
player:removeItem(ITEM_WEDDING_RING,1)
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.'))
setPlayerMarriageStatus(player:getGuid(), MARRIED_STATUS)
setPlayerMarriageStatus(candidate, MARRIED_STATUS)
setPlayerSpouse(player:getGuid(), candidate)
else
npcHandler:say('{' .. getPlayerNameById(candidate) .. '} already made a wedding proposal to {' .. getPlayerNameById(candidateSpouse) .. '}.', cid)
end
else
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)
setPlayerMarriageStatus(player:getGuid(), PROPOSED_STATUS)
setPlayerSpouse(player:getGuid(), candidate)
end
end
end
end
keywordHandler:moveUp(3)
return true
end
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)
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 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, {})
keywordHandler:addKeyword({'remove'}, confirmRemoveEngage, {})
keywordHandler:addKeyword({'divorce'}, confirmDivorce, {})
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
Now, on events/events.xml, enable the method onLook if it's not enabled. The line should be like this:
Code:
<event class="Player" method="onLook" enabled="1"/>
Continue on the next post...
Last edited: