• 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 Premium Points inGame

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,858
Reaction score
96
Location
Brazil
Premium Points System inGame
Credits to me this time.
Like+ Rep++


In data/libs create 048-ppoints.lua
Lua:
function getAccountPoints(cid)
    local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
       return false
    end
    local ret = res:getDataInt("premium_points")
    res:free()
    return tonumber(ret)
end

function doAccountAddPoints(cid, count)
    return db.executeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

function doAccountRemovePoints(cid, count)
    return db.executeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

In talkactions.xml add
XML:
	<!-- Premium Points System -->
	<talkaction log="yes" words="!getpoints;/getpoints" access="6" event="script" value="PremiumPoints/GetPoints.lua" />
	<talkaction log="yes" words="!addpoints;/addpoints" access="6" event="script" value="PremiumPoints/AddPoints.lua" />
	<talkaction log="yes" words="!removepoints;/removepoints" access="6" event="script" value="PremiumPoints/RemovePoints.lua" />
	<talkaction words="!points" event="script" value="PremiumPoints/SelfGetPoints.lua" />

In data/talkactions/script create AddPoints.lua
Lua:
function onSay(cid, words, param, channel)
	local split = param:explode(",")
	local name, count = split[1], tonumber(split[2])
	pid = getPlayerByNameWildcard(name)
	if (not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is not currently online.")
		return TRUE
	end
	if not(split[2]) then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The commands requires 2 parameters: character name, amount")
	end
	if not(count) then
		print(count)
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Numeric parameter required.")
	end
	doAccountAddPoints(cid, count)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "" .. count .. " premium points were added to " .. getCreatureName(pid) .. "\'s Account.")
	return true
end

In data/talkactions/script create GetPoints.lua
Lua:
function onSay(cid, words, param, channel)
local pid = 0
if(param == '') then
	pid = getCreatureTarget(cid)
	if(pid == 0) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return TRUE
	end
	else
		pid = getPlayerByNameWildcard(param)
	end
	if (not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is not currently online.")
		return TRUE
	end
	if isPlayer(pid) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "" .. getCreatureName(pid) .. "\'s Account has " .. getAccountPoints(cid) .. " premium points.")
		return TRUE
	end
return TRUE
end

In data/talkactions/script create RemovePoints.lua
Lua:
function onSay(cid, words, param, channel)
	local split = param:explode(",")
	local name, count = split[1], tonumber(split[2])
	local points = getAccountPoints(cid)
	pid = getPlayerByNameWildcard(name)
	if (not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is not currently online.")
		return TRUE
	end
	if not(split[2]) then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The commands requires 2 parameters: character name, amount")
	end
	if not(count) then
		print(count)
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Numeric parameter required.")
	end
	if (points <= 0) then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "" .. getCreatureName(pid) .. "\'s Account has 0 premium points.")
	end
	doAccountRemovePoints(cid, count)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "" .. count .. " premium points were deleted from " .. getCreatureName(pid) .. "\'s Account.")
	return true
end

In data/talkactions/script create SelfGetPoints.lua
Lua:
function onSay(cid, words, param, channel)
	if isPlayer(cid) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your Account has " .. getAccountPoints(cid) .. " premium points.")
	end
return TRUE
end

Change gender
Lua:
local config = {
	costPremiumDays = 2
}
 
function onSay(cid, words, param, channel)
	if(getPlayerSex(cid) >= 2) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot change your gender.")
		return
	end
 
	if(getAccountPoints(cid) < config.costPremiumDays) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sorry, not enough Premium Points - changing gender costs " .. config.costPremiumDays .. " Premium Points.")
		doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
		return
	end
 
	if(getAccountPoints(cid) >= config.costPremiumDays) then
		doRemovePoints(cid, -config.costPremiumDays)
	end
 
	local c = {
		{3, 1, false, 6, 1},
		{3, 2, false, 6, 2},
		{6, 1, false, 3, 1},
		{6, 2, false, 3, 2}
	}
	for i = 1, #c do
		if canPlayerWearOutfitId(cid, c[i][1], c[i][2]) then
			doPlayerRemoveOutfitId(cid, c[i][1], c[i][2])
			c[i][3] = true
		end
	end
 
	doPlayerSetSex(cid, getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have changed your gender and lost " .. config.costPremiumDays .. " days of premium time.")
	doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_RED)
 
	for i = 1, #c do
		if c[i][3] == true then
			doPlayerAddOutfitId(cid, c[i][4], c[i][5])
		end
	end
 
	return true
