• 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!
 
Maybe a hint:

db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. config.points .. " WHERE `id` = " .. acc_id .. ";")
 
nope :). if it is well scripted (with that i mean the right checks executed in script) then it wont be buggy at all.

I can make it if you want, but more illustration about how it works , cause i dont get it. IS their only 90% of the premium days player choose to transfere is transfered or what :p
 
Yes, it should be like:

Player: hi
NPC: Hi, Player, would you like to transfer some premium points from your account?
Player: yes or transfer
NPC: Ok, You have 1000 premium points, how much you want to transfer?
Player: 1000
NPC: To who this will be transfered? Remember that the comission is 10%, so you will just transfer 900, and 100 will be for me.
Player: Kito
NPC: So you will transfer 900 to Kito, is that right?
Player: Yes.
NPC: Well done!
 
A question : shouldnt when i say bye or move away from the npc the talkuser value is reseted right??

here is a one i made fast
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)
	    elseif tonumber(msg) > getPoints(cid) then
		      selfSay("You only have "..getPoints(cid)..", try again!",cid)
	    else
		
                   t= {}
		      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 {"..getPoints(cid) - math.floor(msg * (per/100)).."} points will go to  me.",cid)
	              talkState[talkUser] = 2
	   end
    elseif talkState[talkUser] == 2 then 
	    
	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:
A question : shouldnt when i say bye or move away from the npc the talkuser value is reseted right??

here is a one i made fast
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)
	    elseif tonumber(msg) > getPoints(cid) then
		      selfSay("You only have "..getPoints(cid)..", try again!",cid)
	    else
		
                   t= {}
		      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 {"..getPoints(cid) - math.floor(msg * (per/100)).."} points will go to  me.",cid)
	              talkState[talkUser] = 2
	   end
    elseif talkState[talkUser] == 2 then 
	    
	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())

What you mean as the talkuser? Anyways repped, I want some info before testing.
 
02:12 Alehv: Hello Kito, would you like to transfer points?
02:12 Kito [1]: transfer
02:12 Alehv: Ok, You have 7190 premium points, how much you want to transfer?
02:13 Kito [1]: 8000
02:13 Alehv: You only have 7190, try again!
02:13 Kito [1]: -0123
02:13 Alehv: To who this will be transfered? Remember that the comission is 10%, so you will just transfer -111 points, and 7301 points will go to me.

Fix it please :)
 
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, value = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '" .. db.escapeString(getPlayerAccount(cid)) .. "' LIMIT 1;"), 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())
 
Back
Top