Jump to content
  • 0

How to convert from addtimer to OnClock/OnHour?


Louis T Steinhil

Question


  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  177
  • Reputation:   33
  • Joined:  06/22/13
  • Last Seen:  

I'm trying to make a script like in RO Mobile Deposit Cards.

This is working if I use addtimer, but if I use OnClock/OnHour I'm getting error. Pls help

Submit_Cards:
    // Initialize the menu string
    set .@menu$, "";

    // Loop through the list of card IDs to populate the menu
    for (set .@i, 0; .@i < .num_cards_to_select; set .@i, .@i + 1) {
        // Get the card name using its ID
        set .@card_name$, getitemname(getd("Card" + .@i));

        // Get the submission count using dedicated variable
        set .@submission_count, getd("Card" + .@i + "_");

        // Retrieve the required number of cards to collect for the chosen slot
        set .@required_cards, getd("Collect" + .@i + "_");

        // Determine the submission status of the card
        set .@submission_status$, " (" + .@submission_count + " / " + .@required_cards + ")";

        // Append the card name and submission status to the menu string
        .@menu$ += .@submission_status$ + " - " + .@card_name$ + ":";
    }

    mes "[Card Collection NPC]";
    mes "Which card would you like to submit?";
    next;

    // Display the menu and handle player selection
    set .@selection, select(.@menu$) - 1;
    set .@selectedCardId, getd("Card" + .@selection);

    // Retrieve the submission count
    set .@submission_count, getd("Card" + .@selection + "_");

    // Retrieve the required number of cards to collect for the chosen slot
    set .@required_cards, getd("Collect" + .@selection + "_");

    // Calculate the number of cards to submit
    set .@cards_needed, .@required_cards - .@submission_count;

    // Get the player's inventory
    getinventorylist;

    // Check if the player has the selected card in their inventory
    set .@player_card_count, 0;
    for (set .@j, 0; .@j < @inventorylist_count; set .@j, .@j + 1) {
        if (@inventorylist_id[.@j] == .@selectedCardId) {
            set .@player_card_count, @inventorylist_amount[.@j];
            break;
        }
    }

    // If player has no cards, inform and exit
    if (.@player_card_count == 0) {
        mes "[Card Collection NPC]";
        mes "You do not have any of this card.";
        close;
    }

    // Calculate the actual number of cards to submit (up to the needed amount)
    set .@cards_to_submit, min(.@cards_needed, .@player_card_count);

    // Update submission count
    setd("Card" + .@selection + "_", .@submission_count + .@cards_to_submit);

    // Remove the cards from the player's inventory
    delitem .@selectedCardId, .@cards_to_submit;

    // Store the card and player information for later processing
    set .@slot, 0;
    while (getd("TempCardID" + .@slot) > 0) {
        set .@slot, .@slot + 1;
    }

    setd("TempCardID" + .@slot, .@selectedCardId);
    setd("TempPlayerID" + .@slot, getcharid(0));
    setd("TempPlayerName$" + .@slot, strcharinfo(0));
    setd("TempCardsToSubmit" + .@slot, .@cards_to_submit);

    // Set a timer for 10 seconds to process returning cards
    addtimer 10000, strnpcinfo(3) + "::OnTimerReturnCards";

    mes "[Card Collection NPC]";
    mes "Card submitted successfully!";

    // If the card collection is complete for this card, apply the bonus
    if (getd("Card" + .@selection + "_") >= .@required_cards) {
        // Retrieve the stored bonus and its value
        set .@bonus_string$, getd("Bonus" + .@selection + "_String$");
        set .@bonus_alias$, getd("Bonus" + .@selection + "_Alias$");
        set .@bonus_value, getd("Bonus" + .@selection + "_Value");

        // Apply bonus
        bonus_script(.@bonus_string$ + .@bonus_value + ";", 10);

        // Display the bonus received
        mes "[ Bonus ]: " + .@bonus_alias$ + " " + .@bonus_value;
    }

    close;

OnTimerReturnCards:

    // Loop through each submission slot to handle returning cards
    for (set .@i, 0; .@i < .num_cards_to_select; set .@i, .@i + 1) {
        // Check if there are cards to return for this slot
        if (getd("TempCardID" + .@i) > 0) {
            // Get stored information for this submission slot
            set .@selectedCardId, getd("TempCardID" + .@i);
            set .@player_id, getd("TempPlayerID" + .@i);
            set .@player_name$, getd("TempPlayerName$" + .@i);
            set .@cards_to_submit, getd("TempCardsToSubmit" + .@i);

            // Define sender's name and mail title
            set .@sender$, "Card Collection NPC"; // Sender's name
            set .@title$, "Card Return"; // Mail title

            // Define mail body
            set .@body$, "Your submitted cards have been returned:";

            // Mail the cards back to the player
            setarray .@mailitem[0], .@selectedCardId; // Set the card ID to be returned
            setarray .@mailamount[0], .@cards_to_submit; // Set the number of cards to return

            mail .@player_id, .@sender$, .@title$, .@body$, 0, .@mailitem, .@mailamount;

            // Clear submission count for this card slot
            setd("Card" + .@i + "_", 0);

            // Update NPC's internal record to reflect returned cards
            set .@npc_card_count, getd("NPC_Card_" + .@i); // Get current count from NPC's internal storage
            setd("NPC_Card_" + .@i, .@npc_card_count + .@cards_to_submit); // Update count (simulate NPC's inventory)

            // Clear stored information for this submission slot
            setd("TempCardID" + .@i, 0);
            setd("TempPlayerID" + .@i, 0);
            setd("TempPlayerName$" + .@i, "");
            setd("TempCardsToSubmit" + .@i, 0);
        }
    }

	bonus_script_clear 1;
	deltimer strnpcinfo(3) + "::OnTimerReturnCards";

    end;

 

Error:

[Error]: get_val_: fatal error ! player not attached!
[Debug]: Source (NPC): [ Letter A ] at yuno_in02 (93,207)
[Debug]: Source (NPC): [ Letter A ] is located in: npc/custom/Card_Collector_A.txt
[Warning]: script:get_val: cannot access player variable 'TempCardID0', defaulting to 0

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  6
  • Topics Per Day:  0.00
  • Content Count:  446
  • Reputation:   30
  • Joined:  12/08/11
  • Last Seen:  

You receive the error because the character is no longer attached to the script to access its variable after closing the npc. 

Ignoring implementation of the system and assuming you want to send the cards back at a specific timeframe, there are 2 ways you can access the variables, by using script commands attachrid and/or query_sql.

You cannot solely use attachrid or query_sql. It will depend on the status of the character character. If it is online, then re-attach the char by using attachrid to access the character variables or modify them directly in the database through query_sql when the character is off.

If you don't mind, a better implementation would be to save the info in another table instead of character variable. There are multiple benefits with this method:

  • The character's status is irrelevant.
  • The server can resend all the cards back in one wave.
  • You don't have to remove the entries from the table thus it can serve as a log.
Edited by Magnetix
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  37
  • Topics Per Day:  0.01
  • Content Count:  177
  • Reputation:   33
  • Joined:  06/22/13
  • Last Seen:  

Thank you for the input. I was totally lost and forgot that I can do sql.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...