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
Question
Louis T Steinhil
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.