soul4soul
Intermediate OT User
everyone thank Sam09 from otfanssam09 said: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