• 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!

New NPC System, 100% lua

Santy

Member
Joined
Aug 14, 2007
Messages
654
Reaction score
22
Code:
luaSys_config = {
	john = {
		basic = { 
			farewell = "Feel free to come back and see me again if you need anything!",
			greet = "Hello |PLAYERNAME|! Would you like to know some tips? Just let me know if you need {help}.",
			walkAway = "See you later.",
			idle = "Hello? Ok... please say {hi} to me again if you need {help}.",
			appear = "Oh, hey there! Need any help?",
			closeChannel = "Hmph!"
		},
		keywords = { -- "greet" and "farewell" are reserved
			name = "My name is John.",
			job = "I rake leaves from the streets at night.",
			--[[
			quest = {"getStorageReturnMessage", {"cid", 1337, { -- cid, storage, messagesArray
				["-1"] = "I don't have any quests to send you on right now, sorry.",
				["0"] = "Hey... There has been a flying bananapenis bothering me lately. Niggercocks?"
			}}},
			]] -- equivalent to below, both are working ways to do it
			quest = function (cid)
				msg = {
					["-1"] = "I don't have any quests to send you on right now, sorry.",
					["0"] = "Hey... There has been a flying bananapenis bothering me lately. Niggercocks?"
				}
				storage = 1337
				if(msg[tostring(getPlayerStorageValue(cid, storage))]) then
					return selfSay(msg[tostring(getPlayerStorageValue(cid, storage))], cid)
				end
				return error("Player storage value wasn't in array.")
			end,
			help = "Fucking go experiment man, ain't nobody going to tell you how to live a life."
		},
		linkage = {
			greet = {"hi", "hello", "greetings"},
			farewell = {"bye", "laters", "cya"},
			help = {"support", "items plx"}
		},
		shop = {
			message = "Pretty nice, right?",
			words = {"wares", "trade"},
			endTrade = "It was a pleasure doing business with you.",
			onBuy = {
				success = "Thanks for the money!",
				needMoney = "You don't have enough money to buy that.",
				needSpace = "Sorry, but you don't have space to take it.",
				needCapacity = "I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary."
			},
			onSell = {
				success = "Here you are.",
				needItem = "No item, no deal."
			},
			items = {
				{id=2160, subType=0, buy=10000, sell=10000, name="Test1"},
				{id=2152, subType=0, buy=100, sell=100, name="Test2"},
				{id=2148, subType=0, buy=1, sell=1, name="Test3"},
				{id=2173, subType=0, buy=10000, sell=5000, name="Test4"}
			}
		}
	}
--	shop = nil
}

That's the structure, you'd just have to add that piece of code to a references file, and make a new xml file for the npc. It's all in lua as you can see. Everything in it is optional, if you want to disregard the shop part, just delete it.
There's a prototypical XML file for all of the new npcs, in which you'd just have to edit the name, outfit, and whatnot. All XML files should refer to the same lua script, which holds the functioning.

I'm thinking about selling this on the Market Place once its done. Any suggestions for the system?
 
Last edited:
Thats good, actually I self would use this system, but it must uses all functions which calls on return, and that system would fit best for basic knowledge ot user, for advanced npcs it wont fit good at all. And nobody would like to recode all their npcs to this npc system. You could offer it only for custom and not started projects, to start script npcs with your npc system. This means actually nobody will be very interested.
 
@Erikas
No, functions it uses don't need to return any value. This is even better for advanced npcs, you just have to make one new function if it's very advanced. However, I'm adding generic functions to ease certain processes, such as the one displayed with func getStorageReturnMessage. You also don't have to recode your npcs to this system, you just have to add new ones linking them to the system's lua file.

I'd also prefer if only advanced users used this function, as it'll come handy the most to them. Specially when making npcs in bunches.

@Outfit
lolwut?
 
I just showed a configuration code in my first post. There'd be different functions for different kind of npcs, such as doRemoveItemAndGiveStorageValue, and that sort of stuff.
 
Maybe nobody noticed, but the NPC says he's a cock sucker lol

appear = "Hey there! I'm a cocksucker! Hen are very fun to taste!",
 
I was thinking more of a Tree.

Lua:
NPC = CreateNPC()

NPC.TalkingLimit = 0 -- Can Talk to Infinite amount of people.
NPC.MustFocus = 0 -- Can Focus on one person.
NPC

TalkTree = {
	["hi"] = 
	{
		{NPC_RANDOMMESSAGE, "Hello Sir |Player Name|", "Greetings Mr |Player Name|"},
		["Offer"] = 
		{
			"Here are my goods",
			{NPC_SHOWSHOP, {1324,4324,1232,1232,3232})
		},
		["Quest"] =
		{	NPC_CONDITION,
			function(cid)
				if getPlayerStorageValue(cid, 111232) > 1 then 
					return "gotQuest" 
				else
					return "DoesNotHaveQuest"
				end
			end,
			["gotQuest"] = 
			{
				"Yes, I could make you a fancy hat and a fancy back. \n but that requires flamingo feathers, can you get me some?",	
				["Yes"] =
				{
					"Splendid!, They are located at the Safari, Watch out for poachers!",
					function(cid)
						setPlayerStorageValue(cid, 111232, 1)
					end
				},
				["No"] = 
				{
					"Ah, Too bad for you, i make excellent hats.",
					{NPC_GOTO_ROW,"Hi","Quest"}
				}
			},
			["DoesNotHaveQuest"] =
			{
				"Do you have my feathers now?",
				
				["Yes"] =
				{NPC_CONDITION,
					function(cid)
						if getPlayerItem(cid, 3423) then
							return "Got Items"
						else
							return "Does no have items"
						end
					end,
					
					["Got Items"] = 
					{
						{NPC_DELAYMESSAGE, 3000, "And here you go, Here is your Hat"},
						function(cid)
							doPlayerGiveAddon(cid, 145, 3)
							doCreatureSetOutfit(NPC, {blablabla})
						end,
						{NPC_GOTO_ROW, "Hi", "Quest"}
					}
				}
			}	
		}	
	},
[NPC_MESSAGE_BUSY] = "Not now |PlayerName|, Im busy can't you see!"
}

TalkTreeNight = 
{
["Hi"] = "What, Leave me alone, its way past midnight!",
[NPC_MESSAGE_DEFAULT] = "Get away, its too dark!",
}


	
NPC.OnAppear = function(cid)

end

NPC.OnDisappear = function(cid)

end

NPC.onTalkedTo = function(cid, type, message)
	if GetTibianTime() > 2000 then
		NPC.TalkWith(cid, type, message, TalkTreeNight)	
	else 
		NPC.TalkWith(cid, type, message, TalkTree)
	end
end

NPC.OnThink = function()


end

Its maybe strange that i dont have "onThink" and those function inside. They are defined with a meta table when added :3
NPC returns the NPC Cid.
 
@up
Mine works kind of like yours. Only mine is much more compact, effective and briefer. It also includes all those functions, but in a lib file. I honestly don't like your structure. Too messy.

@Evil Mark
Yes! This NPC is supposedly a farmer, which enjoys the taste of hen obtained from the extraction procedure that sucking can be.
 
Last edited:
Update: System is done, and upgraded. It already loads npcs from the config file and all functions are working correctly.
I'm now going to add walkpaths for the npc, maximum walk distance, and various functions, enhancing the personalization of an npc through this system.

Credits to MindRage for showing me his structure, gave me the idea to use functions as direct responses from the very config.

Edit: http://otland.net/f485/npc-system-100-lua-154468/
system done.
 
Last edited:
Back
Top