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

Lua Its possible? Isnt request !

Vrotz

Member
Joined
Apr 7, 2011
Messages
1,071
Reaction score
7
Location
Brazil
Hello,

I've a doubt.

The player bought an item by the ShopSystem. Its possible configure the Shop system and/or Globalevents, for that the even withdraws the item after 30 days? If yes, as it does that?

They are able to teach me?
 
Last edited:
Shop.lua

Code:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 19
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
    local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
    if(result_plr:getID() ~= -1) then
        while(true) do
            id = tonumber(result_plr:getDataInt("id"))
            action = tostring(result_plr:getDataString("action"))
            delete = tonumber(result_plr:getDataInt("delete_it"))
            cid = getCreatureByName(tostring(result_plr:getDataString("name")))
            if isPlayer(cid) == TRUE then
                local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
                local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
                local container_id = tonumber(result_plr:getDataInt("param3"))
                local container_count = tonumber(result_plr:getDataInt("param4"))
                local add_item_type = tostring(result_plr:getDataString("param5"))
                local add_item_name = tostring(result_plr:getDataString("param6"))
                local received_item = 0
                local full_weight = 0
                if add_item_type == 'container' then
                    container_weight = getItemWeightById(container_id, 1)
                    if isItemRune(itemtogive_id) == TRUE then
                        items_weight = container_count * getItemWeightById(itemtogive_id, 1)
                    else
                        items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                    full_weight = items_weight + container_weight
                else
                    full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    if isItemRune(itemtogive_id) == TRUE then
                        full_weight = getItemWeightById(itemtogive_id, 1)
                    else
                        full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                end
                local free_cap = getPlayerFreeCap(cid)
                if full_weight <= free_cap then
                    if add_item_type == 'container' then
                        local new_container = doCreateItemEx(container_id, 1)
                        local iter = 0
                        while iter ~= container_count do
                            doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
                            iter = iter + 1
                        end
                        received_item = doPlayerAddItemEx(cid, new_container)
                    else
                        local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
                        received_item = doPlayerAddItemEx(cid, new_item)
                    end
                    if received_item == RETURNVALUE_NOERROR then
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Você recebeu o '.. add_item_name ..' do Zyzz-War.')
                        db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                        db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                    else
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
                    end
                else
                    doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
                end
            end
            if not(result_plr:next()) then
                break
            end
        end
        result_plr:free()
    end
    return TRUE
end


Login:

Code:
local config = {
	loginMessage = getConfigValue('loginMessage'),
	useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
		doPlayerAddPremiumDays(cid, 2)
		doPlayerSetPromotionLevel(cid, 1)
	end

	local accountManager = getPlayerAccountManager(cid)
	if(accountManager == MANAGER_NONE) then
		local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
		if(lastLogin > 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
			str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
		else
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
	elseif(accountManager == MANAGER_NAMELOCK) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
	elseif(accountManager == MANAGER_ACCOUNT) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
	end

	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	end

     registerCreatureEvent(cid, "kill")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "PlayerLogout")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "deathBroadcast")
     registerCreatureEvent(cid, "DeathBroadcast")
     registerCreatureEvent(cid, "Member")
     registerCreatureEvent(cid, "KillingInTheNameOf")
     registerCreatureEvent(cid, "MageBomb")

	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
	registerCreatureEvent(cid, "SkullCheck")
	end

	registerCreatureEvent(cid, "ReportBug")
	return true
end
 
I added a table with some items ids in case you want the items that expires are only certain items. In case you want all items expires, REMOVE the line 'local itemExpires = {...}'
Lua:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 19
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###

local itemsExpires = {2195, 2472}
local expire = 30 * 24 * 60 * 60
function onThink(interval, lastExecution)
    local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")
    if(result_plr:getID() ~= -1) then
        while(true) do
            id = tonumber(result_plr:getDataInt("id"))
            action = tostring(result_plr:getDataString("action"))
            delete = tonumber(result_plr:getDataInt("delete_it"))
            cid = getCreatureByName(tostring(result_plr:getDataString("name")))
            if isPlayer(cid) == TRUE then
                local itemtogive_id = tonumber(result_plr:getDataInt("param1"))
                local itemtogive_count = tonumber(result_plr:getDataInt("param2"))
                local container_id = tonumber(result_plr:getDataInt("param3"))
                local container_count = tonumber(result_plr:getDataInt("param4"))
                local add_item_type = tostring(result_plr:getDataString("param5"))
                local add_item_name = tostring(result_plr:getDataString("param6"))
                local received_item = 0
                local full_weight = 0
                if add_item_type == 'container' then
                    container_weight = getItemWeightById(container_id, 1)
                    if isItemRune(itemtogive_id) == TRUE then
                        items_weight = container_count * getItemWeightById(itemtogive_id, 1)
                    else
                        items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                    full_weight = items_weight + container_weight
                else
                    full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    if isItemRune(itemtogive_id) == TRUE then
                        full_weight = getItemWeightById(itemtogive_id, 1)
                    else
                        full_weight = getItemWeightById(itemtogive_id, itemtogive_count)
                    end
                end
                local free_cap = getPlayerFreeCap(cid)
                if full_weight <= free_cap then
                    if add_item_type == 'container' then
                        local new_container = doCreateItemEx(container_id, 1)
                        local iter = 0
                        while iter ~= container_count do
                            local it = doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
							if itemExpires then
								if isInArray(itemsExpires, itemtogive_id) then
									doItemSetAttribute(it, "boughtdate", os.time() + expire)
								end
							else
								doItemSetAttribute(it, "boughtdate", os.time() + expire)
							end
                            iter = iter + 1
                        end
                        received_item = doPlayerAddItemEx(cid, new_container)
                    else
                        local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
						if itemExpires then
							if isInArray(itemsExpires, itemtogive_id) then
								doItemSetAttribute(new_item, "boughtdate", os.time() + expire)
							end
						else
							doItemSetAttribute(new_item, "boughtdate", os.time() + expire)
						end
                        received_item = doPlayerAddItemEx(cid, new_item)
                    end
                    if received_item == RETURNVALUE_NOERROR then
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'Você recebeu o '.. add_item_name ..' do Zyzz-War.')
                        db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                        db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                    else
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
                    end
                else
                    doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
                end
            end
            if not(result_plr:next()) then
                break
            end
        end
        result_plr:free()
    end
    return TRUE
end

And this to your login.lua
Lua:
local config = {
	loginMessage = getConfigValue('loginMessage'),
	useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
		doPlayerAddPremiumDays(cid, 2)
		doPlayerSetPromotionLevel(cid, 1)
	end

	local accountManager = getPlayerAccountManager(cid)
	if(accountManager == MANAGER_NONE) then
		local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
		if(lastLogin > 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
			str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
		else
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
	elseif(accountManager == MANAGER_NAMELOCK) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
	elseif(accountManager == MANAGER_ACCOUNT) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
	end

	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	end

     registerCreatureEvent(cid, "kill")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "PlayerLogout")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "deathBroadcast")
     registerCreatureEvent(cid, "DeathBroadcast")
     registerCreatureEvent(cid, "Member")
     registerCreatureEvent(cid, "KillingInTheNameOf")
     registerCreatureEvent(cid, "MageBomb")

	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end

	registerCreatureEvent(cid, "ReportBug")
	
	--code for item that expires
	for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
		local item = getPlayerSlotItem(cid, slot)
		if item and item.uid > 0 then
			scanItem(item.uid)
		end
	end			
	return true
end

function scanItem(uid) --By Darkhaos.
	local removed = false
	local count = 0
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					removed = true
					count = count + 1
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanContainer(tmp.uid, list, position)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			removed = true
			count = count + 1
			doRemoveItem(uid)
		end
	end
	if removed then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, (count > 1 and "Some" or "One") .. " of your item" .. (count > 1 and "s" or "") .. " has expired.")
	end
	return true
end
 
This items are the that are going to exhale, certain?

Code:
 {2195, 2472}

They are going to exhale inside 30 days being or done not use?
Im going test!

If I will want to add more items for exhale is alone put after the punctuates?
 
I going to test.
Tks and REP+.

U tested the system ?

A question, the first script I put where? Shop.lua?

Is able to clear me better?
 
I modify the part : local expire = 30 * 24 * 60 * 60 to local expire = 30 * 1000 to test

and isnt working.. the item not desintegrate
 
Oops! Sorry
Lua:
local config = {
	loginMessage = getConfigValue('loginMessage'),
	useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}
 
function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
		doPlayerAddPremiumDays(cid, 2)
		doPlayerSetPromotionLevel(cid, 1)
	end
 
	local accountManager = getPlayerAccountManager(cid)
	if(accountManager == MANAGER_NONE) then
		local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
		if(lastLogin > 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
			str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
		else
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end
 
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
	elseif(accountManager == MANAGER_NAMELOCK) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
	elseif(accountManager == MANAGER_ACCOUNT) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
	end
 
	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	end
 
     registerCreatureEvent(cid, "kill")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "PlayerLogout")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "deathBroadcast")
     registerCreatureEvent(cid, "DeathBroadcast")
     registerCreatureEvent(cid, "Member")
     registerCreatureEvent(cid, "KillingInTheNameOf")
     registerCreatureEvent(cid, "MageBomb")
 
	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
 
	registerCreatureEvent(cid, "ReportBug")
 
	--code for item that expires
	for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
		local item = getPlayerSlotItem(cid, slot)
		if item and item.uid > 0 then
			scanItem(cid, item.uid)
		end
	end			
	return true
end
 
function scanItem(cid, uid) --By Darkhaos.
	local removed = false
	local count = 0
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					removed = true
					count = count + 1
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanContainer(tmp.uid, list, position)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			removed = true
			count = count + 1
			doRemoveItem(uid)
		end
	end
	if removed then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, (count > 1 and "Some" or "One") .. " of your item" .. (count > 1 and "s" or "") .. " has expired.")
	end
	return true
end
 
I tested with Windows XP, and when i upload in my ubuntu i got a errors :(

Here:
Code:
[2:36:25.281] [Error - CreatureScript Interface]
[2:36:25.281] data/creaturescripts/scripts/login.lua:onLogin
[2:36:25.281] Description:
[2:36:25.281] data/creaturescripts/scripts/login.lua:83: attempt to call global 'scanContainer' (a nil value)
[2:36:25.281] stack traceback:
[2:36:25.281]   data/creaturescripts/scripts/login.lua:83: in function 'scanItem'
[2:36:25.281]   data/creaturescripts/scripts/login.lua:64: in function <data/creaturescripts/scripts/login.lua:6>

[2:36:25.331] [Error - CreatureScript Interface]
[2:36:25.331] In a timer event called from:
[2:36:25.331] data/creaturescripts/scripts/anti.lua:onLogin
[2:36:25.331] Description:
[2:36:25.331] (internalGetPlayerInfo) Player not found when requesting player info #28

My Login:
Code:
local config = {
	loginMessage = getConfigValue('loginMessage'),
	useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}
 
function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
		doPlayerAddPremiumDays(cid, 2)
		doPlayerSetPromotionLevel(cid, 1)
	end
 
	local accountManager = getPlayerAccountManager(cid)
	if(accountManager == MANAGER_NONE) then
		local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
		if(lastLogin > 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
			str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
		else
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end
 
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
	elseif(accountManager == MANAGER_NAMELOCK) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
	elseif(accountManager == MANAGER_ACCOUNT) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
	end
 
	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	end
 
     registerCreatureEvent(cid, "kill")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "PlayerLogout")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "deathBroadcast")
     registerCreatureEvent(cid, "DeathBroadcast")
     registerCreatureEvent(cid, "Member")
     registerCreatureEvent(cid, "KillingInTheNameOf")
     registerCreatureEvent(cid, "MageBomb")
 
	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
 
	registerCreatureEvent(cid, "ReportBug")
 
	--code for item that expires
	for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
		local item = getPlayerSlotItem(cid, slot)
		if item and item.uid > 0 then
			scanItem(cid, item.uid)
		end
	end			
	return true
end
 
function scanItem(cid, uid) --By Darkhaos.
	local removed = false
	local count = 0
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					removed = true
					count = count + 1
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanContainer(tmp.uid, list, position)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			removed = true
			count = count + 1
			doRemoveItem(uid)
		end
	end
	if removed then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Um Zyzz Item (VIP) seu expirou, adquira outro em nosso site! Acesse: http://zyzz-war.sytes.net/")
	end
	return true
end

My anti:
Code:
local config = {
	max = 10, -- max chars with the same ip
	text = "MageBomb is not allowed.", -- text on kick
	group_id = 1 -- only kick player with group id 1 (normal players)
}
 
local accepted_ip_list = {} -- list of ip's then can use MC
 
local function antiMC(p)
	if #getPlayersByIp(getPlayerIp(p.pid)) >= p.max then
        	doRemoveCreature(p.pid)
	end
	return TRUE
end
 
