• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Daily Chests System

RStijn

Emulation Addict
Daily Chest System
Allow players to open each spawned chest with specified ID's to be looted only once in a configurable amount of time.
Easy to configure and automatically installs it's table in the character database.
Requires up to date version of Eluna to work.

Features:
  • Choose amount of hours before user can loot again
  • Each object spawn is different chest that can be looted be looted by a player once
  • Limit per account or per character
  • Supports multiple gameobjects
  • Customize already looted message in chatbox

View or download script here

kY3JkZC.jpg
 
Last edited:

EpiNemx

Respected Member
For some reason I can open as many chests as I want. I am using 500501 as my game object ID in the Lua.

Code:
2015-04-19_20:50:31 ERROR lua_scripts/RandomChests.lua:60: attempt to call method 'GetLootRecipient' (a nil value)
 

Rochet2

Moderator / Eluna Dev
For some reason I can open as many chests as I want. I am using 500501 as my game object ID in the Lua.

Code:
2015-04-19_20:50:31 ERROR lua_scripts/RandomChests.lua:60: attempt to call method 'GetLootRecipient' (a nil value)

The reason is that the method was added to Eluna source from a PR from him some time ago.
However the recent version is not yet "released". If you download the latest Eluna repository you will have the method, but not if you use the recommended installation methods.

The method is available soon.
 

EpiNemx

Respected Member
The reason is that the method was added to Eluna source from a PR from him some time ago.
However the recent version is not yet "released". If you download the latest Eluna repository you will have the method, but not if you use the recommended installation methods.

The method is available soon.

Ah this explains it, i'll have to sit tight and wait for a while then. ^_^ thanks
 

dpqks84

Member
I got this errer and doesn't work !!

ERROR lua_scripts/loot_cheasted.lua:52: attempt to index local 'player' (a nil value)

I'm using quite latest trinity_eluna core TDB 335.59 .. Mostly other scripts work fine and I can fix a little bit with my noob skill but I don't know why this error occurs... I think everything is quite fine. it creates db table but didn't write sth on the table even I tried loot a chest on the game.
 

Rochet2

Moderator / Eluna Dev
ERROR lua_scripts/loot_cheasted.lua:52: attempt to index local 'player' (a nil value)

I'm using quite latest trinity_eluna core TDB 335.59 .. Mostly other scripts work fine and I can fix a little bit with my noob skill but I don't know why this error occurs... I think everything is quite fine. it creates db table but didn't write sth on the table even I tried loot a chest on the game.

Made a PR to the script to fix the error:
https://github.com/RStijn/Eluna-Lua-Scripts/pull/1
 

slp13at420

Mad Scientist
are you getting any errors in your server console window during startup or when you try to use it?
if so post some readable screenshots of the errors. :D
 

jimteck

Emulation Addict
Script not load!Безымянный.jpg
Code:
-- Name: 	Daily Chest System
-- Details:	Limits the amount of time between the same chest being opened by the same player.
-- Usage:	Modify the configuration below to suit your needs.
-- Website: [url]https://github.com/RStijn[/url]

-- Config
local CHEST = {
	-- GameObject ID's you want to limit per player.
	500000,
	500001,
	190702,
} 
-- set chest gameobject ID's at bottom
local HOURS = 24 			-- How many hours before a player can loot again 
local ACCOUNTLIMIT = true 	-- TRUE: Limits entire account. FALSE: Limits only this character
-- Message to show when player already looted a chest recently
local ALREADYLOOTED = "You already looted this chest. Please check back within 24 hours."


-- Functions
local function registerNewLoot(pid, goGuid)
	CharDBQuery("INSERT INTO `looted_chests` (`player`, `objectGuid`, `lootTime`) VALUES ('".. pid .. "', '" .. goGuid .. "', UNIX_TIMESTAMP());")
end

local function canLoot(pid, goGuid)
	local q = CharDBQuery("SELECT `id`, `lootTime` FROM `looted_chests` WHERE `player` = " .. pid .. " AND `objectGuid` = " .. goGuid .. ";")
	local now = tonumber(CharDBQuery("SELECT UNIX_TIMESTAMP()"):GetRow(1)["UNIX_TIMESTAMP()"])
	
	-- if possible
	if q == nil then
		return true
	elseif tonumber(q:GetRow(1)["lootTime"]) + (HOURS * 3600) < now then
		CharDBQuery("DELETE FROM `looted_chests` WHERE `id` = "..q:GetRow(1)["id"])
		return true
	else
		return false
	end
end

local function blockLoot(player, go)
	go:SetLootState(3)
	player:SendBroadcastMessage(ALREADYLOOTED);
end

local function handleLoot(player, go)
	-- Get ID's
	local pid = 0
	if ACCOUNTLIMIT then
		pid = player:GetAccountId()
	else
		pid = player:GetPlayerGUID()
	end	
	local goGuid = go:GetGUIDLow()
	
	-- Handle loot
	if canLoot(pid, goGuid) then
		registerNewLoot(pid, goGuid)
	else
		blockLoot(player, go)
	end
end

local function onLootStateChanged(event, go, state)
	if state == 2 then
		local player = go:GetLootRecipient()
		if player then
			handleLoot(player, go)
		end
	end
end

-- Register chests
for k, chest_entry in ipairs(CHEST) do
  RegisterGameObjectEvent(chest_entry, 9, onLootStateChanged)
end
 
Last edited:

slp13at420

Mad Scientist

saying script not load and then not telling us what the file name of the script is , is well lacking the info.
`!Cartmanson,, you lacka the info!` `nah uh I don't lacka the info masterson!`

just in that screen shot I see 4 scripts throwing errors on startup.
help us to help you :)


on a side note I looked into loading this. added the table to my characterDB.
then started up my server with this script and 1 other , a teleporter script.
everything loaded smooth no err's on loading.
so I spawned a chest id:4096 and added it to the table `CHEST`. restarted my server.
again it loaded fine no errors to see.
so I open the chest and grab the goods then closed it back up.
then opened again .. it opened and returned no response like "You already looted this chest. Please check back within 24 hours."; it should.

so I slapped a few prints in the code
here:
Code:
[COLOR="#808080"]
local function onLootStateChanged(event, go, state)
[COLOR="#DAA520"]print("STATE:"..state);[/COLOR]
	if state == 2 then
		local player = go:GetLootRecipient();
[COLOR="#DAA520"]print("PLAYER:"..go:GetLootRecipient());[/COLOR]
		if player then
			handleLoot(player, go)
		end
	end
end
[/COLOR]

and here:
Code:
[COLOR="#808080"]
-- Register chests
for _,chest_entry in ipairs(CHEST) do
[COLOR="#DAA520"]print(chest_entry);[/COLOR]
  RegisterGameObjectEvent(chest_entry, 9, onLootStateChanged)
end
[/COLOR]

all the gob's get Registered to Event 9. the state would change from 1 to 2 like I was expecting it too , more guessing at what it should be doing lol.
but every time I would loot the chest , restart after restart , in the function `OnLootStateChanged(event, go, state)` `go:GetLootRecipient()` would return a nil value every time 'attempt to concatenate a nil value` . so if no player then do nothing and ofc the sql table wont be updated so nothing new there.
n it looks like that's been an issue before.

I tried :
open then close , open and loot all.
open loot partial, close , open and loot rest.
 
Last edited:

jimteck

Emulation Addict
So i have error again,you can see log
 

Attachments

  • Bezyimyannyiy_13206411012.jpg
    Bezyimyannyiy_13206411012.jpg
    224.2 KB · Views: 53
Last edited:

jonmii

Enthusiast
For me, its not limiting the loot.
I can loot from chest that i created the quantity i want.
Also not error logs
 

coffzor

Member
Due to the bug with getting the PID from the looter returning as NIL, I simply rewrote this to work with gossip instead of a gameobject.

Note: This is also a stripped version, only one daily reward can be entered. You could rewrite it to work with a gameobject using gossip etc.

Code:
-- Create sql table if needed
CharDBQuery("CREATE TABLE IF NOT EXISTS `dailyreward` (`id` int(11) NOT NULL AUTO_INCREMENT, `player` int(11) NOT NULL, `lootTime` int(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;")



local UnitEntry = 50004
local HOURS = 12
local ACCOUNTLIMIT = true
local ALREADYLOOTED = "Please wait 12 hours before claiming daily rewards again."

local function registerNewLoot(pid, goGuid)
	CharDBQuery("INSERT INTO `dailyreward` (`player`, `lootTime`) VALUES ('".. pid .. "', UNIX_TIMESTAMP());")
end

local function blockLoot(player, go)
	player:SendBroadcastMessage(ALREADYLOOTED);
end

local function canLoot(pid, goGuid)
	local q = CharDBQuery("SELECT `id`, `lootTime` FROM `dailyreward` WHERE `player` = " .. pid .. ";")
	local now = tonumber(CharDBQuery("SELECT UNIX_TIMESTAMP()"):GetRow(1)["UNIX_TIMESTAMP()"])
	
	-- if possible
	if q == nil then
		return true
	elseif tonumber(q:GetRow(1)["lootTime"]) + (HOURS * 3600) < now then
		CharDBQuery("DELETE FROM `dailyreward` WHERE `id` = "..q:GetRow(1)["id"])
		return true
	else
		return false
	end
end

local function handleLoot(player, go)
	-- Can claim?
	if canLoot(pid, goGuid) then
		registerNewLoot(pid, goGuid)
		player:ModifyMoney(1000000) --Add 100 gold
		player:AddItem(29434, 5) -- Add 5 Badge of Justice
	else
		blockLoot(player, go)
	end
end

local function OnGossipHello(event, player, unit)
    -- Show main menu
	player:GossipMenuAddItem(0, "Claim Daily Reward", 0, 0)
	player:GossipSendMenu(1, unit)
	
	pid = player:GetAccountId()
end	

local function OnGossipSelect(event, player, unit, sender, intid, code)
    if (intid == 0) then
        handleLoot(player, go)
    end
    
    player:GossipComplete()
end

RegisterCreatureGossipEvent(UnitEntry, 1, OnGossipHello)
RegisterCreatureGossipEvent(UnitEntry, 2, OnGossipSelect)
 
Top