end

In data/NPC/scripts create itensforpoints.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg)		end
function onThink()					npcHandler:onThink()					end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
	local bootsid = 1455
	local bootscost = 15

	local ringid = 2145
	local ringcost = 5


	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'vip boots') or msgcontains(msg, 'boots')) then
		selfSay('Do you want to buy Vip Boots fo '.. bootscost ..' premium points?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getAccountPoints(cid) >= bootscost) then
			if(doAccountRemovePoints(cid, bootscost) == TRUE) then
				doPlayerAddItem(cid, bootsid)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)


	elseif(msgcontains(msg, 'expring') or msgcontains(msg, 'ring')) then
		selfSay('Do you want to buy exp ring for '.. ringcost ..' premium points?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getAccountPoints(cid) >= ringcost) then
			if(doAccountRemovePoints(cid, ringcost) == TRUE) then
				doPlayerAddItem(cid, ringid)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
GREAT SCRIPT, THANKS WILL TRY IT OUT ;)
where to put the xml. code for the first script you posted? I mean the lua code :D
 
Great, thanks ;)
 
Last edited:
Here you got with a sample npc for this:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Donator" script="itensforpoints.lua" walkinterval="0" floorchange="0" speed="900">
<health now="150" max="150"/>
<look type="131" head="19" body="19" legs="19" feet="19"/>

<interaction range="3" idletime="60">

<interact keywords="hi" focus="1">
<keywords>hello</keywords>

<response text="Hey there, I sell items only to Donators! To Donate check website or ask Server Staff.">
<action name="idle" value="1"/>
</response>
</interact>

<interact keywords="bye" focus="0">
<keywords>farewell</keywords>

<response text="Good bye."/>
</interact>
</interaction>

</npc>
 
what you don't know?
anyway, I tested it on TFS 0.3.6 pl
and I am GOD on my server!
In my database my account is group 6 and my palyer also group 6....
Anyway I did "!addpoints Damon, 100" = 100 points have been added to Damon's account...
then i wanted to buy from vip npc and said "hi", "vip boots" "yes" , then he said i dont have that item :/
i checked "!points" and i really had no points ;(
Then i tried buying "expring" "yes" then he didnt respond at all..

Then i added points to my other char who trained afk, didn't work, too...
 
Having the same problem as Damon on 0.3.6pl1.
So somewhere in the addpoints area(since the players are not getting points) there would be a newer function of 0.4 that isnt compatable or needs to be added.....is this assumption correct?
I get no errors btw.

Can we fix this please? I can really put this to good use if we can get it to work.
Thanks for any help with this.
:)
 
Hmmmmm....
After looking into this Ive found that I dont have a "premium points" column in "accounts".Could I get the sql query to add that to my database.Hopefully it will work then.
Thanks
:)
 
PHP:
ALTER TABLE `accounts` ADD `premium_points` INT NOT NULL DEFAULT 0;
 
It only works if you agree the points?
Or if they donate the points in shop are the same as ingame?
 
really useful, I use this command in my server xd

@UP

Code:
local keywordHandler = KeywordHandler:new() 
local npcHandler = NpcHandler:new(keywordHandler) 
NpcSystem.parseParameters(npcHandler) 
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end 
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end 
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end 
function onThink() npcHandler:onThink() end 
function creatureSayCallback(cid, type, msg) 
if(not npcHandler:isFocused(cid)) then 
return false 
end 
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
      [2195] = {price = 15},
      [2493] = {price = 25},
      [2361] = {price = 30},
      [8851] = {price = 20},
      [8925] = {price = 30},
      [2640] = {price = 50},
      [2494] = {price = 100},
      [9932] = {price = 50},
      [2472] = {price = 70},
      [8931] = {price = 48}
      }
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if t[item] and getAccountPoints(cid) < t[item].price then
         selfSay("You dont have "..t[item].price.." points", cid)
         else
        doPlayerAddItem(cid, item)
        doAccountRemovePoints(cid, t[item].price)
        selfSay("Here is you item!", cid)
       end
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
            for var, ret in pairs(t) do
                    table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
                end
            openShopWindow(cid, shopWindow, onBuy, onSell)
        end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
Back
Top