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

Action Rl Wagon system + NPC

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
186
Features :(nothing much)
1- Easy configure
2- Wagon system works like the rl one
3- friendly npc, respond different according to your status.
4- if you are subscribed and greeted the npc you get info when your subscription ends


Installing:
goto actions-->scripts--> make new wagons.lua
Lua:
local positions = {
				--[[ Here is how it goes if player clicked the wagon which is on pos1 then he goes to that on pos2 and vice-versa]]--
					[1] = { pos1 = {x=94,y=114,z=7}, pos2 = {x=91,y=123,z=7} },   
					[2] = { pos1 = {x=94,y=119,z=7}, pos2 = {x=83,y=123,z=7} }
}
local days = 1182930		--empty storage, must be the same as the one in the npc file

function isWalkable(pos)
	if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
	for i = 0, 255 do
		pos.stackpos = i
		local tile = getTileThingByPos(pos)
		if tile.itemid ~= 0 and not isCreature(tile.uid) then
			if hasProperty(tile.uid, 2) or hasProperty(tile.uid, 7) then
				return false
			end
		end
	end
	return true
end
function doTeleportToClosestFree(cid,pos, x, y)
	local places = getArea(pos, 1, 1)
	for i = 1,#places do
		if isWalkable(places[i],false,true) then return doTeleportThing(cid,places[i]) and doSendMagicEffect(places[i],10) and true end
	end
	return false
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local Teleport_to,p = false,toPosition
	if getPlayerStorageValue(cid,days) < os.time() then return doPlayerSendCancel(cid,getPlayerStorageValue(cid,days) > 0 and "Your subscription have ended." or "You havn't subscribed yet.") and doSendMagicEffect(p,2) end
	for k,v in pairs(positions) do
		if doComparePositions(p, v.pos1) or doComparePositions(p, v.pos2) then Teleport_to = doComparePositions(p, v.pos1) and v.pos2 or v.pos1 break end
	end
	if not Teleport_to then return doPlayerSendCancel(cid,"wagon is out of service.") and doSendMagicEffect(p,2) end	
	if not doTeleportToClosestFree(cid,Teleport_to, 1, 1) then return doPlayerSendCancel(cid,"You need to inform wagon master about this rail block.") and doSendMagicEffect(p,2) end
	return true
end

goto actions-->actions.xml
XML:
<action itemid="7131" event="script" value="wagons.lua"/><!-- you put the wagon id you use-->


goto npc--> make new lokur.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Lokur" script="wagon.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="150" head="79" body="113" legs="105" feet="86" addons="0"/>
</npc>

goto npc--scripts --> make new wagons.lua
Lua:
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
--[[Editable]]--
local customer = 11998  ---empty storage
local days = 1182930		--empty storage, must be the same as the one in the action file

local  add_days = 7  -- amount of days added per ticket
local price = 250		-- ticket price in gp

--[[Script]]--
function greetCallback(cid)
	talkState[cid] = 0
	if getPlayerStorageValue(cid,customer) <1 then
		selfSay("Ah ".. getCreatureName(cid).." there, right!? I have been expecting you. Seems you are interested in my little wagon system , aren't you?",cid)
	else
		if getPlayerStorageValue(cid,days) > os.time() then
			selfSay("Welcome again ".. getCreatureName(cid).."! I bet you want to ask when your subscription will end right? ",cid)
		else
			selfSay("Welcome back ".. getCreatureName(cid).."! I see your subscription have ended, do you want to re-subscribe?",cid)
		end
	end
	return npcHandler:addFocus(cid)
end
function farewellCallback(cid)
	if getPlayerStorageValue(cid,customer) < 1 then selfSay(talkState[cid] == 0 and "Humm..! Okay then, maybe you would subscribe later. Bye Bye!" or "Humm..! You dont have enough money, come back later.",cid) end
	return npcHandler:releaseFocus(cid)
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
	
	if getPlayerStorageValue(cid,customer) < 1 then
		if  msgcontains(msg, 'yes') and talkState[talkUser] == 0 then
			selfSay("Well Well! You can take a ".. add_days.." days subscribtion for ".. price .." gold coins. So is it a deal?",cid)
			talkState[talkUser] = 1
		elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
			if doPlayerRemoveMoney(cid,price) then
				setPlayerStorageValue(cid,customer,1)
				setPlayerStorageValue(cid,days,os.time()+(add_days*24*60*60))
				selfSay("You have successfuly subscribed for ".. add_days.." days , hope you don't have any complains.",cid)
				talkState[talkUser] = 0
				npcHandler:unGreet(cid)
			else
				npcHandler:unGreet(cid)
			end
		elseif msgcontains(msg, 'no') then
			npcHandler:unGreet(cid)
		end
	
	elseif getPlayerStorageValue(cid,customer) > 0 and getPlayerStorageValue(cid,days) > os.time() then
		if  msgcontains(msg, 'yes') and talkState[talkUser] == 0 then
			selfSay("Your subscribtion will end on "..os.date("%A %d of %B at %X",getPlayerStorageValue(cid,days))..", you can renew it by then.",cid)
			npcHandler:unGreet(cid)
		elseif msgcontains(msg, 'no') and talkState[talkUser] == 0 then
			selfSay("I wonder why you came then. You know you can't renew unless your current subscribtion ends. Bye Bye!",cid)
			npcHandler:unGreet(cid)
		end
	elseif getPlayerStorageValue(cid,customer) > 0 and getPlayerStorageValue(cid,days) < os.time() then
		if  msgcontains(msg, 'yes') and talkState[talkUser] == 0 then
			if doPlayerRemoveMoney(cid,price) then
				setPlayerStorageValue(cid,days,os.time()+(add_days*24*60*60))
				selfSay("You have renewed your subscription with more ".. add_days.." days.",cid)
				npcHandler:unGreet(cid)
			else
				selfSay("Humm..! You dont have enough money, come back later.",cid)
				npcHandler:unGreet(cid)
			end
		elseif msgcontains(msg, 'no') and talkState[talkUser] == 0 then
			selfSay("Maybe later then. Bye Bye!",cid)
			npcHandler:unGreet(cid)
		end
		
	
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It works in 0.4..... tested in latest rev.

i only get this message:
You need to inform wagon master about this rail block.

This means there is no walkable place where the player can be tped to around the tp place...
 
This because your edits was wrong. I think it is too simple , you need to place the wagon position in both places not the place you would be teleported to..

So lets say a wagon at depot teleport to other wagon at temple, so :

pos1 -> will be wagon pos in temple/depot ( not the place you would be tped to, the wagon place)
pos2-> will be the wagon pos in the other place..
 
I tried making more than 2 but it won't work :(

 
Last edited:
you mean you cant add more tables? to create new wagons,

if so , try to put a "," after each table but not the last one

Lua:
local t = {
                 [] = {},
                 [] = {},
                 [] = {},
                 [] = {},
                 [] = {}



}
 
Back
Top