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

Gesior ITEM/PACC Shop (PHP+LUA) for TFS

Status
Not open for further replies.

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,966
Solutions
99
Reaction score
3,383
Location
Poland
GitHub
gesior
Last update: 17 March 2008, 02:21
Newest version: AVAILABLE IS OTHER THREAD!!!
Changes:
v 0.0.3 - fixed bug with database and access to file (linux)
v 0.0.2 - fixed bug in lua script that let players create more than one item when they buy armor, legs, boots or helmet
v 0.0.1 - first posted version

I made shop script for TFS 0.2.10 / 0.2.11, but maybe work with older TFS versions (not tested).
How to install:
1. Unpack "Gesior Shop System for TFS - PHP.zip" to your web directory (.../xampp/htdocs/gesiorshop/).
2. Open ".../gesiorshop/config/config.ini" and set valid directory with your server. Default config is:
Code:
server_path = "C:/Documents and Settings/Gesior/Pulpit/tfs 0.2.9/"
give_to_other_users = "yes"
shop_layout_name = "dirt"
server_path - your directory with TFS, remember about "/" at end!
give_to_other_users - can you give items/pacc to other users of server, not in use in this version (everyone can give items/pacc to other players)
shop_layout_name - name of directory with layout, in this version is only one layout ("dirt", but its not dirt :p )
3. Open your OTS login.lua file from ".../your-ots-directory/data/creaturescripts/scripts/login.lua"
and in place of (only this line, not full login.lua code!):
Code:
function onLogin(cid)
put (it's not full login.lua code!):
Code:
dofile("./config.lua")
function onLogin(cid)
	if sqlType == "mysql" then
		env = assert(luasql.mysql())
		con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
	else -- sqlite
		env = assert(luasql.sqlite3())
		con = assert(env:connect(sqliteDatabase))
	end
	local name = getCreatureName(cid)
	local nametodb = escapeString(name)
        result_plr = assert(con:execute("SELECT * FROM z_ots_comunication WHERE `type` = 'login' AND name = '".. nametodb .."';"))
        todo = result_plr:fetch({}, "a")
        while todo do
			id = tonumber(todo.id)
            action = tostring(todo.action)
			delete = tonumber(todo.delete_it)
			if action == 'show_msg' then
				local msg_text = tostring(todo.param1)
				local msg_type = todo.param2
				doPlayerSendTextMessage(cid, msg_type, msgtext)
				if delete == 1 then
					delete = assert(con:execute("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";"))
				end
			elseif action == 'give_item' then
				local itemtogive_id = tonumber(todo.param1)
				local itemtogive_count = tonumber(todo.param2)
				local b_head_slot = getPlayerSlotItem(cid, 1)
				local b_necklace_slot = getPlayerSlotItem(cid, 2)
				local b_backpack_slot = getPlayerSlotItem(cid, 3)
				local b_armor_slot = getPlayerSlotItem(cid, 4)
				local b_right_hand = getPlayerSlotItem(cid, 5)
				local b_left_hand = getPlayerSlotItem(cid, 6)
				local b_legs_slot = getPlayerSlotItem(cid, 7)
				local b_feet_slot = getPlayerSlotItem(cid, 8)
				local b_ring_slot = getPlayerSlotItem(cid, 9)
				local b_arrow_slot = getPlayerSlotItem(cid, 10)
				if b_arrow_slot.itemid == 0 or (b_left_hand.itemid == 0 and b_right_hand.itemid == 0) then
					local addeditem = doPlayerAddItem(cid, itemtogive_id, itemtogive_count)
					local head_slot = getPlayerSlotItem(cid, 1)
					local necklace_slot = getPlayerSlotItem(cid, 2)
					local backpack_slot = getPlayerSlotItem(cid, 3)
					local armor_slot = getPlayerSlotItem(cid, 4)
					local right_hand = getPlayerSlotItem(cid, 5)
					local left_hand = getPlayerSlotItem(cid, 6)
					local legs_slot = getPlayerSlotItem(cid, 7)
					local feet_slot = getPlayerSlotItem(cid, 8)
					local ring_slot = getPlayerSlotItem(cid, 9)
					local arrow_slot = getPlayerSlotItem(cid, 10)
					if ring_slot.itemid == itemtogive_id or feet_slot.itemid == itemtogive_id or legs_slot.itemid == itemtogive_id or armor_slot.itemid == itemtogive_id or necklace_slot.itemid == itemtogive_id or head_slot.itemid == itemtogive_id or arrow_slot.itemid == itemtogive_id or left_hand.itemid == itemtogive_id or right_hand.itemid == itemtogive_id or backpack_slot.itemid == itemtogive_id then
						if b_ring_slot.uid ~= ring_slot.uid or b_feet_slot.uid ~= feet_slot.uid or b_legs_slot.uid ~= legs_slot.uid or b_armor_slot.uid ~= armor_slot.uid or b_necklace_slot.uid ~= necklace_slot.uid or b_head_slot.uid ~= head_slot.uid or b_backpack_slot.uid ~= backpack_slot.uid or b_right_hand.uid ~= right_hand.uid or b_left_hand.uid ~= left_hand.uid or b_arrow_slot.uid ~= arrow_slot.uid then
						doPlayerSendTextMessage(cid, 17, '"'..getItemName(itemtogive_id)..'" from "OTS shop" added. Please re-login now to save item!')
						delete = assert(con:execute("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";"))
						else
							doPlayerSendTextMessage(cid, 17, '"'..getItemName(itemtogive_id)..'" from "OTS shop" not added. Unknown error occured. Re-login again or contact with admin.')
						end
					else
						doPlayerSendTextMessage(cid, 17, '"'..getItemName(itemtogive_id)..'" from "OTS shop" not added. Unknown error occured. Re-login again or contact with admin.')
					end
				else
					doPlayerSendTextMessage(cid, 17, 'Item from "OTS shop" is waiting for you. Please take items from both hands or item from arrow slot and re-login to get item.')
				end
			end
            todo = result_plr:fetch (todo, "a")
        end
	registerCreatureEvent(cid, "PlayerDeath")
	return TRUE
end
4. In your MySQL database execute (with phpmyadmin or something like that):
Code:
CREATE TABLE `z_ots_comunication` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  `param1` varchar(255) NOT NULL,
  `param2` varchar(255) NOT NULL,
  `param3` varchar(255) NOT NULL,
  `param4` varchar(255) NOT NULL,
  `param5` varchar(255) NOT NULL,
  `param6` varchar(255) NOT NULL,
  `param7` varchar(255) NOT NULL,
  `delete_it` int(2) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
and:
Code:
CREATE TABLE `z_shop_offer` (
  `id` int(11) NOT NULL auto_increment,
  `points` int(11) NOT NULL default '0',
  `itemid1` int(11) NOT NULL default '0',
  `count1` int(11) NOT NULL default '0',
  `itemid2` int(11) NOT NULL default '0',
  `count2` int(11) NOT NULL default '0',
  `offer_type` varchar(255) default NULL,
  `offer_description` text NOT NULL,
  `offer_name` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
and:
Code:
ALTER TABLE `accounts` ADD `premium_points` INT( 11 ) NOT NULL DEFAULT '0';
5. End of installation. Open page index.php from PHP script directory in your internet explorer. ( http://127.0.0.1/gesiorshop/ )
-------------------------------------
About script:
-work with MySQL servers (tested on TFS 0.2.10/0.2.11, XAMPP 1.6.5)
-items can't disappear like in other "item shop" scripts

What my script do:
-give item/pacc in game when player buy it on site
-you can add many items with diffrent prices (like: Golden Armor - 5 points, 10 Days of PACC - 25 points, 5 days of pacc - 15 points)
-load list of offers from database
My script don't:
-give items/pacc for SMS/RL cash transfer

Screens:
-main page:

-when user selected item from list:

-when selected player and item:

-when transaction confirmed:

-there are also pages to login/logout (no screens)

Sample of offer configuration. Execute it in MySQL OTS database:
Code:
INSERT INTO z_shop_offer (id, points, itemid1, count1, itemid2, count2, offer_type, offer_description, offer_name) VALUES(1, 1, 1987, 1, 0, 0, 'item', 'Need place for loot? Buy brown bag! You can put up to 8 items in this bag and it weight is only 8 oz.\r\nOnly today extra cheap offer!', '1x Brown Bag');
INSERT INTO z_shop_offer (id, points, itemid1, count1, itemid2, count2, offer_type, offer_description, offer_name) VALUES(0, 5, 0, 5, 0, 0, 'pacc', 'Buy 5 days of premium account for yourself or your friend!', '5 Days of PACC');
INSERT INTO z_shop_offer (id, points, itemid1, count1, itemid2, count2, offer_type, offer_description, offer_name) VALUES(5, 20, 2466, 1, 0, 0, 'item', 'Become a real knight! Buy this extra armor, 14 armor points reduce monsters hit! ', '1x Golden Armor');
INSERT INTO z_shop_offer (id, points, itemid1, count1, itemid2, count2, offer_type, offer_description, offer_name) VALUES(4, 10, 0, 12, 0, 0, 'pacc', 'Buy 12 days of premium account for yourself or your friend! 12 days for only 10 premium points!', '12 Days of PACC');
When you add new PACC offer you must set in offer table in database:
id - empty (auto_incement)
points - how many points cost this offer
count1 - number of PACC days this offer give
offer_type = "pacc"
offer_description - description of new pacc offer like: "Buy 5 days of PACC. With PACC you can visit new areas, fight stronger monsters and promote your character!"
offer_name - name of new pacc offer like: "5 Days of PACC"

When you add new ITEM offer you must set in offer table in database:
id - empty (auto_increment)
points - how many points cost this offer
itemid1 - ID of created item on OTS
count1 - "count" of item on OTS, like SD with 15 shots has count "15", normal item (bag, crossbow, golden armor...) has count "1"
offer_type = "item"
offer_description - description of new item offer like: "Buy Golden Armor and become great knight! Fight stonger mosters and lose less HP!"
offer_name - name of new pacc offer like: "1x Golden Armor"

I hope you understand how it work :p
It's first version, you can't sell containers in this version.
TODO:
-sell containers with items
-transfer "premium points" to other account
-save all transactions in database and show history of transactions: "XX bought XX item for player XX for XX points, date: 1 march 2008, transaction state: realized"

REPORT BUGS IN THIS THREAD. IT'S TEST VERSION ONLY!
 

Attachments

  • Gesior Shop System 0.0.3 for TFS - PHP.zip
    107.9 KB · Views: 1,195 · VirusTotal
Last edited:
RE: 1. Unpack "Gesior Shop System for TFS - PHP.zip" to your web directory (.../xampp/htdocs/gesiorshop/).

How can i unpack something when it not exist? :p
I dont see here any thing to download-.-
 
RE: 1. Unpack "Gesior Shop System for TFS - PHP.zip" to your web directory (.../xampp/htdocs/gesiorshop/).

How can i unpack something when it not exist? :p
I dont see here any thing to download-.-
First post ready. Now you can download.
EDIT first post: Fixed one bug in LUA script. Now all should work fine.
 
Last edited:
How do you add points to players? (I'm too tired right now to read it thru completely ;))


EDIT: I get this message when I try to connect to the site:

Warning: fopen(usercounter.dat) [function.fopen]: failed to open stream: Permission denied in /var/www/shop/config-and-functions.php on line 123

Warning: fgets(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 124

Warning: rewind(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 126

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 128

Fatal error: Call to a member function fetch() on a non-object in /var/www/shop/pot/OTS_Account.php on line 371
 
Last edited:
Warning: fopen(usercounter.dat) [function.fopen]: failed to open stream: Permission denied in /var/www/shop/config-and-functions.php on line 123

Warning: fgets(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 124

Warning: rewind(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 126

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/shop/config-and-functions.php on line 128

Fatal error: Call to a member function fetch() on a non-object in /var/www/shop/pot/OTS_Account.php on line 371


Help me please :O
 
Help me please :O
You have problem with access to files from PHP script. Why? I don't know, but I deleted this part of code from shop system because it's not in use now and will not be needed. Download version 0.0.3 from first post (php files).
How do you add points to players? (I'm too tired right now to read it thru completely ;))
It's your 'problem'. You must make your own script to add premium points for SMSs/bank transfer/paypal or whatevery you want. Today I made script to change "code" from SMS to 50 premium points, but I based on someone else "pacc for sms" script and I can't post this script here. I'll try to make tommorow my own script to change "sms codes" to "premium points". If you already use any system to change "SMS code >> PACC days" or "paypal transfer >> PACC days" you must only change "premdays" to "premium_points" in every SQL query to OTS database and all should work fine.
SMS script "work" here (it's not my ots):
http://persoul.hopto.org/punkty.php
My shop "work" here (translated to polish with "Persoul RPG server" items/pacc offer):
http://persoul.hopto.org/shop/index.php
 
Last edited:
Nice release Gesior. Sure cuts back on the work for those that want to setup a donation system. I tested this and it works fine with paypal transfer. Thank you for the release.
 
Thx It's very great job! I no have problems in this script.
 
Great, works now, but where does the items end up? In a players DP or ON the player? :p


EDIT: And also, the header redirects you to \index.html :p
 
Last edited:
Still getting errors;

Fatal error: Call to a member function fetch() on a non-object in C:\xampp\htdocs\gesiorshop\pot\OTS_Account.php on line 371
 
Gesior

can you make real tibia payment system but in sms with layou
Add it on
Gesior acc. maker for TFS (tibia.com and Swelia layout)
 
I now have this error:

Database error - can't open SQLite database. Possible reasons:
C:/Documents and Settings/kris/Pulpit/Mystic Spirit/forgottenserver.s3db - file isn't valid SQLite database.
C:/Documents and Settings/kris/Pulpit/Mystic Spirit/forgottenserver.s3db - doesn't exist.
 
@UP
Error is in your config.lua
Edit config.lua and change database setting to good.
 
Great, works now, but where does the items end up? In a players DP or ON the player? :p
EDIT: And also, the header redirects you to \index.html :p
This bug in layout and other fixed by "Ronaldino".
Script (LUA) give item to player when he login or show msg:
Item or container from "OTS shop" is waiting for you. Please take items from both hands or item from arrow slot and re-login to get this item or container.
(ver. 0.0.4, you can sell containers with items)
It put item (or container with items) in one of his hands or arrow slot, but arrow slot or BOTH hands must be empty (when he wear 2-handed weapon one hand return in LUA "itemid = 0" - empty, so 2 hands must be empty). Items will not be dropped on floor. Later it check is new item added and if is, it delete row from database. Don't ask me why this code is soo long. It can't be shorter (check how works lua functions :( ).
Still getting errors;
Did you executed in your database:
Code:
ALTER TABLE `accounts` ADD `premium_points` INT( 11 ) NOT NULL DEFAULT '0';
?
Did you execute other SQL queries from first post? Do you use TFS (this shop work only with TFS engine/database structure)?
I now have this error:
Is it hard to understand what is wrong? "SQLite database isn't valid SQLite file or file doesn't exist" change your configuration in config.lua (TFS file).
habiba said:
can you make real tibia payment system but in sms with layou
Add it on
Gesior acc. maker for TFS (tibia.com and Swelia layout)
Shop system will be added to next version of acc. maker, when shop system will be ready in 100%. Acc. maker will have only one layout in next version: tibia.com, shop system in version 1.0 and maybe fixed all problems with XSS attacks.
----
TODO in shop system (for today):
-transaction history
-add to item/pacc/container "from" (when you give something to player from other account you can enter your "nick" and player will see this nick)
-transfer points to other player (account of this player)
 
4. In your MySQL database execute (with phpmyadmin or something like that):

No idea how to do that :p Could you gesior please post some screens how to add this or explain it a little more?:p
 
Can you get a system with DaoPAY as gateway? Would be great..
Would also be great if you could let the item deliver in depot and configure the townID what you want. (even better if the item was in a 'present box' with a label in by who and when it was bought).

Just some ideas tho..
 
Did you executed in your database:
Code:
ALTER TABLE `accounts` ADD `premium_points` INT( 11 ) NOT NULL DEFAULT '0';
?
Did you execute other SQL queries from first post? Do you use TFS (this shop work only with TFS engine/database structure)?

Yes, yes and yes.
 
Can you get a system with DaoPAY as gateway? Would be great..
Would also be great if you could let the item deliver in depot and configure the townID what you want. (even better if the item was in a 'present box' with a label in by who and when it was bought).
Just some ideas tho..
Do you know any LUA function to add item to player depo? If not it's not possible. Other shop systems add items to depo, but it's stupid. If player is online item will just disappear (when player logout). Some systems can add only one item to depo and than you must relog what is also stupid. With my system player can be offline/online and can buy many items.
Maybe I'll add "present", but player will receive item "present" with description (from who is this item) and item when he login.
Maybe I'll create other LUA script and player will receive item in 1-xx seconds after buy (if is online).
 
Status
Not open for further replies.
Back
Top