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

NPC Donation in-game NPC

8408323

Hoster
Joined
Mar 6, 2009
Messages
432
Reaction score
26
I've decided to release this script made by me and hakeee.

Tested on 0.3.6 pl1 But I believe it should work on 0.4 as well. If not, let me know!

It's a in-game donation shop. Which works together with premium_points in MySQL.
How to configure this script?
Well, in donation shop.lua you can add new items that you want the npc to sell/buy. Bpoints is the number of premium_points the items costs, for instance on already added item "Goldnugget" it is Bpoints = 1 which means that every gold nugget costs 1 premium_points. All items are salable, if you put Spoints = 0 the item are not salable. And if you put it for instance Spoints = 2 you can sell that item for 2 premium_points.

How to add more items?
just copy this line
Code:
{id=2157, subType=0, buy=1, sell=0, name="Buyprice:1P", Bpoints = 1, Spoints = 0}[COLOR="#FF0000"],[/COLOR]    --Goldnuggets
and paste it below that line in donation shop.lua in data\npc\scripts. Remember that all lines but the last one need to have a , where I marked it in red above. Otherwise the script will return an error.

Questions? Just leave an reply

Things you need to do:

1. In data\npc create a new file named Donation Shop.xml

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Donation Shop" script="donation shop.lua" walkinterval="2000000000" author="8408323" contact="http://otland.net/members/8408323/">
<health now="150" max="150"/>
<look type="147" head="114" body="94" legs="19" feet="0" addons="3" corpse="2212"/>
	<parameters>
		<parameter key="message_greet" value="Greetings |PLAYERNAME|. I sell lots of donation stuff! Take a look at the donation list when you {trade} with me" />
	</parameters>
</npc>

2.Then go to data\npc\scripts and create a file named donation shop.lua and paste this into it.

Lua:
-- Made by 8408323
-- Used ny Goblinsfoe's Team "goblinsfoe-no-ip.org
-- Contact [url=http://otland.net/members/8408323/]View Profile: 8408323 - OtLand[/url] if you have any problem

local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

local itemWindow = {

	{id=2157, subType=0, buy=1, sell=0, name="Buyprice:1P", Bpoints = 1, Spoints = 0},    --Goldnuggets
	{id=7958, subType=0, buy=1, sell=0, name="Buyprice:5P", Bpoints = 5, Spoints = 2}     --Donated Wand 
	


	}

--{id=5785, subType=0, buy=1, sell=0, name="10P", Bpoints = 10, Spoints = 5},
	--{id=5785, subType=0, buy=0, sell=1, name="5P", Bpoints = 10, Spoints = 5}

local items = {}
for _, item in ipairs(itemWindow) do
	items[item.id] = {
		buyPrice = item.buy,
		sellPrice = item.sell,
		subType = item.subType,
		realName = item.name,
		Bpoints = item.Bpoints or 0,
		Spoints = item.Spoints or 0
	}
end

local function getPlayerMoney(cid)
	return getAccountPremiumPoints(cid)
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not selling it.", cid)
		return
	end

	if(getPlayerMoney(cid) >= amount * items[item].Bpoints) then
		if(getPlayerFreeCap(cid) >= getItemWeightById(item,amount)) then
			local new_item = doCreateItemEx(item, amount)
            local received_item = doPlayerAddItemEx(cid, new_item)
			if received_item == RETURNVALUE_NOERROR then
				selfSay("Thanks for the money!", cid)
				doAccountRemovePremiumPoints(cid, amount * items[item].Bpoints)
			else
				selfSay("You have no space for this item!", cid)
			end
		else
			selfSay("You can't carry this!", cid)
		end
	else
		selfSay("Buy more premium points at {www.goblinsfoe.no-ip.org}", cid)
	end
end

local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not buying it.", cid)
	end

	if(subType < 1) then
		subType = -1
	end
	if(doPlayerRemoveItem(cid, item, amount, subType)) then
		doAccountAddPremiumPoints(cid, items[item].Spoints * amount)
		selfSay("Here you are.", cid)
	else
		selfSay("No item, no deal.", cid)
	end
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid)) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end

function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
		selfSay("Do you want to see my {wares}?", cid)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "wares" or msg == "trade")) then
		selfSay("Pretty nice, right?", cid)
		openShopWindow(cid, itemWindow, onBuy, onSell)
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onPlayerEndTrade(cid)
	selfSay("It was a pleasure doing business with you.", cid)
end

function onThink()
	for i, focus in pairs(focuses) do
		if(not isCreature(focus)) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end

3. After that, go to data\lib and open 050-function.lua and add these functions.

Lua:
-- Premium Points made by 8408323
function getAccountPremiumPoints(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 doAccountAddPremiumPoints(cid, count)
    return db.executeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPremiumPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end
 
function doAccountRemovePremiumPoints(cid, count)
    return db.executeQuery("UPDATE `accounts` SET `premium_points` = '".. getAccountPremiumPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

4.Finally, add this into your database in phpmyadmin.
SQL:
ALTER TABLE accounts ADD COLUMN premium_points VARCHAR(128);

P.s I'm not 100% sure that this is the right section. But I considered to post here since it's a npc :)
And rep me if you want! :)
 
Didn't found any npc like this, so I made one by myself (with the help of hakeee) as well. Thanks! :)
 
Thanks! :)
Well, it's easier for the player to buy from the website. However, this is more like a rpg feeling, and it can be easy to use for some :)
 
how do i get bpoints??

i added the npc but i cant buy anything cause i dont know how to get the bpoints lol


help plz?


nvm i already figured out


good job!
 
Last edited:
i know this is an old thread but i'm having some trouble, the npc does sell and buy the shop tokens but it does not remove or add premium points. im running 0.3.6 and using znote aac and i'm not receiving any errors

edit: the problem is that the premium points in the database is not linking to the websites donation points, so it wont add or remove points from the website
 
Last edited:
Back
Top