• 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 TRADE DONATE

di12345di

New Member
Joined
Aug 1, 2012
Messages
105
Reaction score
0
I need 1 NPC script that swaps items donate from shop $ for premium points can anyone help me? Id of the point is 2157

Sorry for the english, I use a translator.

bump

bump
 
Last edited by a moderator:
I need 1 NPC script that swaps items donate from shop $ for premium points can anyone help me? Id of the point is 2157

Sorry for the english, I use a translator.

bump

bump
Note! I didn't test it.
NPC.xml:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Exchanger" script="exchange.lua" walkinterval="2000" floorchange="0">
   <health now="100" max="100"/>
   <look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
   <parameters>
       <parameter key="message_greet" value="Hello |PLAYERNAME|, ask me for {exchange} your coins to premium items."/>
   </parameters>
</npc>
exchange.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 FindTable(Table, Element)
   for i = 1,#Table do
       local Value = Table[i]
       if Value == Element then
           return Value
       else
           return nil
       end
   end
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_id, items_name, items_cost, items_count, text = {}, {}, {}, {}, ""
    local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `z_shop_offer`;")
    local tmp = result:getDataInt("count")
    result:free()
    local amount = tmp
   for i = 1, amount do
       local check = db.getResult("SELECT * FROM `z_shop_offer` WHERE `id` = '".. i .."' LIMIT 1;")
       if(check:getID() == -1) then
           break
       end
       local item_name = check:getDataString("offer_name")
       local item_id = check:getDataInt("itemid1")
       local item_cost = check:getDataInt("points")
       local item_count = check:getDataInt("count1")
       check:free()
       if #items == 0 then
           text = ".. text .." {".. item_name .."}
       else
           text = ".. text ..", {".. item_name .."}
       end
       table.insert(items_id, item_id)
       table.insert(items_name, item_name)
       table.insert(items_cost, item_cost)
       table.insert(items_count, item_count)
   end
   if(msgcontains(msg, 'exchange') or msgcontains(msg, 'trade')) then
       selfSay('What would you like to buy? Select one: '.. text ..'.', cid)
       setPlayerStorageValue(cid, 99999, 0)
       talkState[talkUser] = 1
   elseif(isInArray(msg, items_name) and talkState[talkUser] == 1) then
       if FindTable(items_name, msg) then
           selfSay('Are you sure that you want to buy '.. msg ..' for '.. items_cost[FindTable(items_name, msg)] ..'?', cid)
           setPlayerStorageValue(cid, 99999, FindTable(items_name, msg))
           talkState[talkUser] = 2           
       else
           selfSay('This item doesn\'t exist in my offer.', cid)
       end
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
       if(doPlayerRemoveItem(cid, 2157, items_cost[getPlayerStorageValue(cid, 99999)])) then
           doPlayerAddItem(cid, items_id[getPlayerStorageValue(cid, 99999)], items_count[getPlayerStorageValue(cid, 99999)])
           selfSay('Here you are.', cid)
       else
           selfSay('Sorry, you don\'t have enough coins.', cid)
       end
       setPlayerStorageValue(cid, 99999, 0)
       talkState[talkUser] = 0
   elseif(msgcontains(msg, 'no') and isInArray({1, 2}, talkState[talkUser])) then
       talkState[talkUser] = 0
       selfSay('Ok then, see you later.', cid)
   end
   return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Note! I didn't test it.
NPC.xml:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Exchanger" script="exchange.lua" walkinterval="2000" floorchange="0">
   <health now="100" max="100"/>
   <look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
   <parameters>
       <parameter key="message_greet" value="Hello |PLAYERNAME|, ask me for {exchange} your coins to premium items."/>
   </parameters>
</npc>
exchange.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 FindTable(Table, Element)
   for i = 1,#Table do
       local Value = Table[i]
       if Value == Element then
           return Value
       else
           return nil
       end
   end
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_id, items_name, items_cost, items_count, text = {}, {}, {}, {}, ""
    local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `z_shop_offer`;")
    local tmp = result:getDataInt("count")
    result:free()
    local amount = tmp
   for i = 1, amount do
       local check = db.getResult("SELECT * FROM `z_shop_offer` WHERE `id` = '".. i .."' LIMIT 1;")
       if(check:getID() == -1) then
           break
       end
       local item_name = check:getDataString("offer_name")
       local item_id = check:getDataInt("itemid1")
       local item_cost = check:getDataInt("points")
       local item_count = check:getDataInt("count1")
       check:free()
       if #items == 0 then
           text = ".. text .." {".. item_name .."}
       else
           text = ".. text ..", {".. item_name .."}
       end
       table.insert(items_id, item_id)
       table.insert(items_name, item_name)
       table.insert(items_cost, item_cost)
       table.insert(items_count, item_count)
   end
   if(msgcontains(msg, 'exchange') or msgcontains(msg, 'trade')) then
       selfSay('What would you like to buy? Select one: '.. text ..'.', cid)
       setPlayerStorageValue(cid, 99999, 0)
       talkState[talkUser] = 1
   elseif(isInArray(msg, items_name) and talkState[talkUser] == 1) then
       if FindTable(items_name, msg) then
           selfSay('Are you sure that you want to buy '.. msg ..' for '.. items_cost[FindTable(items_name, msg)] ..'?', cid)
           setPlayerStorageValue(cid, 99999, FindTable(items_name, msg))
           talkState[talkUser] = 2          
       else
           selfSay('This item doesn\'t exist in my offer.', cid)
       end
   elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
       if(doPlayerRemoveItem(cid, 2157, items_cost[getPlayerStorageValue(cid, 99999)])) then
           doPlayerAddItem(cid, items_id[getPlayerStorageValue(cid, 99999)], items_count[getPlayerStorageValue(cid, 99999)])
           selfSay('Here you are.', cid)
       else
           selfSay('Sorry, you don\'t have enough coins.', cid)
       end
       setPlayerStorageValue(cid, 99999, 0)
       talkState[talkUser] = 0
   elseif(msgcontains(msg, 'no') and isInArray({1, 2}, talkState[talkUser])) then
       talkState[talkUser] = 0
       selfSay('Ok then, see you later.', cid)
   end
   return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


bro example item 8850= 10 points
9935 = 16 points
10350 = 8 points

understand?

points = 2157
 
I thought that you asking for script where NPC is selling all premium items (same as on website - sms shop) for this 2157 points...
 
Do you think it's possible to create it like that?
Code:
if doPlayerRemoveItem(cid, 8850, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ " 5" WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 8850, 1) then
   db.query("UPDATE accounts SET premium_points = premium_points+ " 10 " WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 9935, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ "16 " WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 10350, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ "8" WHERE id = " .. accountId .. ";")
end
 
Code:
if doPlayerRemoveItem(cid, 8850, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ " 5" WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 8850, 1) then
   db.query("UPDATE accounts SET premium_points = premium_points+ " 10 " WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 9935, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ "16 " WHERE id = " .. accountId .. ";")
elseif doPlayerRemoveItem(cid, 10350, 1) then
  db.query("UPDATE accounts SET premium_points = premium_points+ "8" WHERE id = " .. accountId .. ";")
end

What I need is 1 NPC that makes these item changes donate to ***** to keep calling me understand?
 
Last edited by a moderator:
Back
Top