• 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
 
I'm not understanding what you're asking for, I assume you want to check whether a day has passed or not.

os.time() returns the time from the operating system, measured in seconds since the beginning of 1970.
You can test out the function here and see what it gives you: Lua code - 1 line - codepad

You could give the player a specific time in seconds (os.time) as a storagevalue.
To check it at log-in: you would subtract the storagevalue from os.time() and
compare that to the required length of time in seconds (in your case, it is 60*60*24*1).

A Lua-based code example:
LUA:
storage = 10000;
startTime = os.time()
setPlayerStorageValue(cid, storage, startTime)

Then, when you check at onLogin:
LUA:
requiredTimeLength = 1*24*60*60
storage = 10000;
if (os.time() - getPlayerStorageValue(cid, storage)) >= requiredTimeLength then
it has been at least 24 hours since

I'm sorry if I'm not able to understand what you're asking for, you're welcome post back if you have anything else ask.
 
Yes, but my doubt is on after 30 horse rented how i cancel the other orders....I can set globalstorage and each horse rent i put +1 global storage...and after 30 i cancel the other other for 1 day, but how i can reset the globalstorage every 00:00?
 
Try this:
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
		doPlayerAddMount(cid, 10)     
		npcHandler:say('Now you have a rented horse for the next 24 hours..', cid)
		local time = os.time() + days
		setCreatureStorageValue(cid, 15905, time) 
		setGlobalStorageValue(15906, math.max(0, getGlobalStorageValue(15906)) + 1) 
	else
		doPlayerSendCancel(cid, "All mounts is rented on this moment. Try Tomorrow.")
	end
end
 
 
local node1 = keywordHandler:addKeyword({'mount'}, horse, {npcHandler = npcHandler, onlyFocus = true, reset = true})

and add a globalevent on time="00:00" (there should be an example in your globalevents) which calls:
LUA:
setGlobalStorageValue(15906, 0)
 
Summ, there's no problem here.. He just wants to learn the function "()os.time"..

Don't you read the posts?
Yes, but my doubt is on after 30 horse rented how i cancel the other orders....I can set globalstorage and each horse rent i put +1 global storage...and after 30 i cancel the other other for 1 day, but how i can reset the globalstorage every 00:00?
 
Hello,
I create one npc about mount, and i dont have idea , i say rent and this no answer me...i tryed everything ...

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 creatureSayCallback(cid, message, keywords, parameters, node)
	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)
      elseif msgcontains(msg, 'yes') then
	 doPlayerRemoveMoney(cid, 500) 
     doPlayerAddMount(cid , 10)
	 local time = os.time() + days
	 setCreatureStorageValue(cid, 15905, time)
     setPlayerStorageValue(15906, math.max(0, getPlayerStorageValue(15906)) + 1)  
	 npcHandler:say('Now you have mount.', cid)
	 else 
	 selfSay('Sorry, you don\'t have money.', cid)
     end
     end
 
     
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hello,
I create one npc about mount, and i dont have idea , i say rent and this no answer me...i tryed everything ...

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 creatureSayCallback(cid, message, keywords, parameters, node)
	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)
      elseif msgcontains(msg, 'yes') then
	 doPlayerRemoveMoney(cid, 500) 
     doPlayerAddMount(cid , 10)
	 local time = os.time() + days
	 setCreatureStorageValue(cid, 15905, time)
     setPlayerStorageValue(15906, math.max(0, getPlayerStorageValue(15906)) + 1)  
	 npcHandler:say('Now you have mount.', cid)
	 else 
	 selfSay('Sorry, you don\'t have money.', cid)
     end
     end
 
     
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Change
LUA:
function creatureSayCallback(cid, message, keywords, parameters, node)
to this
LUA:
function creatureSayCallback(cid, type, msg)
 
Thanks, but now i try very times , but i cant if the player have this mount you cant rent more or you dont have money but dont work good...
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 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 getGlobalStorageValue(15911) == 1 then
	  if doPlayerRemoveMoney(cid, 500) then
	 doPlayerRemoveMoney(cid, 500) 
     doPlayerAddMount(cid , 437)
	 local time = os.time() + days
	setCreatureStorageValue(cid, 15912, time) 
	setGlobalStorageValue(15911, math.max(0, getGlobalStorageValue(15911)) + 1)  
	  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())
 
If I understood you correctly, after 1 day, you want them to mount it again?

So, you need to do an onLogin check.
You can check my post on the first page if you want to do it my way.
 
Login is not problem , i create this npc to add mount for 24hours, but his dont work fine, i create think about if you have mount you cant horse or you dont have money you cant rent horse, but npc dont work ..
 
I had to re-tab the code, looks like crap and makes it difficult for people to read it.

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 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 getGlobalStorageValue(15911) == 1 then
			if doPlayerRemoveMoney(cid, 500) then
				doPlayerRemoveMoney(cid, 500) 
				doPlayerAddMount(cid , 437)
				local time = os.time() + days
				setCreatureStorageValue(cid, 15912, time) 
				setGlobalStorageValue(15911, math.max(0, getGlobalStorageValue(15911)) + 1)  
				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())

Does message show when you say 'rent'?
 
I say rent appear this..
Do you want to rent a horse for one day at a price of 500 gold?
but i say "yes" and appear "You already have this mount."
 
You get that message when this line fails (as you can see, thanks to tabbing):
LUA:
if getGlobalStorageValue(15911) == 1 then

You need to reset the globalStorageValue back to 1.
 
Back
Top