Jump to content

autoloot_expire quest does not work


Go to solution Solved by Froslass,

Recommended Posts

Hey there guys, I'm kinda new to dev quest and I could need some help for setting autoloot_expire from account table to new players. This is what I got:

quest autoloot_expire_set begin
    state start begin
        when login begin
            -- Retrieve the account ID of the current player
            local account_id = pc.get_account_id()
            syschat(string.format("Account ID: %d", account_id))

            -- Check if autoloot_expire is already set
            local query = string.format(
                "SELECT autoloot_expire FROM account.account WHERE id = %d;",
                account_id
            )
            local affected_rows, result = mysql_direct_query(query)

            if affected_rows > 0 and result[1] and result[1].autoloot_expire ~= "0000-00-00 00:00:00" then
                return -- Exit if autoloot_expire is already set
            end

            -- Set the expiration date to 2026-01-01 00:00:00
            local expire_date = "2026-01-01 00:00:00"
            local update_query = string.format(
                "UPDATE account.account SET autoloot_expire = '%s' WHERE id = %d;",
                expire_date,
                account_id
            )

            -- Execute the update query
            local update_affected_rows, update_result = mysql_direct_query(update_query)

            -- Debugging output to verify changes
            syschat(string.format("Rows affected: %d", update_affected_rows))
            if not update_affected_rows or update_affected_rows == 0 then
                syschat("Error: Update query did not affect any rows.")
            else
                syschat("Autoloot expiration successfully set.")
            end

            -- Inform the player
            say("You have received autoloot until January 1, 2026.")

            -- Mark the quest as complete
            set_state(_COMPLETE_)
        end
    end

    state _COMPLETE_ begin
    end
end

regards
 

Link to comment
https://metin2.dev/topic/33349-autoloot_expire-quest-does-not-work/
Share on other sites

  • Active+ Member
  • Solution

You should put this kind of code in your website, just modify the sql code when inserting a new player in db during the sign up phase. So you will have only 1 sql query (insert at sign up), instead of 3 (insert at signup + select and update at login); of course do that for all kind of bonus you want to give players at the start. Also try to avoid using sql queries in your quests as much as possible, especially if player's input is involved. And a last tip, when you are asking for help explain in detail what's wrong/what you need, don't just say "i need help" and dump all your code without explaining what you have tried, the output you get, what you are expecting etc.

  • muscle 1

 

On 12/26/2024 at 2:45 AM, [GF]Froslass said:

You should put this kind of code in your website, just modify the sql code when inserting a new player in db during the sign up phase. So you will have only 1 sql query (insert at sign up), instead of 3 (insert at signup + select and update at login); of course do that for all kind of bonus you want to give players at the start. Also try to avoid using sql queries in your quests as much as possible, especially if player's input is involved. And a last tip, when you are asking for help explain in detail what's wrong/what you need, don't just say "i need help" and dump all your code without explaining what you have tried, the output you get, what you are expecting etc.

Thank you very much, I'll provide better information in future posts, thanks for the help!

  • muscle 1

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.