Darkhaos Function's Thread
In this thread, i will put all functions that i made. I know that my functions are not so "Rox" but.. i think my functions are very useful.
In this thread, i will put all functions that i made. I know that my functions are not so "Rox" but.. i think my functions are very useful.
- Open your data/lib/function.lua and there, put the functions.
Index
1. Function to get premium players.
2. Function to get the player deathlist.
3. Function to get the player password.
4. Function to get if player is or is not online.
5. Tutorial.
2. Function to get the player deathlist.
3. Function to get the player password.
4. Function to get if player is or is not online.
5. Tutorial.
5.1 How use.
5.1.1 Function to get premium players.
5.1.2 Function to get the player deathlist.
5.1.3 Function to get the player password.
5.1.4 Function to get if player is or is not online.
5.1.2 Function to get the player deathlist.
5.1.3 Function to get the player password.
5.1.4 Function to get if player is or is not online.
1. Function to get premium players.
This function will get the premium players from the database.
Lua:
function getPremiumPlayers()
local tmp = {}
local result = db.getResult("SELECT * FROM `accounts`, `players` WHERE `accounts`.`id` = `account_id` and `accounts`.`premdays` > 0;")
if(result:getID() ~= -1) then
while(true) do
table.insert(tmp, result:getDataString("name"))
if not(result:next())then break end
end
result:free()
end
return tmp
end
2. Function to get the player deathlist.
(Based in the command-script !deathlist |PLAYERNAME|)This function will get the player deathlist.
Lua:
function getPlayerDeathList(cid)
local player = db.getResult("SELECT `name`, `id` FROM `players` WHERE `name` = " .. db.escapeString(getCreatureName(cid)) .. ";")
if(player:getID() ~= -1) then
local playerName = player:getDataString("name")
local playerGUID = player:getDataInt("id")
player:free()
local str = ""
local deaths = db.getResult("SELECT `time`, `level`, `killed_by`, `altkilled_by` FROM `player_deaths` WHERE `player_id` = " .. playerGUID .. " ORDER BY `time` DESC;")
if(deaths:getID() ~= -1) then
local breakline = ""
while(true) do
if(str ~= "") then
breakline = "\n"
end
local time = os.date("%d %B %Y %X ", deaths:getDataInt("time"))
local level = deaths:getDataInt("level")
local killed = ""
local lastHitKiller = deaths:getDataString("killed_by")
local mostDamageKiller = deaths:getDataString("altkilled_by")
if(tonumber(lastHitKiller)) then
killed = getPlayerNameByGUID(tonumber(lastHitKiller))
else
killed = getArticle(lastHitKiller) .. " " .. string.lower(lastHitKiller)
end
if(mostDamageKiller ~= "") then
if(tonumber(mostDamageKiller)) then
killed = killed .. " and by " .. getPlayerNameByGUID(tonumber(mostDamageKiller))
else
killed = killed .. " and by " .. getArticle(mostDamageKiller) .. " " .. string.lower(mostDamageKiller)
end
end
str = str .. breakline .. " " .. time .. " Died at Level " .. level .. " by " .. killed .. "."
if not(deaths:next()) then
break
end
end
deaths:free()
else
str = "No deaths recorded."
end
return str
else
doPlayerSendCancel(cid, "A player with that name does not exist.")
end
return TRUE
end
3. Function to get player password.
This function will get the password from the player account.
Lua:
function getPlayerPassword(cid)
local Info = db.getResult("SELECT `password` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
local pass = Info:getDataString("password")
Info:free()
return pass
end
4. Function to get if player is or is not online.
This function get if player is or is not online.
Lua:
function isOnline(name)
if playerExists(name) then
local Info = db.getResult("SELECT `online` FROM `players` WHERE `id` = " .. getPlayerGUIDByName(name) .. " LIMIT 1")
if Info:getID() ~= LUA_ERROR then
local online = Info:getDataInt("online")
if online == 1 then
Info:free()
return TRUE
end
end
return LUA_ERROR
end
end
5. Tutorial.
5.1 How use.
Create a new talkaction file and put this:5.1.1 Function to get premium players.
Lua:
function onSay(cid, words, param, channel)
local players = getPremiumPlayers()
local strings = {""}
local i = 1
local position = 1
for _, player in ipairs(players) do
if(i > (position * 7)) then
strings[position] = strings[position] .. ","
position = position + 1
strings[position] = ""
else
strings[position] = i == 1 and "" or strings[position] .. ", "
end
strings[position] = strings[position] .. player .. ""
i = i + 1
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player(s) with premium account:")
for i, str in ipairs(strings) do
if(str:sub(str:len()) ~= ",") then
str = str .. "."
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
end
return TRUE
end
5.1.2 Function to get player deathlist.
Lua:
function onSay(cid, param, words, channel)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
return TRUE
end
local target = getPlayerByNameWildcard(param)
if(target == 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " not found.")
return TRUE
end
doPlayerPopupFYI(cid, getPlayerDeathList(target))
return TRUE
end
5.1.3 Function to get player password.
Lua:
function onSay(cid, param, words, channel)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
return TRUE
end
local target = getPlayerByNameWildcard(param)
if(target == 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " not found.")
return TRUE
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " password is " .. getPlayerPassword(target) .. ".")
return TRUE
end
5.1.4 Function to get if player is or is not online.
Lua:
function onSay(cid, param, words, channel)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
return TRUE
end
if isOnline(param) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is online.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is offline.")
return TRUE
end
end