• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Buy items with frags

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,681
Solutions
126
Reaction score
1,119
Location
Germany
GitHub
slawkens
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:
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:
But maybe u can do that the player gain a point only if he kills higher lvl than him or same lvl. Because players will kill all lower lvls only for gaining points ;/

Anyway nice idea and gj.
 
Does this work for pvp enforced servers? cause im using TFS 3.4pl2 and it always says: You need 5 frags for this item, even do I have 10 frags registered... don't any error on console nor anything just that msg and the item is not added
 
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

Where is the code that actually gives the player the item??
 
Can anyone tell me where in this code it gives the player the item? so far all I can see is the error checks and then right at the end it has the message saying you got the item and a random function that doesnt give the item to the player haha help :D

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
 
Back
Top