Zisly
Intermediate OT User
- Joined
- Jun 9, 2008
- Messages
- 7,338
- Reaction score
- 120
Saw this http://otland.net/f83/city-guide-adding-mapmarks-locations-166422/ and I did an attempt at it as well, I'm no real Lua scripter and I haven't really tested it, it's very theoretical but I think it should work. What I did was make it easier to configure, just add one line for each location and the script does the rest. So credits to Limos for idea and initial code. I have more ideas but I think it might get a bit heavy on the server, for example if I added the ability to add multiple keywords for one location, say the tool shop: shovel, rope, pick etc. Anyway, back to business.
Requirements: TFS
You add a location by adding a new entry to the locations array
Say we want to add a new location, this time a rotworm spawn. We'd add this to the array.
Explanation:
rotworms - The keyword which triggers the mapmarking, if you say "bla bla rotworms", it will ask you if you want to add a mark to that location...
title - This is the title that will be added to the mark.
say - This is what the npc will have in his sentence when asking you if you want to add x. Example: Do you want me to add a mapmark where the rotworms are.
mark - Which kind of mark to put out
pos - position of mark
City Guide.xml - Credits Limos
cityguide.lua
As stated earlier, this might not work so yeah... report the possible errors
Requirements: TFS
You add a location by adding a new entry to the locations array
LUA:
local locations = {
tools = {title = 'The tool shop', say = 'tool shop is', mark = MAPMARK_SHOVEL, pos = {x=1000, y=1000, z=7}};
}
LUA:
rotworms = {title = 'Rotworm spawn', say = 'rotworms are', mark = MAPMARK_TICK, pos = {x=1500, y=1500, z=7}};
rotworms - The keyword which triggers the mapmarking, if you say "bla bla rotworms", it will ask you if you want to add a mark to that location...
title - This is the title that will be added to the mark.
say - This is what the npc will have in his sentence when asking you if you want to add x. Example: Do you want me to add a mapmark where the rotworms are.
mark - Which kind of mark to put out
pos - position of mark
City Guide.xml - Credits Limos
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="City Guide" script="cityguide.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="130" head="95" body="114" legs="118" feet="4" addons="0"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I'm the city guide from xcity and I know almost every place in the city and around it. Just tell me where you want to go or where you want to hunt and I will add a mapmark to guide you there."/>
</parameters>
</npc>
cityguide.lua
LUA:
-- By Zisly
-- Basic idea by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local talkState = {}
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
-- Location array
local locations = {
tools = {title = 'The tool shop', say = 'tool shop is', mark = MAPMARK_SHOVEL, pos = {x=1000, y=1000, z=7}};
rotworms = {title = 'Rotworm spawn', say = 'rotworms are', mark = MAPMARK_TICK, pos = {x=1500, y=1500, z=7}};
}
-- Future or would it be too heavy on the server when the list grows?
-- tools = {name = 'tool shop is', keywords = {'shovel', 'rope', 'backpack'}, x=1000, y=1000, z=7}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
-- Check if we got a conversation going on and if he answered yes to our dear question
if msgcontains(msg, 'yes') and locations[talkState[talkUser]] then
-- Add the mark
doPlayerAddMapMark(cid, locations.talkState[talkUser].pos, locations.talkState[talkUser].mark, locations.talkState[talkUser].say)
-- We're done
npcHandler:say('Here you are.', cid)
return true
end
-- Loop through locations
for _,v in pairs(locations) do
-- If keyword matches key
if msgcontains(msg, v) then
selfSay('Do you want me to add a mapmark where the ' .. locations[v].say .. '?', cid)
-- Save state thingy and return
talkState[talkUser] = v
return true
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
As stated earlier, this might not work so yeah... report the possible errors
Last edited: