• 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 that transfer premium points!

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hi there, could someone make an NPC that transfer your premium points to other players, they should retrieve you like X amount, and then they will transfer a 90% of the value (comision for using the system).

Would be very nice!
 
It always says: 23:46 Alehv: Ok, You have 0 premium points, how much you want to transfer? -- And I have like 2000 premium points on account... BUG?
 
This should be WORKING FINE
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic, Amount = {}, {}
 
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 per = 90 -- percentage that will be transferred to player 
 
function getPoints(cid) 
    local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
	local value = 0
	if(res:getID() ~= -1) then
		value = res:getDataInt("premium_points")
		res:free()
	end
return value
end
 
function greetCallback(cid)
	Topic[cid], Amount[cid] = 0, nil
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'transfer') or msgcontains(msg, 'yes') then
	selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 then 
		msg = tonumber(msg)
		if not msg then
			return selfSay("You must type the amount of points, try again!",cid)
		end
 
		msg = math.abs(msg)
 
		if msg > getPoints(cid) then
			return selfSay("You only have "..getPoints(cid)..", try again!",cid)
		end
 
		selfSay("Who do you want to transfer to? Remember that the comission is {".. 100-per.."%}, so you will only transfer {"..math.floor(msg * (per/100)).."} points, and {"..getPoints(cid) - math.floor(msg * (per/100)).."} points will go to  me.",cid)
		Topic[cid] = 2
		Amount[cid] = msg
	elseif Topic[cid] == 2 then 
		local to = getAccountIdByName(msg)
		if to > 0 then
			db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. Amount[cid] .. " WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1;")
			db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. math.floor(Amount[cid] * (per/100)) .. " WHERE `id` = " .. to .. " LIMIT 1;")
			selfSay("You have successfuly transfered " .. math.floor(Amount[cid] * (per/100)) .. " points to " .. msg .. ".",cid)
			Topic[cid], Amount[cid] = 0, nil
		else
			selfSay("Player doesnt exist, try again!",cid)
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
BUG!

19:23 Alehv: Hello Kito, would you like to transfer points?
19:23 Kito [21]: transfer
19:23 Alehv: Ok, You have 48190 premium points, how much you want to transfer?
19:23 Kito [21]: 5000
19:23 Alehv: Who do you want to transfer to? Remember that the comission is 1%, so you will only transfer 4950 points, and 43240 points will go to me.
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic, Amount = {}, {}
 
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 per = 90 -- percentage that will be transferred to player 
 
function getPoints(cid) 
    local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
	local value = 0
	if(res:getID() ~= -1) then
		value = res:getDataInt("premium_points")
		res:free()
	end
return value
end
 
function greetCallback(cid)
	Topic[cid], Amount[cid] = 0, nil
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'transfer') or msgcontains(msg, 'yes') then
	selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 then 
		msg = tonumber(msg)
		if not msg then
			return selfSay("You must type the amount of points, try again!",cid)
		end
 
		msg = math.abs(msg)
 
		if msg > getPoints(cid) then
			return selfSay("You only have "..getPoints(cid)..", try again!",cid)
		end
 
		selfSay("Who do you want to transfer to? Remember that the comission is {".. 100-per.."%}, so you will only transfer {"..math.floor(msg * (per/100)).."} points, and {".. msg - math.floor(msg * (per/100)).."} points will go to  me.",cid)
		Topic[cid] = 2
		Amount[cid] = msg
	elseif Topic[cid] == 2 then 
		local to = getAccountIdByName(msg)
		if to > 0 then
			db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. Amount[cid] .. " WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1;")
			db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. math.floor(Amount[cid] * (per/100)) .. " WHERE `id` = " .. to .. " LIMIT 1;")
			selfSay("You have successfuly transfered " .. math.floor(Amount[cid] * (per/100)) .. " points to " .. msg .. ".",cid)
			Topic[cid], Amount[cid] = 0, nil
		else
			selfSay("Player doesnt exist, try again!",cid)
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Found a bug!

17:08 Alehv: Hello Kito, would you like to transfer points?
17:09 Kito [151]: transfer
17:09 Alehv: Ok, You have 47990 premium points, how much you want to transfer?
17:09 Kito [151]: /points Kito, -47900
17:09 Kito [151]: 2500
17:09 Alehv: You only have 90, try again!
17:09 Kito [151]: transfer
17:09 Alehv: Ok, You have 90 premium points, how much you want to transfer?
17:09 Kito [151]: 90
17:09 Alehv: Who do you want to transfer to? Remember that the comission is 2%, so you will only transfer 88 points, and 2 points will go to me.
17:09 Kito [151]: /points kito, -90
17:10 Kito [151]: Volxiimba
17:10 Alehv: You have successfuly transfered 88 points to Volxiimba.

Now I have -90 points, because had at the begining 90, but spent them, and then transfered them, just duplicated my points.

So when Im at black part, if I spent my points, I will transfer them too...
 
Im not friendly with NPCs yet, I've been learning java, now a little of lua (actions, movements and creaturescripts) but NPC, I dont know much about it, if I could do that by my self, I wouldn't post it.
 
I didnt know these error as i just edited the script by cyko so here use my main script i posted, fixed the first error of negative amount.
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
 
 --[[Edit]]--
  local per = 90 -- percentege that will be sent to player 
 
 
 --[[functions]]--
function getPoints(cid) 
    local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
	local value = 0
	if(res:getID() ~= -1) then
		value = res:getDataInt("premium_points")
		res:free()
	end
return value
end
function transfer(from,to,amount,perc) --percent equal the amount that will be tranferred
local pid = (getAccountIdByName(string.lower(to)))
local player = getAccountIdByName(string.lower(getCreatureName(from)))
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` - '"..amount.."' WHERE `id` = '"..player.."' ;")
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` + '"..math.floor(amount * (perc/100)).."' WHERE `id` = '"..pid.."' ;")
 
end
 
--[[Script start]]--
 
function creatureSayCallback(cid, type, msg)
 
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and talkState[talkUser] ~= 1 and talkState[talkUser] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         talkState[talkUser] = 1
 
    elseif talkState[talkUser] == 1 then 
 
            if not tonumber(msg) then
				selfSay("You must type the amount of points, try again!",cid)
			else
				msg = math.abs(msg)
				t= {}
 
					if  tonumber(msg) > getPoints(cid) then
						return selfSay("You only have "..getPoints(cid)..", try again!",cid)
					end
 
		        table.insert(t,msg)
		        table.insert(t,math.floor(msg * (per/100)))
		        selfSay("To who this will be transfered? Remember that the comission is {".. 100-per.."%}, so you will just transfer {"..math.floor(msg * (per/100)).."} points, and {"..msg - math.floor(msg * (per/100)).."} points will go to  me.",cid)
				talkState[talkUser] = 2
			end
 
	elseif talkState[talkUser] == 2 then 
        if getPoints(cid) < t[2] then
			selfSay("You only have "..getPoints(cid)..", try again!",cid) 
			talkState[talkUser] = 1
			return true
		end
		if getAccountIdByName(msg) > 0 then
			transfer(cid,msg,t[1],per)
			selfSay("You have successfuly transfered "..t[2].." points to "..msg..".",cid)
			talkState[talkUser] = 0
		else
			selfSay("Player doesnt exist, try again!",cid)
		end
	end
 
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
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
 
 --[[Edit]]--
  local per = 90 -- percentege that will be sent to player 
 
 
 --[[functions]]--
function getPoints(cid) 
    local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
	local value = 0
	if(res:getID() ~= -1) then
		value = res:getDataInt("premium_points")
		res:free()
	end
return value
end
function transfer(from,to,amount,perc) --percent equal the amount that will be tranferred
local pid = (getAccountIdByName(string.lower(to)))
local player = getAccountIdByName(string.lower(getCreatureName(from)))
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` - '"..amount.."' WHERE `id` = '"..player.."' ;")
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` + '"..math.floor(amount * (perc/100)).."' WHERE `id` = '"..pid.."' ;")
 
end
 
--[[Script start]]--
 
function creatureSayCallback(cid, type, msg)
 
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if (msgcontains(msg, 'transfer') or msgcontains(msg, 'yes')) and talkState[talkUser] ~= 1 and talkState[talkUser] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         talkState[talkUser] = 1
 
    elseif talkState[talkUser] == 1 then 
 
            if not tonumber(msg) then
				selfSay("You must type the amount of points, try again!",cid)
			else
				msg = math.abs(msg)
				t= {}
 
					if tonumber(msg) > getPoints(cid) then
						return selfSay("You only have "..getPoints(cid)..", try again!",cid)
					end
 
		        table.insert(t,msg)
		        table.insert(t,math.floor(msg * (per/100)))
		        selfSay("To who this will be transfered? Remember that the comission is {".. 100-per.."%}, so you will just transfer {"..math.floor(msg * (per/100)).."} points, and {"..msg - math.floor(msg * (per/100)).."} points will go to  me.",cid)
				talkState[talkUser] = 2
			end
 
	elseif talkState[talkUser] == 2 then 
        if getPoints(cid) < t[2] then
			selfSay("You only have "..getPoints(cid)..", try again!",cid) 
			talkState[talkUser] = 1
			return true
		end
		if getAccountIdByName(msg) > 0 then
			transfer(cid,msg,t[1],per)
			selfSay("You have successfuly transfered "..t[2].." points to "..msg..".",cid)
			talkState[talkUser] = 0
		else
			selfSay("Player doesnt exist, try again!",cid)
		end
	end
 
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Have 1 error, fixed.
 
Look here..

Code:
 if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and talkState[talkUser] ~= 1 and talkState[talkUser] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         talkState[talkUser] = 1
 
LUA:
    if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and talkState[talkUser] ~= 1 and talkState[talkUser] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         talkState[talkUser] = 1

Look here..

Code:
 if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and talkState[talkUser] ~= 1 and talkState[talkUser] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         talkState[talkUser] = 1

which diference??
 
19:05 Kito [151]: hi
19:05 Kito [151]: transfer
19:05 Alehv: Ok, You have 500 premium points, how much you want to transfer?
19:05 Kito [151]: 2300
19:05 Alehv: You only have 500, try again!
19:05 Kito [151]: 200
19:05 Alehv: To who this will be transfered? Remember that the comission is 1%, so you will just transfer 198 points, and 2 points will go to me.
19:05 Kito [151]: bye

19:05 Alehv: Good bye, Kito!
19:05 Kito [151]: hi
19:05 Alehv: Hello Kito, would you like to transfer points?
19:05 Kito [151]: transfer
19:05 Alehv: Player doesnt exist, try again!

Nice xD
 
I thought the talkstate should be set to 0 on sayibg bye but here is it :p
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
 
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
 
 --[[Edit]]--
  local per = 90 -- percentege that will be sent to player 
 
 
 --[[functions]]--
function getPoints(cid) 
    local res = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."' LIMIT 1 ;")
	local value = 0
	if(res:getID() ~= -1) then
		value = res:getDataInt("premium_points")
		res:free()
	end
return value
end
function transfer(from,to,amount,perc) --percent equal the amount that will be tranferred
local pid = (getAccountIdByName(string.lower(to)))
local player = getAccountIdByName(string.lower(getCreatureName(from)))
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` - '"..amount.."' WHERE `id` = '"..player.."' ;")
 db.executeQuery("UPDATE `accounts` set `premium_points`=`premium_points` + '"..math.floor(amount * (perc/100)).."' WHERE `id` = '"..pid.."' ;")
 
end
 
function greetCallback(cid)
	Topic[cid] = 0
	return true
end
--[[Script start]]--
 
function creatureSayCallback(cid, type, msg)
 
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (msgcontains(msg, 'transfere') or msgcontains(msg, 'yes')) and Topic[cid] ~= 1 and Topic[cid] ~= 2 then
	 selfSay("Ok, You have "..getPoints(cid).." premium points, how much you want to transfer?",cid)
         Topic[cid] = 1
 
    elseif Topic[cid] == 1 then 
 
            if not tonumber(msg) then
				selfSay("You must type the amount of points, try again!",cid)
			else
				msg = math.abs(msg)
				t= {}
 
					if tonumber(msg) > getPoints(cid) then
						return selfSay("You only have "..getPoints(cid)..", try again!",cid)
					end
 
		        table.insert(t,msg)
		        table.insert(t,math.floor(msg * (per/100)))
		        selfSay("To who this will be transfered? Remember that the comission is {".. 100-per.."%}, so you will just transfer {"..math.floor(msg * (per/100)).."} points, and {"..msg - math.floor(msg * (per/100)).."} points will go to  me.",cid)
				Topic[cid] = 2
			end
 
	elseif Topic[cid] == 2 then 
        if getPoints(cid) < t[2] then
			selfSay("You only have "..getPoints(cid)..", try again!",cid) 
			Topic[cid] = 1
			return true
		end
		if getAccountIdByName(msg) > 0 then
			transfer(cid,msg,t[1],per)
			selfSay("You have successfuly transfered "..t[2].." points to "..msg..".",cid)
			Topic[cid] = 0
		else
			selfSay("Player doesnt exist, try again!",cid)
		end
	end
 
	return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thanks, I can't rep you, it says: You must spread some Reputation around before giving it to Damadger again.
I've repped a other people... It seems that you can rep just once.
 
Could this be updated and just accept only entire numbers, without decimals?
Found a bug to duplicate points using decimals.

PS: Added a part at line 75

doWriteLogFile("data/logs/points_transfer.txt", "".. getCreatureName(cid) .." transfered "..t[2].." to "..msg..".")

So at /logs/points_transfer.txt you will find who is trying to scam or have a controll about this service.
 
Last edited:
Back
Top