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

Donation shop problem

grek3535

New Member
Joined
Jul 12, 2009
Messages
11
Reaction score
0
Hello!
I got problems with my donations everything works fin until i buy an item, after buying it it wont appear on the character and i cant find the problem, can anyone help me ?

I hope i posted right :p
New here

Great regards
Grek
 
Do you have correctly installed global event / onLogin event?
 
Could you explain abit more? :p I use the TFS 0.3.5 and [Gesior AAC] 0.3.5 fixed v6
 
Last edited:
Many players forget this part.

Make sure you add this to Global.lua

Code:
InitHistory = 0
InitShopComunication = 0
 
i run The Forgotten Server, version 0.3.5 (Crying Damson)... there is no global.lua were i should i add that? do i need to add it to both globalevent and login? i tried that i tried lots of combinations and places to add that. my website is [Gesior AAC] 0.3.5 fixed v6
 
Solution

open your ots login.lua file from ".../your-ots-directory/data/creaturescripts/scripts/login.lua", delete all and put:

If you use tfs 0.2.9, 0.2.10, 0.2.11, 0.2.12, 0.2.13, 0.2.14, 0.2.15, 0.2.16, 0.2.17, 0.2.18, 0.2.19 or tfs 0.3 rev. Under 815:

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 ###
sql_comunication_interval = sql_interval * 1000
function onlogin(cid)
	if(initshopcomunication == 0) then
		local eventserv = addevent(sql_communication, sql_comunication_interval, {})
		initshopcomunication = eventserv
	end
	registercreatureevent(cid, "playerdeath")
	return true
end

function sql_communication(parameters)
	dofile("./config.lua")
	env = assert(luasql.mysql())
	con = assert(env:connect(mysqldatabase, mysqluser, mysqlpass, mysqlhost, mysqlport))
	result_plr = assert(con:execute("select * from z_ots_comunication where `type` = 'login';"))
	todo = result_plr:fetch({}, "a")
	while todo do
		id = tonumber(todo.id)
		action = tostring(todo.action)
		delete = tonumber(todo.delete_it)
		cid = getplayerbyname(tostring(todo.name))
		if isplayer(cid) == true then
			local itemtogive_id = tonumber(todo.param1)
			local itemtogive_count = tonumber(todo.param2)
			local container_id = tonumber(todo.param3)
			local container_count = tonumber(todo.param4)
			local add_item_type = tostring(todo.param5)
			local add_item_name = tostring(todo.param6)
			local received_item = 0
			local full_weight = 0
			if add_item_type == 'container' then
				container_weight = getitemweight(container_id, 1)
				if isitemrune(itemtogive_id) == true then
					items_weight = container_count * getitemweight(itemtogive_id, 1)
				else
					items_weight = container_count * getitemweight(itemtogive_id, itemtogive_count)
				end
				full_weight = items_weight + container_weight
			else
				full_weight = getitemweight(itemtogive_id, itemtogive_count)
				if isitemrune(itemtogive_id) == true then
					full_weight = getitemweight(itemtogive_id, 1)
				else
					full_weight = getitemweight(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, 'you received >> '.. Add_item_name ..' << from ots shop.')
					delete = assert(con:execute("delete from `z_ots_comunication` where `id` = " .. Id .. ";"))
					assert(con:execute("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
		todo = result_plr:fetch (todo, "a")
	end
	con:close()
	env:close()
	local eventserv = addevent(sql_communication, sql_comunication_interval, parameters)
end

or if you use new version of tfs 0.3 (alpha1 or new):
Beta 0.3 installation (test on alpha4) - not in login.lua / globals.lua!:
In data/globalevent/globalevents.xml add:
PHP:
<globalevent name="shop" interval="30" script="shop.lua"/>

in data/globalevent/shop.lua paste:

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 ###
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, 'you received >> '.. Add_item_name ..' << from ots shop.')
                        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
everyone thank Sam09 from otfans
 
Back
Top