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

[Talkaction] !buy donation

oldtimes

Member
Joined
Jan 21, 2013
Messages
311
Reaction score
23
I need a in-game talkaction for buying donation items for premium points.

Can someone help me with this?
I am only asking for a NPC that will sell you items if you got enough premium points on your account.

Using Avesta server.
 
Last edited:
Can you give me that use so I can use it in the script? And the add points if you have that one too.

I just need a talkaction that will take points from the player in mysql server and give you the item you type.

Example: !buy boh , and it will take 1 point from the player in the mysql and add boots of haste to the players.
 
I ment a lua function.

I got no lua function for the paypal to work.
I am using paygol (php files) on the website for people to buy points.

I want them to be able to use this points in-game to buy items by typing for example: "!buy boh" etc

- - - Updated - - -

I ment a lua function.

I can't PM you anymore, it says that "Limos has exceeded their stored private messages quota".
Your inbox is full.
 
Here is the NPC
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Alfonzo" script="donations.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="130" head="114" body="113" legs="114" feet="114" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|, You can {buy} items from me for premium points. You can see in the {list} which items you can buy."/>
    </parameters>
</npc>

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}

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

local function getPremiumPoints(cid)
    local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
       return 0
    end
    local ret = res:getDataInt("premium_points")
    res:free()
    return tonumber(ret)
end

local items = {
    ["thaian sword"] = {points = 100, itemid = 7391},  
    ["golden helmet"] = {points = 100, itemid = 2471}
}

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 x = items[msg:lower()]

    if msgcontains(msg, 'buy') then
        selfSay('Which donate item would you like to buy?', cid)
        talkState[talkUser] = 2
    elseif x and talkState[talkUser] >= 1 then
        selfSay('Do you want to buy 1 '..msg..' for '..x.points..' premium points?', cid)
        xmsg[cid] = msg
        talkState[talkUser] = 3
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        x = items[xmsg[cid]:lower()]
        if getPremiumPoints(cid) >= x.points then
            selfSay('Here you are, have fun with it.', cid)
             doPlayerAddItem(cid, x.itemid, 1)
            db.executeQuery('UPDATE accounts SET premium_points=premium_points-'..x.points..' WHERE id=' .. getPlayerAccountId(cid))
            talkState[talkUser] = 1
        else
            selfSay('You don\'t have enough points.', cid)
            talkState[talkUser] = 1
        end
    elseif msgcontains(msg, 'list') then
        text = 'Donation Items\n'
        for i, x in pairs(items) do
                text = text .. "\n" .. i .. " - "..x.points.." points"
        end
        doShowTextDialog(cid, 7391, "" .. text)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 2 then
        selfSay('You can\'t buy this item from me, look in the {list} which items you can buy.', cid)
    else
        selfSay('What? I don\'t understand what you mean with '..msg..'.', cid)
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Here is the NPC
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Alfonzo" script="donations.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="130" head="114" body="113" legs="114" feet="114" addons="3"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|, You can {buy} items from me for premium points. You can see in the {list} which items you can buy."/>
	</parameters>
</npc>

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

local function getPremiumPoints(cid)
    local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
       return 0
    end
    local ret = res:getDataInt("premium_points")
    res:free()
    return tonumber(ret)
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 items = {
	["Thaian Sword"] = {points = 100, itemid = 7391}, 	
	["Golden Helmet"] = {points = 100, itemid = 2471} 
}

 	local function addCptl(first, rest)
  		return first:upper()..rest:lower()
	end
 
	local x = items[msg:gsub("(%a)([%w_']*)", addCptl)]

	local buy = (msgcontains(msg, 'buy'))
	if buy then
		selfSay('Which donate item would you like to buy?', cid)
		talkState[talkUser] = 2
	end
 
	if x and talkState[talkUser] >= 1 then 
		selfSay('Do you want to buy 1 '..msg..' for '..x.points..' premium points?', cid)
		xmsg = msg
		talkState[talkUser] = 3
	end
	local agree = (msgcontains(msg, 'yes'))
	if agree and talkState[talkUser] == 3 then 
		x = items[xmsg:gsub("(%a)([%w_']*)", addCptl)]
		if getPremiumPoints(cid) >= x.points then
			selfSay('Here you are, have fun with it.', cid)
 			doPlayerAddItem(cid, x.itemid, 1)
			db.executeQuery('UPDATE accounts SET premium_points=premium_points-'..x.points..' WHERE id=' .. getPlayerAccountId(cid))
			talkState[talkUser] = 1
		else
			selfSay('You don\'t have enough points.', cid)
			talkState[talkUser] = 1
		end
	end
 
	local list = (msgcontains(msg, 'list'))
	if list then
	text = 'Donation Items\n'
		for i, x in pairs(items) do
				text = text .. "\n" .. i .. " - "..x.points.." points"
		end
		doShowTextDialog(cid, 7391, "" .. text)
		talkState[talkUser] = 1
	end
 
	if not x and not list and not buy and not agree and talkState[talkUser] == 2 then
		selfSay('You can\'t buy this item from me, look in the {list} which items you can buy.', cid)
	elseif not x and not list and not buy and not agree and talkState[talkUser] ~= 2 then
		selfSay('What? I don\'t understand what you mean with '..msg..'.', cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Thank you.
REP+++

Can you make me the talkaction aswell?
Will rep you +++ !


Sorry to say, but the npc does not work :(

(the NPC is only responding to "hi" and nothing else.)
 
Last edited:
It's tested on TFS 0.3.6pl1, incase it's usefull for other people.

Talkaction
XML:
<talkaction words="!buy" event="script" value="points.lua"/>
LUA:
local items = {
	["thaian sword"] = {points = 100, itemid = 7391}, 	
	["golden helmet"] = {points = 100, itemid = 2471} 
}

local function getPremiumPoints(cid)
    local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
       return 0
    end
    local ret = res:getDataInt("premium_points")
    res:free()
    return tonumber(ret)
end

function onSay(cid, words, param)

	local param = string.lower(param)
 
	local x = items[param]

	if x then
		if getPremiumPoints(cid) >= x.points then
			doPlayerAddItem(cid, x.itemid, 1)
			doPlayerSendTextMessage(cid, 25, "You have bought 1 "..param.." for "..x.points.." premium points.")
			db.executeQuery('UPDATE accounts SET premium_points=premium_points-'..x.points..' WHERE id=' .. getPlayerAccountId(cid))
		else
			doPlayerSendCancel(cid, "You don\'t have enough premium points.")
		end
	end
	if not x then
		doPlayerSendCancel(cid, "You can\'t buy this item.")
	end
	return true
end

Example: !buy golden helmet



Edit: the NPC and the talkaction work, but not on his server (and he doesn't get errors).
He uses Avesta 7.72
 
Last edited:

Similar threads

Back
Top