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

Linux This Item doesn't disappear

Vrotz

Member
Joined
Apr 7, 2011
Messages
1,071
Reaction score
7
Location
Brazil
I'm using a script done by the user View Profile: Darkhaos - OtLand

It works as follows:
I add Premium Points in ur account and in-game player buys Items VIPs by an NPC made ​​by me.

I did everything correctly, since the function in NPC until Login.lua.. There are no errors in the console and not the time of purchase of the item. He just doesn't disappear on time.

How I can fix this?

Script NPC:
PHP:
elseif(msgcontains(msg, '4war blessed helmet') or msgcontains(msg, 'blessed')) then
		selfSay('Voce desejar comprar o 4war blessed helmet por '.. helmetcost ..' premium points?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getAccountPoints(cid) >= helmetcost) then
			if(doAccountRemovePoints(cid, helmetcost) == TRUE) then
                        local t = 30
                        local item = doPlayerAddItem(cid, helmetid)
                        doItemSetAttribute(item, "boughtdate", os.time() + t)
				selfSay('Voce comprou o 4war blessed helmet.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed helmet.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed helmet.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)

NOTE: I change this:
PHP:
if(doAccountRemovePoints(cid, armorcost) == TRUE) then
				doPlayerAddItem(cid, helmetid)
				selfSay('Voce comprou o 4war blessed helmet.', cid)

For this:
PHP:
 			if(doAccountRemovePoints(cid, helmetcost) == TRUE) then
                        local t = 30
                        local item = doPlayerAddItem(cid, helmetid)
                        doItemSetAttribute(item, "boughtdate", os.time() + t)
				selfSay('Voce comprou o 4war blessed helmet.', cid)

Function scan on Login.lua:
PHP:
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

I edited only part to understand the script and see if it works, if you need the complete script here this:
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
npcHandler:setMessage(MESSAGE_GREET, "Ola, |PLAYERNAME|. Eu sou o NPC responsável por vender Items VIPs para Knights e Paladins. Para mais informações diga {info}.")


function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
end
 
	local bootsid = 2358
	local bootscost = 5
 
	local helmetid = 11302
	local helmetcost = 2

	local armorid = 11301
	local armorcost = 2

	local legsid = 11304
	local legscost = 2

	local shieldid = 6391
	local shieldcost = 2

	local swordid = 12649
	local swordcost = 10

	local axeid = 11305
	local axecost = 10

	local spearid = 7367
	local spearcost = 10
 
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, '4war boots') or msgcontains(msg, 'boots')) then
		selfSay('Voce deseja comprar a 4war boots por '.. bootscost ..' premium points?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getAccountPoints(cid) >= bootscost) then
			if(doAccountRemovePoints(cid, bootscost) == TRUE) then
				doPlayerAddItem(cid, bootsid)
				selfSay('Voce comprou uma 4war boots.', cid)
			else
				selfSay('Voce nao tem pontos suficientes.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
 
 
	elseif(msgcontains(msg, '4war blessed helmet') or msgcontains(msg, '4war blessed helmet')) then
		selfSay('Voce desejar comprar o 4war blessed helmet por '.. helmetcost ..' premium points?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getAccountPoints(cid) >= helmetcost) then
			if(doAccountRemovePoints(cid, helmetcost) == TRUE) then
                        local t = 1
                        local item = doPlayerAddItem(cid, helmetid)
                        doItemSetAttribute(item, "boughdate", os.time() + t)
				selfSay('Voce comprou o 4war blessed helmet.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed helmet.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed helmet.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


	elseif(msgcontains(msg, '4war blessed armor') or msgcontains(msg, '4war blessed armor')) then
		selfSay('Voce desejar comprar o 4war blessed armor por '.. armorcost ..' premium points?', cid)
		talkState[talkUser] = 3
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		if(getAccountPoints(cid) >= armorcost) then
			if(doAccountRemovePoints(cid, armorcost) == TRUE) then
				doPlayerAddItem(cid, armorid)
				selfSay('Voce comprou o 4war blessed armor.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed armor.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed armor.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


	elseif(msgcontains(msg, '4war blessed legs') or msgcontains(msg, '4war blessed legs')) then
		selfSay('Voce desejar comprar o 4war blessed legs por '.. legscost ..' premium points?', cid)
		talkState[talkUser] = 4
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 4) then
		if(getAccountPoints(cid) >= legscost) then
			if(doAccountRemovePoints(cid, legscost) == TRUE) then
				doPlayerAddItem(cid, legsid)
				selfSay('Voce comprou a 4war blessed legs.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed legs.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed legs.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


		elseif(msgcontains(msg, '4war blessed shield') or msgcontains(msg, '4war blessed shield')) then
		selfSay('Voce desejar comprar o 4war mage spelbook por '.. shieldcost ..' premium points?', cid)
		talkState[talkUser] = 5
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 5) then
		if(getAccountPoints(cid) >= shieldcost) then
			if(doAccountRemovePoints(cid, shieldcost) == TRUE) then
				doPlayerAddItem(cid, shieldid)
				selfSay('Voce comprou a 4war blessed shield.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed shield.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar o 4war blessed shield.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


		elseif(msgcontains(msg, '4war blessed sword') or msgcontains(msg, '4war blessed sword')) then
		selfSay('Voce desejar comprar o 4war blessed sword por '.. swordcost ..' premium points?', cid)
		talkState[talkUser] = 6
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6) then
		if(getAccountPoints(cid) >= swordcost) then
			if(doAccountRemovePoints(cid, swordcost) == TRUE) then
				doPlayerAddItem(cid, swordid)
				selfSay('Voce comprou a 4war blessed sword.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed sword.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed sword.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


		elseif(msgcontains(msg, '4war blessed axe') or msgcontains(msg, '4war blessed axe')) then
		selfSay('Voce desejar comprar o 4war blessed axe por '.. swordcost ..' premium points?', cid)
		talkState[talkUser] = 7
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 7) then
		if(getAccountPoints(cid) >= axecost) then
			if(doAccountRemovePoints(cid, axecost) == TRUE) then
				doPlayerAddItem(cid, axeid)
				selfSay('Voce comprou a 4war blessed axe.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed axe.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed axe.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


		elseif(msgcontains(msg, '4war blessed spear') or msgcontains(msg, '4war blessed spear')) then
		selfSay('Voce desejar comprar o 4war blessed spear por '.. swordcost ..' premium points?', cid)
		talkState[talkUser] = 8
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 8) then
		if(getAccountPoints(cid) >= spearcost) then
			if(doAccountRemovePoints(cid, spearcost) == TRUE) then
				doPlayerAddItem(cid, spearid)
				selfSay('Voce comprou a 4war blessed spear.', cid)
			else
				selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed spear.', cid)
			end
		else
			selfSay('Voce nao tem pontos suficientes para comprar a 4war blessed spear.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

keywordHandler:addKeyword({'info'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Eu posso lhe dar explicações detalhadas. Diga {points} para saber para que servem, {doacao} para saber como doar, {check} para consultar os pontos de sua account ou {VIP} para comprar os seus Items.'})

keywordHandler:addKeyword({'check'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Você pode consultar quantos pontos (Premium Points) você possui em sua conta, digite, no Default, o comando !points ou !check.'})

keywordHandler:addKeyword({'vip'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Para comprar o seu Item VIP comigo, apenas diga o nome do Item e confirme. Estes são os Items VIPs para Knights e Paladins: {4war blessed helmet}, {4war blessed armor}, {4war blessed legs}, {4war blessed shield}, {4war blessed sword}, {4war blessed axe}, {4war blessed spear}, {4war boots}.'})

keywordHandler:addKeyword({'points'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Premium Points são pontos obtidos através de doações para o server e eles servem para que você possa troca-los comigo por Items VIPs. Igual o sistema de um "Shop System".'})

keywordHandler:addKeyword({'doacao'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'As doações são necessárias para que você possa comprar um Item VIP comigo, sem os seus pontos eu não posso lhe dar os items. Portanto, acesse o nosso site e faça já uma doação! www.enforced.4war.org.'})

I'm used Tfs 0.3.7 R1 by MartyX.
 
Last edited:
That's what I said, I just modified a part to her forehead. Yes, I bought and no errors in the console. The item just doesn't disappear
 
Last edited:
You should make the text in english for presenting it here,that way people will be able to know wheres the part that your saying doesnt work.
 
What are you talking about? Everything is in English.

Maybe he mean in the scripts..

Also if you post lua scripts use lua tags and not php tags. So fast i look at lua script with php tags i just cancel the site. Hate that
 
You also have to add:
Lua:
     for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local item = getPlayerSlotItem(cid, i)
        if item.uid > 0 then
            scanItem(cid, item.uid)
        end
    end

under function onLogin(....)
 
Summ,
Please could u show me where I add this correctly? Tks
~~

I know where is the location, but within the script or after? I'll do the way I think its:

PHP:
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  

for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local item = getPlayerSlotItem(cid, i)
        if item.uid > 0 then
            scanItem(cid, item.uid)
        end
    end

Like this??
 
Like that?

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

function onLogin(cid)
	local a = 0
	local limitAM = 20
	if getCreatureName(cid):lower() == "account manager" then
		for _, pid in ipairs(getPlayersOnline()) do
			if getCreatureName(pid):lower() == "account manager" and pid ~= cid then
				a = a + 1
			end
		end

for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local item = getPlayerSlotItem(cid, i)
        if item.uid > 0 then
            scanItem(cid, item.uid)
        end
    end

		if a >= limitAM then
			return false
		end

		return true
	end

	if (getCreatureName(cid) == "Account Manager") then
		return doRemoveCreature(cid, true)
	end

	local loss = getConfigValue('deathLostPercent')
	if(loss ~= nil) then
		doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
	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, "Mail")
	registerCreatureEvent(cid, "GuildMotd")

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

	registerCreatureEvent(cid, "ReportBug")
	registerCreatureEvent(cid, "AdvanceSave")
	return true
end

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

I hate trying to understand your abbreviations, I'm really bad for derivatives and functions .-.
 
Lua:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

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 

function onLogin(cid)
    local a = 0
    local limitAM = 20
    if getCreatureName(cid):lower() == "account manager" then
        for _, pid in ipairs(getPlayersOnline()) do
            if getCreatureName(pid):lower() == "account manager" and pid ~= cid then
                a = a + 1
            end
        end

        if a >= limitAM then
            return false
        end

        return true
    end

    if (getCreatureName(cid) == "Account Manager") then
        return doRemoveCreature(cid, true)
    end

    for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local item = getPlayerSlotItem(cid, i)
        if item.uid > 0 then
            scanItem(cid, item.uid)
        end
    end
    
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    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, "Mail")
    registerCreatureEvent(cid, "GuildMotd")

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

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end
 

Similar threads

Back
Top