function onLogin(cid)
	if getPlayerGroupId(cid) <= config.group_id then
		if isInArray(accepted_ip_list,getPlayerIp(cid)) == FALSE then 
			addEvent(antiMC, 1, {pid = cid, max = config.max+1})
			doPlayerSendTextMessage(0, cid, 21, "MageBomb is not allowed.")
		end
	end
	return TRUE
end

Wats wrongggg? :((
 
Lua:
function scanItem(cid, uid) --By Darkhaos.
	local removed = false
	local count = 0
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					removed = true
					count = count + 1
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanItem(cid, tmp.uid)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			removed = true
			count = count + 1
			doRemoveItem(uid)
		end
	end
	if removed then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, (count > 1 and "Some" or "One") .. " of your item" .. (count > 1 and "s" or "") .. " has expired.")
	end
	return true
end
 
LOL! don't have error in console now, but isnt working -.-

i got o cry :(

Code:
local config = {
	loginMessage = getConfigValue('loginMessage'),
	useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}
 
function onLogin(cid)
	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
		doPlayerAddBlessing(cid, 1)
		doPlayerAddBlessing(cid, 2)
		doPlayerAddBlessing(cid, 3)
		doPlayerAddBlessing(cid, 4)
		doPlayerAddBlessing(cid, 5)
		doPlayerAddPremiumDays(cid, 2)
		doPlayerSetPromotionLevel(cid, 1)
	end
 
	local accountManager = getPlayerAccountManager(cid)
	if(accountManager == MANAGER_NONE) then
		local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
		if(lastLogin > 0) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
			str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
		else
			str = str .. " Please choose your outfit."
			doPlayerSendOutfitWindow(cid)
		end
 
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
	elseif(accountManager == MANAGER_NAMELOCK) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
	elseif(accountManager == MANAGER_ACCOUNT) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
	end
 
	if(not isPlayerGhost(cid)) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
	end
 
     registerCreatureEvent(cid, "kill")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "PlayerLogout")
     registerCreatureEvent(cid, "onPrepareDeath")
     registerCreatureEvent(cid, "deathBroadcast")
     registerCreatureEvent(cid, "DeathBroadcast")
     registerCreatureEvent(cid, "Member")
     registerCreatureEvent(cid, "KillingInTheNameOf")
     registerCreatureEvent(cid, "MageBomb")
 
	registerCreatureEvent(cid, "Idle")
	if(config.useFragHandler) then
		registerCreatureEvent(cid, "SkullCheck")
	end
 
	registerCreatureEvent(cid, "ReportBug")
 
	--code for item that expires
	for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
		local item = getPlayerSlotItem(cid, slot)
		if item and item.uid > 0 then
			scanItem(cid, item.uid)
		end
	end			
	return true
end
 
function scanItem(cid, uid) --By Darkhaos.
	local removed = false
	local count = 0
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					removed = true
					count = count + 1
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanItem(cid, tmp.uid)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			removed = true
			count = count + 1
			doRemoveItem(uid)
		end
	end
	if removed then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Um Zyzz Item (VIP) seu expirou, adquira outro em nosso site! Acesse: http://zyzz-war.sytes.net/")
	end
	return true
end

- - - Updated - - -

the item not desintegrate now and no msg why this
 
Last edited:
Solved! Tks so much, Darkhaos.

How I do for the he specify the item that is going to finish?
Example: Boots of haste has expired.

It has a function of identify the player and I tried for in the item but didnt give, which would be to correct?
 
Last edited:
Lua:
function scanItem(cid, uid) --By Darkhaos.
	if isContainer(uid) then
		for k = (getContainerSize(uid) - 1), 0, -1 do
			local tmp = getContainerItem(uid, k)
			if not isContainer(tmp.uid) then
				if getItemAttribute(tmp.uid, "boughtdate") and os.time() >= getItemAttribute(tmp.uid, "boughtdate") then
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getItemNameById(tmp.itemid) .. " has expired.")
					doRemoveItem(tmp.uid)
				end
			elseif isContainer(tmp.uid) then
				scanItem(cid, tmp.uid)
			end
		end
	else
		if getItemAttribute(uid, "boughtdate") and os.time() >= getItemAttribute(uid, "boughtdate") then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getItemNameById(getThing(uid).itemid) .. " has expired.")
			doRemoveItem(uid)
		end
	end
	return true
end

But with this, you'll get a message for each item removed.
 
Back
Top