I've added this to my server yesterday, with a database, a VIP System. Now players can buy items with these vip points.
Note: (Vip points is by account and not by players.)
If you want a Vip System by storages (the points will be by players and not by accounts), then look here http://otland.net/f81/vip-system-add-remove-vip-points-buy-sell-item-vip-points-storagevalue-30164/
Extecute this with MySQL
Add this to your function.lua:
Now, create a file called vip.lua in your talkactions folder and add this:
These are the items that you can buy/sell
Words:
Thanks to:
-Master-m, i based the "!buyitem" code in your script.
-josejunior23, I was going to thank you for your script since in some parts I base on your script, I do not give the thanks to you since your script has a bug that I fix, if you check the topic of your script, you will see which mistake you have.
Note: (Vip points is by account and not by players.)
If you want a Vip System by storages (the points will be by players and not by accounts), then look here http://otland.net/f81/vip-system-add-remove-vip-points-buy-sell-item-vip-points-storagevalue-30164/
Extecute this with MySQL
Code:
ALTER TABLE `accounts` ADD `vip_points` INT( 11 ) NOT NULL DEFAULT '0';
Add this to your function.lua:
Code:
function getPlayerVipPoints(cid)
local Info = db.getResult("SELECT `vip_points` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
if Info:getID() ~= LUA_ERROR then
local Points= Info:getDataInt("vip_points")
Info:free()
return Points
end
return LUA_ERROR
end
function doPlayerAddVipPoints(cid, points)
local dif = getPlayerVipPoints(cid) + points
if dif >= 0 then
db.executeQuery("UPDATE `accounts` SET `vip_points` = `vip_points` + " .. points .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
return TRUE
end
return FALSE
end
function doPlayerRemoveVipPoints(cid, points)
local dif = getPlayerVipPoints(cid) - points
if dif >= 0 then
db.executeQuery("UPDATE `accounts` SET `vip_points` = `vip_points` - " .. points .. " WHERE `id` = " .. getPlayerAccountId(cid) .. ";")
return TRUE
end
return FALSE
end
Now, create a file called vip.lua in your talkactions folder and add this:
Code:
requiredGroup = 3
function onSay(cid, words, param)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
return TRUE
end
local t = string.explode(param, ",")
local target = getPlayerByNameWildcard(t[1])
local points = tonumber(t[2])
if(words == "/addvip") then
if(getPlayerGroupId(cid) < requiredGroup) then
return FALSE
end
if(target == 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[1] .. " not found.")
return TRUE
end
if(not points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "No point specified.")
return TRUE
end
points = math.abs(points)
doPlayerAddVipPoints(target, points)
doSendMagicEffect(getCreaturePosition(target), CONST_ME_MAGIC_RED)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have added " .. points .. " points to " .. t[1] .. ".")
return TRUE
end
if(words == "/removevip") then
if(getPlayerGroupId(cid) < requiredGroup) then
return FALSE
end
if(target == 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. t[1] .. " not found.")
return TRUE
end
if(not points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "No point specified.")
return TRUE
end
points = math.abs(points)
doPlayerRemoveVipPoints(cid, points)
doSendMagicEffect(getCreaturePosition(target), CONST_ME_MAGIC_RED)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have removed " .. points .. " points from " .. t[1] .. ".")
return TRUE
end
if(words == "/getvip") then
if(getPlayerGroupId(cid) < requiredGroup) then
return FALSE
end
target = getPlayerByNameWildcard(param)
if(target == 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " not found.")
return TRUE
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " have " .. getPlayerVipPoints(target) .. " points.")
return TRUE
end
if(words == "!buyitem") then
local buyableItems =
{
["boots of haste"] = {id = 2195, count = 1, points = 3, charges = 1},
["amulet of loss"] = {id = 2173, count = 1, points = 5, charges = 1},
["soft boots"] = {id = 6132, count = 1, points = 20, charges = 1}
}
local buyableItem = buyableItems[t[1]]
if buyableItem then
if(not t[2]) then
if getPlayerVipPoints(cid) >= buyableItem.points then
doPlayerGiveItem(cid, buyableItem.id, buyableItem.count, buyableItem.charges)
doPlayerRemoveVipPoints(cid, buyableItem.points)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought x" .. buyableItem.count .. " " .. getItemNameById(buyableItem.id) .. " for " .. buyableItem.points .." vip points. " .. getPlayerVipPoints(cid) .. " vip points left.")
return TRUE
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have enough vip points.")
return TRUE
end
else
if(getPlayerVipPoints(cid) >= buyableItem.points * t[2]) then
doPlayerGiveItem(cid, buyableItem.id, buyableItem.count * t[2], buyableItem.charges)
doPlayerRemoveVipPoints(cid, buyableItem.points * t[2])
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought x" .. buyableItem.count * t[2] .. " " .. getItemNameById(buyableItem.id) .. " for " .. buyableItem.points * t[2] .. " vip points. " .. getPlayerVipPoints(cid) .. " vip points left.")
return TRUE
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have enough vip points.")
return TRUE
end
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not buy that item.")
return TRUE
end
end
if(words == "!sellitem") then
local sellableItems =
{
["boots of haste"] = {id = 2195, count = 1, points = 3, charges = 1},
["amulet of loss"] = {id = 2173, count = 1, points = 5, charges = 1},
["soft boots"] = {id = 6132, count = 1, points = 20, charges = 1}
}
local sellableItem = sellableItems[t[1]]
if sellableItem then
if(not t[2]) then
if(getPlayerVipPoints(cid) > 0) then
if(doPlayerTakeItem(cid, sellableItem.id, sellableItem.count, sellableItem.charges) == LUA_ERROR) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have that item.")
return TRUE
else
doPlayerAddVipPoints(cid, sellableItem.points)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sold x" .. sellableItem.count .. " " .. getItemNameById(sellableItem.id) .. " for " .. sellableItem.points .. " vip points. " .. getPlayerVipPoints(cid) .. " vip points left.")
return TRUE
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be vip to sell items.")
return TRUE
end
else
if(getPlayerVipPoints(cid) > 0) then
if(doPlayerTakeItem(cid, sellableItem.id, sellableItem.count * t[2], sellableItem.charges) == LUA_ERROR) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have these items.")
return TRUE
else
doPlayerAddVipPoints(cid, sellableItem.points * t[2])
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sold x" .. sellableItem.count * t[2] .. " " .. getItemNameById(sellableItem.id) .. " for " .. sellableItem.points * t[2] .. " vip points. " .. getPlayerVipPoints(cid) .. " vip points left.")
return TRUE
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be vip to sell items.")
return TRUE
end
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not sell that item.")
return TRUE
end
end
if(words == "!itemlist") then
if(param == "buy") then
local text = "Items that you can buy:\n\nName: Boots of haste, Price: 3 points.\nName: Amulet of loss, Price: 5 points.\nName: Soft boots, Price: 20 points.\n\nYou have " .. getPlayerVipPoints(cid) .. " vip points."
doPlayerPopupFYI(cid, text)
return TRUE
elseif(param == "sell") then
local txt = "Items that you can sell:\n\nName: Boots of haste, Price: 3 points.\nName: Amulet of loss, Price: 5 points.\nName: Soft boots, Price: 20 points.\n\nYou have " .. getPlayerVipPoints(cid) .. " vip points."
doPlayerPopupFYI(cid, txt)
return TRUE
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Say (!itemlist buy) or (!itemlist sell) to see the items that you can buy or sell.")
return TRUE
end
end
end
These are the items that you can buy/sell
Code:
local buyableItems = --Items that you can buy
{
["boots of haste"] = {id = 2195, count = 1, points = 3, charges = 1},
["amulet of loss"] = {id = 2173, count = 1, points = 5, charges = 1},
["soft boots"] = {id = 6132, count = 1, points = 20, charges = 1}
}
local sellableItems = --Items that you can sell
{
["boots of haste"] = {id = 2195, count = 1, points = 3, charges = 1},
["amulet of loss"] = {id = 2173, count = 1, points = 5, charges = 1},
["soft boots"] = {id = 6132, count = 1, points = 20, charges = 1}
}
Code:
id -- itemid
count -- item count that you will buy or sell
points -- cost in vip points
charges --item charges (for runes, stackable items)
Code:
requiredGroup = 3 --Group ID required to use /addvip, /removevip and /getvip
Words:
- /addvip (Add vip points to a player. Ex: /addvip Darkhaos, 10)
- /removevip (Remove vip points to a player. Ex: /removevip Darkhaos, 10)
- /getvip (Get vip points from a player. Ex: /getvip Darkhaos <- this will send you a message "Player Darkhaos have 10 vip points")
- !buyitem (buy items with vip points. Ex: !buyitem boots of haste. Ex: !buyitem boots of haste, 2 <- Buy 2 boots of haste)
- !sellitem (Sell item by vip points. Ex: !sellitem boots of haste. Ex: !sellitem boots of haste, 2 <- Sell 2 boots of haste)
- !itemlist buy/sell (See the item list that you can buy or sell. Ex: !itemlist buy or !itemlist sell)
Thanks to:
-Master-m, i based the "!buyitem" code in your script.
-josejunior23, I was going to thank you for your script since in some parts I base on your script, I do not give the thanks to you since your script has a bug that I fix, if you check the topic of your script, you will see which mistake you have.
Last edited: