slaw
Software Developer
Buying items, paying frags.
Requested from here:
http://otland.net/f132/buy-items-frags-request-rep-helper-24604/index3.html
Warning:
Works only on TFS 0.3!
1. First you need to add this new function to data/lib/function.lua:
2. data/scripts/fragreward.lua
3. talkactions.xml
Usage:
*!fragreward and !fragreward list - show window with names + frag needed
*!fragreward itemname - buy itemname
Requested from here:
http://otland.net/f132/buy-items-frags-request-rep-helper-24604/index3.html
Warning:
Works only on TFS 0.3!
1. First you need to add this new function to data/lib/function.lua:
Code:
function doPlayerAddFrags(cid, amount)
return doPlayerSetRedSkullTicks(cid, getPlayerRedSkullTicks(cid) + getConfigInfo('timeToDecreaseFrags') * amount)
end
2. data/scripts/fragreward.lua
Code:
local fragRewards =
{
--frag rewards configuration
--from highest to lowest (by frags)
{frags = 50, itemid = 2160},
{frags = 30, itemid = 2152, count = 50},
{frags = 10, itemid = 2148, count = 100},
{frags = 5, itemid = 2273, count = 50}
}
local function getRewardByName(name)
local tmp = name:lower()
local tmp2 = ""
for _, reward in pairs(fragRewards) do
tmp2 = getItemNameById(reward.itemid)
if(tmp == tmp2) then
reward.name = tmp2
return reward
end
end
return FALSE
end
function onSay(cid, words, param)
if(param == "" or param:lower() == "list") then
local str = "#Frag rewards:"
for _, reward in pairs(fragRewards) do
str = str .. "\n" .. getItemNameById(reward.itemid) .. " " .. (reward.count ~= nil and "(x" .. reward.count .. ")" or "") .. "- " .. reward.frags .. " frags"
end
doPlayerPopupFYI(cid, str .. "\n\nExample: " .. words .. " magic plate armor")
return TRUE
end
local reward = getRewardByName(param)
if(reward == FALSE) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Invalid item specified. Please use '" .. words .. " list' command to get valid rewards list.")
return TRUE
end
local playerFrags = getPlayerFrags(cid)
if(playerFrags < reward.frags) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need " .. reward.frags .. " frags for this item.")
return TRUE
end
itemWeight = getItemWeightById(reward.itemid, reward.count)
if(isItemRune(reward.itemid) == TRUE) then
itemWeight = getItemWeightById(reward.itemid, 1)
end
local rewardItem = doCreateItemEx(reward.itemid, reward.count)
local freeCap = getPlayerFreeCap(cid)
if(itemWeight > freeCap or doPlayerAddItemEx(cid, rewardItem) ~= RETURNVALUE_NOERROR) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enought space/capacity for this item.")
return TRUE
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought " .. reward.name .. " for " .. reward.frags .. " frags.")
doPlayerAddFrags(cid, -reward.frags)
return TRUE
end
3. talkactions.xml
Code:
<talkaction words="!fragreward" script="fragreward.lua"/>
Usage:
*!fragreward and !fragreward list - show window with names + frag needed
*!fragreward itemname - buy itemname
Last edited: