• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Need script fix

Dkadsfe

Member
Joined
Apr 1, 2016
Messages
280
Reaction score
22
Code:
    elseif param == "prestige" or param == "prestiges" or param == "prs" or param == "pr" then
        str = "# [Prestige] - Name\n"
        value = "Prestige"
        name = "name"
        result = ("(getCreatureStorage(thing.uid, 4500);")
I know this script works except for the result how do i make it show the creature storage 4500 this is like a !ranks command btw
 
you want result to say what is in that storage?
Code:
result = getPlayerStorageValue(thing.uid, 4500)..";"
i changed getCreatureStorage(...) to getPlayerStorageValue(...) since i assume its only for players, and afaik getCreatureStorage(...) doesnt exist
 
you want result to say what is in that storage?
Code:
result = getPlayerStorageValue(thing.uid, 4500)..";"
i changed getCreatureStorage(...) to getPlayerStorageValue(...) since i assume its only for players, and afaik getCreatureStorage(...) doesnt exist
I tried both but it says
Code:
[08/05/2016 12:36:25] [Error - TalkAction Interface]
[08/05/2016 12:36:25] data/talkactions/scripts/highscore.lua:onSay
[08/05/2016 12:36:25] Description:
[08/05/2016 12:36:25] data/talkactions/scripts/highscore.lua:26: attempt to index global 'thing' (a nil value)
[08/05/2016 12:36:25] stack traceback:
[08/05/2016 12:36:25]     data/talkactions/scripts/highscore.lua:26: in function <data/talkactions/scripts/highscore.lua:1>
 
my bad, thing.uid isnt a valid creature id...
if you change thing.uid to a valid cid for example it will work (or player incase of 1.x)
otherwise if you cant fix it, paste your entire function
 
my bad, thing.uid isnt a valid creature id...
if you change thing.uid to a valid cid for example it will work (or player incase of 1.x)
otherwise if you cant fix it, paste your entire function
I need it to put the creaturestorage 4500 in the prestige area for only players but this is the whole thing btw i dont have the creaturestorage 4500 in my database yet i use sqlite

Code:
function onSay(cid, words, param)

     -- max players on the highscore
     local players = 20 -- The amount of players that is shown in the list

     -- don't touch --
     local str = ""
     local value = ""
     local name = ""
     local player_id = 0
     local result = nil
    if param == "level" or param == "exp" or param == "lvl" then
        str = "# [Level] - Name\n"
        value = "level"
        name = "name"
        result = db.getResult("SELECT `level`, `name` FROM `players` WHERE `name` != 'GamemasterNick' ORDER BY `level` DESC;")
    elseif param == "magiclevel" or param == "magic" or param == "mlevel" or param == "ml" then
        str = "# [Magic Level] - Name\n"
        value = "maglevel"
        name = "name"
        result = db.getResult("SELECT `name`, `maglevel` FROM `players` ORDER BY `maglevel` DESC, `name` ASC;")
    elseif param == "prestige" or param == "prestiges" or param == "prs" or param == "pr" then
        str = "# [Prestige] - Name\n"
        value = "prestige"
        name = "name"
        result = getPlayerStorageValue(thing.uid, 4500) or 0;
    elseif param == "fist" then
        str = "# [Fist] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 0 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "club" then
        str = "# [Club] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 1 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "sword" then
        str = "# [Sword] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 2 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "axe" then
        str = "# [Axe] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 3 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "dist" or param == "distance" then
        str = "# [Distance] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 4 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "shield" or param == "shielding" then
        str = "# [Shield] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 5 ORDER BY `value` DESC, `player_id` ASC;")
    elseif param == "fish" or param == "fishing" then
        str = "# [Fishing] - Name\n"
        value = "value"
        player_id = "player_id"
        result = db.getResult("SELECT `player_id`, `value` FROM `player_skills`  WHERE `skillid` = 6 ORDER BY `value` DESC, `player_id` ASC;")
    else
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong Skill: '" .. param .. "'")
         return TRUE
    end
    if (result:getID() ~= -1) then
        local i = 1
        while TRUE do
            if not(result:next()) or i > players then
                break
            end
            str = str .. "\n " .. i .. ". [" .. result:getDataInt(value) .. "] - " .. (name ~= "" and result:getDataString("name") or getPlayerNameByGUID(result:getDataInt(player_id)))
            i = i+1
        end
        result:free()
    end
    if str ~= "" then
        doPlayerPopupFYI(cid, str)
    end
    return TRUE
end
 
it does, but this part
Code:
if (result:getID() ~= -1) then
local i = 1
while TRUE do
if not(result:next()) or i > players then
break
end
str = str .. "\n " .. i .. ". [" .. result:getDataInt(value) .. "] - " .. (name ~= "" and result:getDataString("name") or getPlayerNameByGUID(result:getDataInt(player_id)))
i = i+1
end
result:free()
end
is never executed when it goes to prestige, because getPlayerStorageValue(...) returns a number, and number:getID() will be nil (aka -1) afaik

what do you want the script to do if they say prestige with it?
 
it does, but this part
Code:
if (result:getID() ~= -1) then
local i = 1
while TRUE do
if not(result:next()) or i > players then
break
end
str = str .. "\n " .. i .. ". [" .. result:getDataInt(value) .. "] - " .. (name ~= "" and result:getDataString("name") or getPlayerNameByGUID(result:getDataInt(player_id)))
i = i+1
end
result:free()
end
is never executed when it goes to prestige, because getPlayerStorageValue(...) returns a number, and number:getID() will be nil (aka -1) afaik

what do you want the script to do if they say prestige with it?
like it has a list that says the player names and creaturestorage of 4500 that they have from highest to lowest
 
like it has a list that says the player names and creaturestorage of 4500 that they have from highest to lowest
so you want to have a list of every player online with the storagevalue from 4500, sorted from highest to lowest? or ALL players?
like
Code:
x = 10
y = 20
z = 15
n = 0
if these are the players online you want like
Code:
y = 20
z = 15
x = 10
?
 
you want it to show players who has 0 in the storage value aswell, last?

youll have to write a separate function for this regardless, using getOnlinePlayers or w/e its called and getting storage values + names, then sorting by storage value
 
you want it to show players who has 0 in the storage value aswell, last?

youll have to write a separate function for this regardless, using getOnlinePlayers or w/e its called and getting storage values + names, then sorting by storage value
Yes but only top 20 players
 
easiest way would still be to do what i said, and then only print 20 first positions of table if #table > 20
i think that should be a different talkaction now since its complicated to script ranks with prestiges could you script me a talkaction that says !topprestige and shows the creatureid 4500 and 20 top players?
 
i agree that it would be a bit messy doing it in the same script considering this doesnt use any db queries like the other ones :)
no fun if i just give you everything you need, try doing it yourself first ;)
Code:
getPlayersOnline()
getPlayerStorageValue(...)
getCreatureName
table.sort(t, function(a,b) return a>b end) (this sorts a table in descending order)
i dont think youll need more than these 4 to do it
 
so in the new lua i would put in
Code:
getPlayersOnline()
getPlayerStorageValue(4500)
getCreatureName
table.sort(t, function(a,b) return a>b end) (this sorts a table in descending order)
?
 
Code:
function onSay(cid, words, param)
    local storage = 4500 --prestige storage number config
    local players = getPlayersOnline() --creates a table of CIDs for all players online
    local ptable = {}  --initializes an empty table for end result
--this takes the players table and for each CID it adds the name and storage value of storage config in the form of {name, value}
    for i=1,#players,1 do
        ptable[i] = {getCreatureName(players[i]), getPlayerStorageValue(players[i], storage)}
    end
    table.sort(ptable, function(a,b) return a[2]>b[2] end) --this sorts the entire ptable in descending order for the second value of each {name, value} table inside the main table
--prints it all
    for i=1,#ptable,1 do
        print("Name: "..ptable[i][1].." - Prestige: "..ptable[i][2])
    end
end
you can remove the ptable part entirely, and change the players from cids to {name, value} yes, but this is more clear and easier for people to understand
looking at you mr codex ;)
 
Code:
function onSay(cid, words, param)
    local storage = 4500 --prestige storage number config
    local players = getPlayersOnline() --creates a table of CIDs for all players online
    local ptable = {}  --initializes an empty table for end result
--this takes the players table and for each CID it adds the name and storage value of storage config in the form of {name, value}
    for i=1,#players,1 do
        ptable[i] = {getCreatureName(players[i]), getPlayerStorageValue(players[i], storage)}
    end
    table.sort(ptable, function(a,b) return a[2]>b[2] end) --this sorts the entire ptable in descending order for the second value of each {name, value} table inside the main table
--prints it all
    for i=1,#ptable,1 do
        print("Name: "..ptable[i][1].." - Prestige: "..ptable[i][2])
    end
end
you can remove the ptable part entirely, and change the players from cids to {name, value} yes, but this is more clear and easier for people to understand
looking at you mr codex ;)
why does this show only in my console?
[08/05/2016 13:24:09] Name: Test - Prestige: 3
 
i used this just to print in console for easy viewing, change it from
Code:
print("Name: "..ptable[i][1].." - Prestige: "..ptable[i][2])
to
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Name: "..ptable[i][1].." - Prestige: "..ptable[i][2])
which you would realize if you knew anything about lua
you should read up and try to learn it :)
 
Back
Top