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

doPlayerAddDepotItem, getInstantSpells, setPlayerRK

Maguss

New Member
Joined
May 17, 2009
Messages
4
Reaction score
1
DoPlayerAddDepotItem

Syntax:
doPlayerAddDepotItem( int cid , mixed item [, mixed count ] )


This function add the item and count specifieds on cid's depot, and both item/count can be an integer or table value.
(Unfortunately, the player have to be kicked off, when he log in the item will be on his depot.)

Return values:
true on sucess, false on failure.

Example usage:
Code:
local Item = 2400 --Magic Sword
if (doPlayerAddDepotItem(cid, Item) ~= TRUE) then
	Mensagem("Failure")
	return
end
Code:
local Item = {2400, 2148, 2152, 2160} -- Magic Sword, Gold Coin, Platinum Coin, Crystal Coin
local Qtdade = {1, 100, 10, 5} -- Count coucerning Item's values.
doPlayerAddDepotItem(cid, Item, Qtdade)
Function:
Code:
function doPlayerAddDepotItem(cid, item, count)
    local item,count,pid = type(item)=="table" and item or {item},type(count)=="table" and count or {(count or 1)},getPlayerGUID(cid)
    doRemoveCreature(cid)
    for k,v in ipairs(item) do
        local ls = db.getResult("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = "..pid.." ORDER BY `sid` DESC LIMIT 1")
        return db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ("..pid..", "..(ls:getDataInt("sid")+1)..", 101, "..v..", "..count[k]..", '"..(count[k] > 1 and string.format("%x",count[k]) or '').."')") or false
    end
end

getInstantSpells

Syntax:
getInstantSpells([ int vocid ] )


Silimar to getPlayerInstantSpellsInfo(), but it takes results from vocation, not player. If you don't set vocid, then it will return all spells.

Return values:
A table with all result matches and these keys (words, name, level, mlevel, mana, manapercent) on sucess or table nil on failure.

Example usage:
Code:
--A talkaction !spelldruid that shows all druid's spells.
function onSay(cid)
    local text = ""
    for k,v in ipairs(getInstantSpells(2)) do --Here you set vocation id
        text = text..v.name.."\nWords: "..v.words.."\nLevel: "..v.level.."\nMana: "..(v.mana == 0 and v.manapercent.."%" or v.mana).."\n\n"
    end
    doShowTextDialog(cid, 2175, string.trim(text))
end
Function:
Code:
function getInstantSpells(voc)
    local voc = voc and (getVocationInfo(voc).name or nil) or nil
    local spell = io.open(getDataDir().."/spells/spells.xml")
    local r,cts = {},spell:read("*a")
	for t,name,xml in string.gmatch(cts,'<(%a+) name="(.-)".->(.-)</[^s]') do
		if (t ~= "rune") then
			vocs = {""}
			for voc in string.gmatch(xml,'"(.-)"') do table.insert(vocs,voc) end
			if (isInArray(vocs,voc)) then table.insert(r,getInstantSpellInfo(name)) end
		end
	end
    spell:close()
    return r
end

setPlayerRecoveryKey

Syntax:
setPlayerRecoveryKey( int cid )


Sets a new recovery key to the player cid, and don't sets repeated rks.

Return values:
String with new recovery key on sucess or false on failure.

Example usage:
Code:
--talkaction !newrk that sets it one time
function onSay(cid)
    if (getPlayerStorageValue(cid, 78789) == -1) then
        local newRK = setPlayerRecoveryKey(cid)
        if (newRK) then
            Message("RK changed with sucess! Your new rk is: "..newRK)
            setPlayerStorageValue(cid, 78789, 1)
        else
            Message("There was an error while trying to change your rk!")
        end
    else
        Message("You already changed your rk!")
    end
end
Function:
Code:
function setPlayerRecoveryKey(cid)
    local wd,newrk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",""
    for i = 0, 15 do
        tmp = math.random(1,#wd)
        newrk = newrk..string.sub(wd,tmp,tmp)
    end
    local newrk = string.gsub(newrk, "(....)", "%1-", 3)
	local keyexists = db.getResult("SELECT * FROM `accounts` WHERE `key` = '"..newrk.."'")
	if (keyexists:getID() ~= -1) then return setPlayerRecoveryKey(cid) end
    return db.executeQuery("UPDATE `accounts` SET `key` = '"..newrk.."' WHERE `id` = "..getPlayerAccountId(cid)) and newrk or false
end
 
Last edited:
doPlayerAddDepotItem, usefull for SMS Shop, player receive items to depo ;)
 
Hey. Can I add actionID for depositing item (doPlayerAddDepotItem)?
if you are able to serialize it into a binary sure

btw i dont think that function works while the player is online
 
Back
Top