Lua TFS 0.4 - Graduation system, storage for 5 best players

Discussion in 'Support' started by roriscrave, Jan 12, 2018.

  1. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    Hello friends, I need a script that when the server starts, it will check which are the 05 players that have the highest value of storage 1030.
    For exemample:
    Teste 1 has storage 1030, value 500
    Teste 2 has storage 1030, value 450
    Teste 3 has storage 1030, value 300


    Assuming they are the players with the highest storage 1030, when the server stats, i want to the player Teste 1, receives a storage 887, value 1.
    The player test 2, receives storage 887, value 2
    The player test 3, receives storage 887, value 3.

    Tkx!
     
  2. Bogart

    Bogart ...has super panda powers

    Joined:
    Jun 21, 2009
    Messages:
    7,943
    Likes Received:
    526
    Best Answers:
    19
    Code (Lua):
    1. local storage = 1030
    2. local high_value = 887
    3. local top_n = 5
    4. function onStartup()
    5.     local score = 1
    6.     local highscore = db.storeQuery("SELECT player_id FROM `player_storage` WHERE player_storage.key = '" .. storage .. "' and value > 0 ORDER BY value DESC LIMIT "..  top_n .. ";")
    7.     db.query("DELETE FROM player_storage WHERE player_storage.key = '" .. high_value .. "';")
    8.     if result.getNumber(highscore, "player_id") then
    9.             local pl_id = result.getNumber(highscore, "player_id")
    10.             db.query(MESSAGE_STATUS_CONSOLE_BLUE,"INSERT INTO player_storage(player_id, key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
    11.             score = score + 1
    12.             while(result:next(highscore)) do
    13.                 local pl_id = result.getNumber(highscore, "player_id")
    14.                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "number " .. score .. ":" .. pl_id)
    15.                 db.query("INSERT INTO player_storage(player_id,  key, value) VALUES (" .. pl_id .. ", " .. high_value .. ", " .. score .. ");")
    16.                 score = score + 1
    17.         end
    18.     end
    19. end
     
    Last edited: Jan 14, 2018
    Shadowsong and roriscrave like this.
  3. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    thx bogard!
     
  4. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    I have this error:
    attempt to call field 'getNumber' (a nil value)

    do u know how i can solve it?
     
  5. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    i got this erros:

    SQLITE ERROR: near ".": syntax error (INSERT INTO player_storage(player_id, player_storage.key, value) VALUES (31, 887, 1);)
    SQLITE ERROR: near ".": syntax error (INSERT INTO player_storage(player_id, player_storage.key, value) VALUES (68, 887, 2);)
     
  6. Itutorial

    Itutorial Well-Known Member

    Joined:
    Dec 23, 2014
    Messages:
    1,316
    Likes Received:
    274
    Best Answers:
    22
    This is where your issue is:

    Code (Text):
    1.  
    2. player_storage.key
    3.  
     
  7. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    but what should I do there?
     
  8. Itutorial

    Itutorial Well-Known Member

    Joined:
    Dec 23, 2014
    Messages:
    1,316
    Likes Received:
    274
    Best Answers:
    22
    Well, I would delete. player_storage. from it. You could, if you wanted to figure it out on your own, open up your database and look in the player_storage table. You will see 3 values that can be put in: player_id, key, value. or something simular. What ever that 2nd one "key" is named that is what you need to change it too instead of player_storage.key
     
    roriscrave likes this.
  9. roriscrave

    roriscrave Member

    Joined:
    Dec 7, 2011
    Messages:
    182
    Likes Received:
    10
    Best Answers:
    0
    thx a lot!
     
  10. Bogart

    Bogart ...has super panda powers

    Joined:
    Jun 21, 2009
    Messages:
    7,943
    Likes Received:
    526
    Best Answers:
    19
    Lol my bad, edited.
     
    xDyego likes this.
  11. Itutorial

    Itutorial Well-Known Member

    Joined:
    Dec 23, 2014
    Messages:
    1,316
    Likes Received:
    274
    Best Answers:
    22
    You only fixed it on one line. There are 3 more lines that it needs to be corrected on.
     

Share This Page

Loading...