Hello, all. Zyntax and me were busy with some scripts, and then we came on the idea to make some functions ourselves.
The two functions we made are highscore functions. What they do is, set a value +1 for a player (if you won a duel or something) and the other function shows a list of highscores for a function.
Here they are: in data/lib/050-functions.lua add:
And the showing highscore function: (also in functions.lua)
How to use:
let's say you have a duel arena script, and you want to add one point to the winner.
Let's say the winner is 'cid'. Then you have to choose a storage to add the value and show the list. We'll use storage 43210.
So to add the point to the winner, we use:
Voila. As simple as that! Now you can show the highscore list by doing:
We'll cut the parameters down. uid is the player you are showing the highscore list to. It will be cid in our case.
Storage is in this case the same, which is 43210. Now you can also fill in a name for your highscore. This name cannot be longer
than 20 characters, and has to be a STRING. So for example:
Voila, this will show the highscore list for storage 43210 to cid, as name "Duel Arena". You don't have to fill in a name. It's just optional.
If you don't fill in a name, it will automatically set the name to "Game".
If you don't know if you should do a talkaction / statue / NPC or something else to display your highscores
then here is an example of how I am using it.
Draw 3 statues with the same ItemID.
Set the UniqueID's like in the picture (for example: 10001,10002,...)
Now insert this script in your data\actions\scripts\other and name it
newhighscore.lua
And in data\actions\actions.xml paste this line:
If you want that the statue with the UniqueID = 10001 displays your "Demon Hunt Quest script" highscore, then insert the correct storage value and the name for the highscore, like you did in
Meaning that 23005 is your "Demon Hunt Quest script" storage.
Well, I guess you get it by now.
The result is this:
Have fun.
The two functions we made are highscore functions. What they do is, set a value +1 for a player (if you won a duel or something) and the other function shows a list of highscores for a function.
Here they are: in data/lib/050-functions.lua add:
Lua:
function doPlayerSetHighscore(uid, storage)
-- Function made by Ragheed and Zyntax from OTFans. --
if storage then
if(isNumber(storage) == true) then
if(isPlayer(uid)) then
local player_id = getPlayerGUID(uid)
local result = 0
if(getPlayerStorageValue(uid, storage) > 0) then
result = getPlayerStorageValue(uid, storage)
end
if(result == 0) then
db.executeQuery("INSERT INTO `player_storage` VALUES (" .. player_id .. "," .. storage .. ", 1)")
setPlayerStorageValue(uid, storage, 1)
else
db.executeQuery("UPDATE `player_storage` SET `value`='".. result+1 .."' WHERE `key`='" .. storage .."' AND `player_id`='"..player_id.."'")
setPlayerStorageValue(uid, storage, result+1)
end
else
print("[ERROR] : doPlayerSetHighscore: player not found.")
return false
end
else
print("[ERROR] : doPlayerSetHighscore: storage is not a number.")
return false
end
else
print("[ERROR] : doPlayerSetHighscore: storage not found.")
return false
end
return true
end
And the showing highscore function: (also in functions.lua)
Lua:
function doPlayerShowHighscore(uid, storage, name)
-- Function made by Ragheed and Zyntax from OTFans. --
if storage then
if(isNumber(storage) == true) then
if(isPlayer(uid)) then
if name then
if(type(name)== 'string') then
if(string.len(name) <= 20) then
gameName = name
else
print("[ERROR] : doPlayerShowHighscore: name cannot be longer then 20 characters.")
return false
end
else
print("[ERROR] : doPlayerShowHighscore: name is not a string.")
return false
end
else
gameName = "Game"
end
local shownPlayers = 10
local str = ""..gameName.." Highscore:\n# Player - [Score]\n"
local result = db.getResult('SELECT `value`, `player_id` FROM `player_storage` WHERE `key`='..storage..' ORDER BY `value` DESC;')
if(result:getID() ~= -1) then
local i = 1
while TRUE do
str = str .. "\n " .. i .. ". "..getPlayerNameByGUID(result:getDataInt("player_id")).." - [" .. result:getDataInt("value") .. "]"
if not(result:next()) or i > shownPlayers then
break
end
i = i+1
end
result:free()
else
str = ""..gameName.." Highscore is empty."
end
if(str ~= "") then
doPlayerPopupFYI(uid, str)
end
else
print("[ERROR] : doPlayerShowHighscore: player not found.")
return false
end
else
print("[ERROR] : doPlayerSetHighscore: storage is not a number value.")
return false
end
else
print("[ERROR] : doPlayerShowHighscore: storage not found.")
return false
end
return true
end
How to use:
let's say you have a duel arena script, and you want to add one point to the winner.
Let's say the winner is 'cid'. Then you have to choose a storage to add the value and show the list. We'll use storage 43210.
So to add the point to the winner, we use:
Lua:
doPlayerSetHighscore(cid, 43210)
Voila. As simple as that! Now you can show the highscore list by doing:
Lua:
doPlayerShowHighscore(uid, storage, name)
We'll cut the parameters down. uid is the player you are showing the highscore list to. It will be cid in our case.
Storage is in this case the same, which is 43210. Now you can also fill in a name for your highscore. This name cannot be longer
than 20 characters, and has to be a STRING. So for example:
Lua:
doPlayerShowHighscore(cid, 43210, "Duel Arena")
Voila, this will show the highscore list for storage 43210 to cid, as name "Duel Arena". You don't have to fill in a name. It's just optional.
If you don't fill in a name, it will automatically set the name to "Game".
If you don't know if you should do a talkaction / statue / NPC or something else to display your highscores
then here is an example of how I am using it.
Draw 3 statues with the same ItemID.
Set the UniqueID's like in the picture (for example: 10001,10002,...)
Now insert this script in your data\actions\scripts\other and name it
newhighscore.lua
Lua:
function onUse(cid, item, frompos, item2, topos)
--Example: [ UID ] = {storageValue, "Name of the Highscore"}
local board = {
[10001] = {23005, "Hunt the Demon"},
[10002] = {23006, "Arena Tournament"},
[10003] = {23007, } --Leave {storageValue, >BLANK<} to use default "Game Highscore" name
}
for k, v in pairs(board) do
if item.uid == k then
doPlayerShowHighscore(cid, v[1], v[2])
end
end
end
And in data\actions\actions.xml paste this line:
XML:
<action uniqueid="10001-10003" event="script" value="other/newhighscore.lua"/>
If you want that the statue with the UniqueID = 10001 displays your "Demon Hunt Quest script" highscore, then insert the correct storage value and the name for the highscore, like you did in
Lua:
doPlayerSetHighscore(cid, 23005)
Meaning that 23005 is your "Demon Hunt Quest script" storage.
Well, I guess you get it by now.
The result is this:
Have fun.
Last edited: