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

Lua Rented Horse Script

hasbro

Member
Joined
Feb 15, 2009
Messages
286
Reaction score
6
Hello,
I 'am here again, today i have other script i have one doubt about the function os.time , can someone recommend for me a website to i study this functions?
I create this script thinking on world change like tibia.com..
If 30 mounts hunted in one day, anything can rented more on this day, and mount is removed on one day..You can use this mount on one day.

Follow my bad script rs..


NPC...
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local days =  1 * 24 * 60 * 60

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

function horse(cid, message, keywords,parameters,node)
	if(not npcHandler:isFocused(cid)) then
		return false
    end
    if getGlobalStorageValue(15906) == 30 then
    if getGlobalStorageValue(15906) > 30  then
    doPlayerAddMount(cid, 10)     
     npcHandler:say('Now you have a rented horse for the next 24hours..', cid)
      time = os.time() + days
    setGlobalStorageValue(15905, time) 
    setGlobalStorageValue(15906, 1) 
    else
    doPlayerSendCancel(cid, "All mounts is rented on this moment.Try Tomorrow.")
    end
    end
    end
    
    
local node1 = keywordHandler:addKeyword({'mount'}, horse, {npcHandler = npcHandler, onlyFocus = true, reset = true})

Now CreatureScript to check time and remove Mount..
LUA:
function onLogin(cid) 
if getPlayerStorageValue(cid, 13540)  - os.time() <= 0 then
doPlayerRemoveMount(cid ,10)
doPlayerSendTextMessage(cid, 21, "You Rented Horse Mount finish.")
end
end
 
Yes but after i talk npc i dont have this storage, this is limit player rent more 1 time ...right?
I change the script , can you look this is right?
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local days = 1 * 24 * 60 * 60
local requiredTimeLength = 1*24*60*60
 
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
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
    end
	if msgcontains(msg, 'rent') then
		selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
	end
	if msgcontains(msg, 'yes') then
		if (os.time() - getPlayerStorageValue(cid, 19006)) < requiredTimeLength then
			if doPlayerRemoveMoney(cid, 500) then
				doPlayerAddMount(cid , 437)
				local startTime = os.time() + days
				setPlayerStorageValue(cid, 19006, startTime)
				selfSay('Now you have mount.', cid)
			else 
				selfSay('Sorry, you don\'t have money.', cid)
			end
		else
			selfSay('You already have this mount.', cid)
		end
	end
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

- - - Updated - - -

Now i solved the problem but the other way... But the player can say transport to go the other npc, or rent to rent horse..but how i add transport on the script...
I add but this mod is wrong..
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local storage = 18600;
local startTime = os.time()
 
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
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if msgcontains(msg, 'rent') then
		selfSay('Do you want to rent a horse for one day at a price of 500 gold?', cid)
	end
	if msgcontains(msg, 'yes') then
		 if not getPlayerMount(cid, 25) then 
		 if doPlayerRemoveMoney(cid, 500) then
		doPlayerAddMount(cid,25)
        setPlayerStorageValue(cid, storage, startTime)
        selfSay('I\'ll give you one of our experienced ones. Take care! Look out for low hanging branches.', cid)
		else
		selfSay('Sorry, you are too poor. I\d rent one to you for free but I\m afraid you might be desperate enough to eat the horse, sorry.', cid)
		end
		else 
		selfSay('You already have this mount.', cid)
	end
	end
end
if msgcontains(msg, 'transport') then
	selfSay('We can bring you to Thais with one of our coaches for 125 gold. Are you interested?', cid)
	end
if msgcontains(msg, 'yes') then
if doPlayerRemoveMoney(cid, 125) then
doTeleportThing(cid, newpos)
else
selfSay('You don\'t have enough money.', cid)
end
end
if msgcontains(msg, 'no') then
selfSay('You have no idea what you are missing.', cid)
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Back
Top