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

Plum farming

Muzzy

New Member
Joined
Jul 8, 2008
Messages
125
Reaction score
1
Hey!

I've been trying to get a plum tree script to work, where you basically either use or use with a tool on a plum tree to harvest a randomized(1-4) amount of plums.

What I've come across is the following:

Code:
function onUse(cid, item, frompos, item2, topos)
            doTransformItem(item.uid,4008)
            doPlayerAddItem(cid,2675,math.random(5))
            doDecayItem(item.uid)
      return 1 
end

This is an orange tree version of it, but I can easily replace it with a plum tree. The problem occurs when I click repeatedly, since it'll give me an unlimited amount of plums. How do I set a cooldown on this?

The second script I found was:

Code:
local cfg = {
    palm_id = 1234,
    coconut_id = 2345,
    count = 10, -- How many coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
            doPlayerAddItem(cid, cfg.coconut_id, cfg.count)
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
        end
    end
return true
end

This also works if I alter it, but it'll only give me one(since I don't know what I need to write to make it randomized). It also applies to all plum trees, meaning if I use one tree and I get a plum I can't use any other plum tree on the server.

An answer to either one of those questions would be answered with a big hug.

Thanks!
 
Lua:
local cfg = {
    palm_id = 1234,
    coconut_id = 2345,
    count = 10, -- Max amount coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
            doPlayerAddItem(cid, cfg.coconut_id, math.random(cfg.count))
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
        end
    end
return true
end

this will give you a random count as for the disabling the use of all palm tress thats cause it goes by the id of the palm tree not uniqueid or actionid
 
Lua:
local cfg = {
    palm_id = 1234,
    coconut_id = 2345,
    count = 10, -- Max amount coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
            doPlayerAddItem(cid, cfg.coconut_id, math.random(cfg.count))
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
        end
    end
return true
end

this will give you a random count as for the disabling the use of all palm tress thats cause it goes by the id of the palm tree not uniqueid or actionid

Oh, thanks for the 'random' fix!

Do you think the use of all palm trees would be fixed if I added a second tree sprite and replace it with it it'd work?
 
You can add another item id, and make it so if you use that one next that the previous one will free up.
here ill make it for you:
Lua:
local cfg = {
    palm_id = 1234,
	palm_id2 = XXXX,
    coconut_id = 2345,
    count = 10, -- Max amount coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
	storage2 = 3457
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
	   local add = math.random(cfg.count)
            doPlayerAddItem(cid, cfg.coconut_id, add)
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage2) > 0 then
					setPlayerStorageValue(cid, storage2, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage.." seconds.")
		end
	elseif item.itemid == cfg.palm_id2 then
		if getPlayerStorageValue(cid, cfg.storage2) <= os.time() then
		local add = math.random(cfg.count)
			doPlayerAddItem(cid, cfg.coconut_id, add)
                        setPlayerStorageValue(cid, cfg.storage2, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage) > 0 then
					setPlayerStorageValue(cid, storage, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage2.." seconds.")
		end
    end
return true
end
make sure you fill in a tree id for palm2, so basically both will give you the plums not, and if you use one of them then it will take away the exhaust on the other
also make sure you set both of the palm ids in actions.xml
 
You can add another item id, and make it so if you use that one next that the previous one will free up.
here ill make it for you:
Lua:
local cfg = {
    palm_id = 1234,
	palm_id2 = XXXX,
    coconut_id = 2345,
    count = 10, -- Max amount coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
	storage2 = 3457
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
	   local add = math.random(cfg.count)
            doPlayerAddItem(cid, cfg.coconut_id, add)
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage2) > 0 then
					setPlayerStorageValue(cid, storage2, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage.." seconds.")
		end
	elseif item.itemid == cfg.palm_id2 then
		if getPlayerStorageValue(cid, cfg.storage2) <= os.time() then
		local add = math.random(cfg.count)
			doPlayerAddItem(cid, cfg.coconut_id, add)
                        setPlayerStorageValue(cid, cfg.storage2, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage) > 0 then
					setPlayerStorageValue(cid, storage, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage2.." seconds.")
		end
    end
return true
end
make sure you fill in a tree id for palm2, so basically both will give you the plums not, and if you use one of them then it will take away the exhaust on the other
also make sure you set both of the palm ids in actions.xml

Thanks, I'll try that once I get home!

- - - Updated - - -

You can add another item id, and make it so if you use that one next that the previous one will free up.
here ill make it for you:
Lua:
local cfg = {
    palm_id = 1234,
	palm_id2 = XXXX,
    coconut_id = 2345,
    count = 10, -- Max amount coconuts?
    minutes = 120, -- How many minutes before you can use the palm again?
    storage = 3456,
	storage2 = 3457
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == cfg.palm_id then
       if getPlayerStorageValue(cid, cfg.storage) <= os.time() then
	   local add = math.random(cfg.count)
            doPlayerAddItem(cid, cfg.coconut_id, add)
            setPlayerStorageValue(cid, cfg.storage, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage2) > 0 then
					setPlayerStorageValue(cid, storage2, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage.." seconds.")
		end
	elseif item.itemid == cfg.palm_id2 then
		if getPlayerStorageValue(cid, cfg.storage2) <= os.time() then
		local add = math.random(cfg.count)
			doPlayerAddItem(cid, cfg.coconut_id, add)
                        setPlayerStorageValue(cid, cfg.storage2, os.time() + (cfg.minutes * 60 * 1000))
			doPlayerSendTextMessage(cid, 19, "You have gained "..add.." plums.")
				if getPlayerStorageValue(cid, storage) > 0 then
					setPlayerStorageValue(cid, storage, 0)
				end
		else
			doPlayerSendTextMessage(cid, 19, "You are exhausted please wait "..cfg.storage2.." seconds.")
		end
    end
return true
end
make sure you fill in a tree id for palm2, so basically both will give you the plums not, and if you use one of them then it will take away the exhaust on the other
also make sure you set both of the palm ids in actions.xml

Ah, sorry for being unclear. I want plum trees to drop plums, and there's only one plum tree. That's where I'm at right now, do I have to make another tree sprite kinda like blueberry bushes?
 
Back
Top