• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

City Guide (adding mapmarks to locations) ANOTHER VERSION

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
LUA:
local locations = {
    tools      = {title = 'The tool shop', say = 'tool shop is', mark = MAPMARK_SHOVEL, pos = {x=1000, y=1000, z=7}};
}
Say we want to add a new location, this time a rotworm spawn. We'd add this to the array.
LUA:
rotworms  = {title = 'Rotworm spawn', say = 'rotworms are', mark = MAPMARK_TICK,     pos = {x=1500, y=1500, z=7}};
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
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:
For the lua i ran through lua demo to check for structure errors:

Lua: demo

Its a really helpful tool and provides easy answers like the error with expected ")"
 
I can't declare multidimensional associate arrays that way? I read something about tables and crap a long time ago, something needed for this task or did I screw up the syntax somewhere?
 
Its a bit out of my league correcting and hiving dupport for lua atm, still learning - my minimap 1 was my first working script. I just followed lua.org tutorial n applied tibias functions.

I assumed you could use the arrays like that but idk enough to help, just the demo thing on the lua site is good to test syntax. Hope it helps alittle. Wish i could help more

- - - Updated - - -

Giving support* (damn phone)
 
Removed the quotations('tools' =) and it stopped bitching at me :D. Mindrage said something about it earlier, should probably have paid more attention :<
 
Ahh didnt notice that either and i was looking for errors ;)
 
Im getting an error on line 33, here is my script

Code:
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end


local locations = {
mayor  = {title = 'Mayor', say = 'The Mayor is', mark = MAPMARK_TICK,     pos = {x=1056, y=1029, z=6}


};
}


 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'mayor') or msgcontains(msg, 'bobbie') or msgcontains(msg, 'sewerwork') or msgcontains(msg, 'sewer')) or msgcontains(msg, 'sewer work') then
		selfSay('Do you want me to add a mapmark where the Mayor, Bobbie, is?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		doPlayerAddMapMark(cid,config.mayor,MAPMARK_STAR,"Mayor")
                npcHandler:say('Here you are.', cid)

line 33 is the "doPlayerAddMapMark" line, second last one. I am using OTServ r.6052 8.60 is that a problem with this script? Is there anyway to make this script work with my server or will it only work with TFS?
 
It's for TFS, guess I missed mentioning that :p
 
Back
Top