Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ACCOUNT_TYPE_NORMAL = 1
- ACCOUNT_TYPE_TUTOR = 2
- ACCOUNT_TYPE_GAMEMASTER = 3
- MESSAGE_LOOT = 29
- MESSAGE_TRADE_NPC = 30
- MESSAGE_EVENT_GUILD = 31
- MESSAGE_PARTY_MANAGEMENT = 32
- MESSAGE_PARTY = 33
- MESSAGE_REPORT = 36
- MESSAGE_HOTKEY_USE = 37
- MESSAGE_TUTORIAL_HINT = 38
- getPlayerByNameWildcard = getPlayerByName
- doCreatureSetStorage = setPlayerStorageValue
- doPlayerSetStorageValue = setPlayerStorageValue
- getCreatureStorage = getPlayerStorageValue
- getCreatureSkullType = getPlayerSkullType
- getCreatureSkull = getPlayerSkullType
- getNpcId = getNpcCid
- doBroadcastMessage = broadcastMessage
- db.executeQuery = db.query
- getStorage = getGlobalStorageValue
- doSetStorage = setGlobalStorageValue
- getItemNameById = getItemName
- getItemWeightById = getItemWeight
- getItemDescriptionsById = getItemDescriptions
- getItemInfo = getItemDescriptions
- getThingFromPos = getThingfromPos
- getThingPosition = getThingPos
- string.boolean = function (input)
- local tmp = type(input)
- if(tmp == 'boolean') then
- return input
- end
- if(tmp == 'number') then
- return input > 0
- end
- local str = string.lower(tostring(input))
- return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
- end
- getBooleanFromString = string.boolean
- function getPlayerAccount(pid)
- getAccountNumberByPlayerName(getPlayerByName(pid))
- end
- function getItemArticleById(itemid)
- return getItemInfo(itemid).article
- end
- function getItemPluralNameById(itemid)
- return getItemInfo(itemid).plural
- end
- math.round = function(num, idp)
- return tonumber(string.format("%." .. (idp or 0) .. "f", num))
- end
- exhaustion =
- {
- check = function (cid, storage)
- if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
- return false
- end
- return getPlayerStorageValue(cid, storage) >= os.time()
- end,
- get = function (cid, storage)
- if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
- return false
- end
- local exhaust = getPlayerStorageValue(cid, storage)
- if(exhaust > 0) then
- local left = exhaust - os.time()
- if(left >= 0) then
- return left
- end
- end
- return false
- end,
- set = function (cid, storage, time)
- setPlayerStorageValue(cid, storage, os.time() + time)
- end,
- make = function (cid, storage, time)
- local exhaust = exhaustion.get(cid, storage)
- if(not exhaust) then
- exhaustion.set(cid, storage, time)
- return true
- end
- return false
- end
- }
- function doComparePositions(position, positionEx)
- return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
- end
- function getArea(position, x, y)
- local t = {}
- for i = (position.x - x), (position.x + x) do
- for j = (position.y - y), (position.y + y) do
- table.insert(t, {x = i, y = j, z = position.z})
- end
- end
- return t
- end
- function Position(x, y, z, stackpos)
- local position = {x = 0, y = 0, z = 0}
- if(isNumeric(x .. y .. z)) then
- position = {x = x, y = y, z = z}
- if(isNumeric(stackpos)) then
- position.stackpos = stackpos
- end
- end
- return position
- end
- function isValidPosition(position)
- return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
- and position.y > 0 and position.z >= 0 and position.z <= 15)
- end
- -- googled functions used to convert ip
- -- source: http://www.dialectronics.com/Lua/code/BinDecHex.shtml
- local hex2bin = {
- ["0"] = "0000",
- ["1"] = "0001",
- ["2"] = "0010",
- ["3"] = "0011",
- ["4"] = "0100",
- ["5"] = "0101",
- ["6"] = "0110",
- ["7"] = "0111",
- ["8"] = "1000",
- ["9"] = "1001",
- ["a"] = "1010",
- ["b"] = "1011",
- ["c"] = "1100",
- ["d"] = "1101",
- ["e"] = "1110",
- ["f"] = "1111"
- }
- function Hex2Bin(s)
- local ret = ""
- local i = 0
- for i in string.gfind(s, ".") do
- i = string.lower(i)
- ret = ret.." "..hex2bin[i]
- end
- return ret
- end
- function Bin2Dec(s)
- local num = 0
- local ex = string.len(s) - 1
- local l = 0
- l = ex + 1
- for i = 1, l do
- b = string.sub(s, i, i)
- if b == "1" then
- num = num + 2^ex
- end
- ex = ex - 1
- end
- return string.format("%u", num)
- end
- -- source: http://www.forums.evilmana.com/psp-lua-codebase/string-replace-string-insert/
- function string.replace(value, insert, place)
- if place == nil then
- place = string.len(value)+1
- end
- return string.sub( value, 1, place-1) .. string.gsub(string.sub(value, place,place), string.sub(value, place,place), insert) .. string.sub( value, place+string.len(insert), string.len(value))
- end
- -- end of googled functions
- function getPlayerIPv4(pid)
- local numbers = {}
- local ip_bin = Hex2Bin(string.format("%x",getPlayerIp(pid)))
- local a = string.replace(ip_bin,".",-10)
- local b = string.replace(a,".",-20)
- local c = string.replace(b,".",-30)
- local d = string.gsub(c, " ", "")
- local e = string.sub(d, -8, -1)
- local f = string.sub(d, -17, -10)
- local g = string.sub(d, -26, -19)
- local h = string.sub(d, -35, -28)
- return Bin2Dec(e).."."..Bin2Dec(f).."."..Bin2Dec(g).."."..Bin2Dec(h)
- end
- function doRevertIp(str)
- local i, ip = 4, {}
- for b in str:gmatch("(%d+).?") do
- ip[i] = b
- i = i - 1
- end
- if(not ip[1] or not ip[2] or not ip[3] or not ip[4]) then
- return nil
- end
- return table.concat(ip, ".")
- end
- function choose(...)
- local arg = {...}
- return arg[math.random(1, table.maxn(arg))]
- end
- function doPlayerAddExpEx(cid, amount)
- if(not doPlayerAddExp(cid, amount)) then
- return false
- end
- local position = getThingPosition(cid)
- doPlayerSendTextMessage(cid, MESSAGE_EXPERIENCE, "You gained " .. amount .. " experience.", amount, COLOR_WHITE, position)
- local spectators, name = getSpectators(position, 7, 7), getCreatureName(cid)
- for _, pid in ipairs(spectators) do
- if(isPlayer(pid) and cid ~= pid) then
- doPlayerSendTextMessage(pid, MESSAGE_EXPERIENCE_OTHERS, name .. " gained " .. amount .. " experience.", amount, COLOR_WHITE, position)
- end
- end
- return true
- end
- function getItemTopParent(uid)
- local parent = getItemParent(uid)
- if(not parent or parent.uid == 0) then
- return nil
- end
- while(true) do
- local tmp = getItemParent(parent.uid)
- if(tmp and tmp.uid ~= 0) then
- parent = tmp
- else
- break
- end
- end
- return parent
- end
- function getItemHolder(uid)
- local parent = getItemParent(uid)
- if(not parent or parent.uid == 0) then
- return nil
- end
- local holder = nil
- while(true) do
- local tmp = getItemParent(parent.uid)
- if(tmp and tmp.uid ~= 0) then
- if(tmp.itemid == 1) then -- a creature
- holder = tmp
- break
- end
- parent = tmp
- else
- break
- end
- end
- return holder
- end
- function valid(f)
- return function(p, ...)
- if(isCreature(p)) then
- return f(p, ...)
- end
- end
- end
- function doSetItemText(uid, text, writer, date)
- local thing = getThing(uid)
- if(thing.itemid < 100) then
- return false
- end
- doItemSetAttribute(uid, "text", text)
- if(writer ~= nil) then
- doItemSetAttribute(uid, "writer", tostring(writer))
- if(date ~= nil) then
- doItemSetAttribute(uid, "date", tonumber(date))
- end
- end
- return true
- end
- function doSendAnimatedText(...)
- print("doSendAnimatedText is now a deprecated function.")
- return true
- end
- function doPlayerSendToChannel(cid, target, type, text, channel, time)
- return doCreatureChannelSay(cid, target, text, type, channel)
- end
- function getItemWeaponType(uid)
- local thing = getThing(uid)
- if(thing.itemid < 100) then
- return false
- end
- return getItemInfo(thing.itemid).weaponType
- end
- function getItemRWInfo(uid)
- local thing = getThing(uid)
- if(thing.itemid < 100) then
- return false
- end
- local item, flags = getItemInfo(thing.itemid), 0
- if(item.readable) then
- flags = 1
- end
- if(item.writable) then
- flags = flags + 2
- end
- return flags
- end
- function doPlayerWithdrawMoney(cid, amount)
- local balance = getPlayerBalance(cid)
- if(amount > balance or not doPlayerAddMoney(cid, amount)) then
- return false
- end
- doPlayerSetBalance(cid, balance - amount)
- return true
- end
- function doPlayerDepositMoney(cid, amount)
- if(not doPlayerRemoveMoney(cid, amount)) then
- return false
- end
- doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
- return true
- end
- function doPlayerWithdrawAllMoney(cid)
- return doPlayerWithdrawMoney(cid, getPlayerBalance(cid))
- end
- function doPlayerDepositAllMoney(cid)
- return doPlayerDepositMoney(cid, getPlayerMoney(cid))
- end
- function doPlayerTransferAllMoneyTo(cid, target)
- return doPlayerTransferMoneyTo(cid, target, getPlayerBalance(cid))
- end
- string.trim = function (str)
- return str:gsub("^%s*(.-)%s*$", "%1")
- end
- string.explode = function (str, sep, limit)
- if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
- return {}
- end
- local i, pos, tmp, t = 0, 1, "", {}
- for s, e in function() return string.find(str, sep, pos) end do
- tmp = str:sub(pos, s - 1):trim()
- table.insert(t, tmp)
- pos = e + 1
- i = i + 1
- if(limit ~= nil and i == limit) then
- break
- end
- end
- tmp = str:sub(pos):trim()
- table.insert(t, tmp)
- return t
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement