Jump to content
  • 0

Explain getd because i don't understand :(


caspa

Question


  • Group:  Members
  • Topic Count:  194
  • Topics Per Day:  0.04
  • Content Count:  499
  • Reputation:   3
  • Joined:  03/11/12
  • Last Seen:  

can somebody explain to me why there is a 0 in this part   delitem2 .@refineitemid,1,1,getd(".@equip_inf"+.@re+"[4]"),0, and why there is a successive same getd ,getd(".@equip_inf"+.@re+"[0]"),getd(".@equip_inf"+.@re+"[1]"),getd(".@equip_inf"+.@re+"[2]"),getd(".@equip_inf"+.@re+"[3]"); after that?
 

                successrefitem .@part;
                set .@j, .@j - 1;
                if(.@j <= 0) close;
                set .@re, 0;
                while ( getequiprefinerycnt(.@part) >= .@refinecnt ) {
                    for (set .@c, 0; .@c < 4; set .@c, .@c + 1)
                        if (getequipcardid(.@part,.@c) != 0)
                            setd ".@equip_inf"+.@re+"[.@c]", getequipcardid(.@part,.@c);
                    setd ".@equip_inf"+.@re+"[4]", getequiprefinerycnt(.@part);
                    unequip .@part;
   delitem2 .@refineitemid,1,1,getd(".@equip_inf"+.@re+"[4]"),0,getd(".@equip_inf"+.@re+"[0]"),getd(".@equip_inf"+.@re+"[1]"),getd(".@equip_inf"+.@re+"[2]"),getd(".@equip_inf"+.@re+"[3]");
                    equip .@refineitemid;
                    set .@re, .@re + 1;
                }
                if (.@re) {
                    for (set .@c, 0; .@c < .@re; set .@c, .@c + 1) {
   getitem2 .@refineitemid,1,1,getd(".@equip_inf"+.@c+"[4]"),0,getd(".@equip_inf"+.@c+"[0]"),getd(".@equip_inf"+.@c+"[1]"),getd(".@equip_inf"+.@c+"[2]"),getd(".@equip_inf"+.@c+"[3]");
                    }
                }
            }
Edited by caspa
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1676
  • Reputation:   702
  • Joined:  12/21/14
  • Last Seen:  

.@something = 10;
.@string$ = "thing";

mes "" + getd(".@some" + .@string$);
mes "" + .@something;


//.@some + (.@string$ = "thing";)
//.@some + thing
//.@something
//getd(".@some" + .@string$) == .@something

-----------------------------------------------------
.@var0 = 0;
.@var1 = 5;
.@var2 = 10;
.@var3 = 15;

for(.@i=0;.@i<4;.@i++)
	mes "" + getd(".@var" + .@i);

//getd(".@var" + 0) == .@var0
//getd(".@var" + 1) == .@var1
//getd(".@var" + 2) == .@var2
//getd(".@var" + 3) == .@var3

 

it's easy you just need to test it , than you understand it

 

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  86
  • Reputation:   21
  • Joined:  10/02/13
  • Last Seen:  

Also, for instructive purposes:

From rA\doc\script_commands.txt:

*delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};

This command will remove a specified amount of items from the invoking/target character.
See 'getitem2' for an explanation of the expanded parameters.

On the script excerpt you provided, the delitem2 argument you request an explanation for (the number zero) occupies the 5th position, that of the <attribute> parameter.
The delitem2 command explanation forwards us to getitem2 for explanation on these parameters.

From rA\doc\script_commands.txt:

identify    - Whether you want the item to be identified (1) or not (0).
refine      - For how many pluses will it be refined.
              It will not let you refine an item higher than the max refine.
attribute   - Whether the item is broken (1) or not (0).
card1,2,3,4 - If you want a card compound to it, place the card ID number into
              the specific card slot.

Here is your explanation for that parameter.

Now, regarding the use of getd, let's first take a look at this command at rA\doc\script_commands.txt:

*getd("<variable name>")

Returns a reference to a variable, the name can be constructed dynamically.
Refer to 'setd' for usage.

In order for you to properly understand getd, you need to first understand how to use basic variables and arrays (skip the spoiler if you do).

Spoiler

 

Setting a variable's value:


set <variable_name>, <variable_value>; // For single-value variables
setarray <array_name>[0], {<value_0>, <value_1>, <value_2>, ...};

Examples:


set .@item_id, 19015; // Sets the value 19015 to .@item_id
setarray .@item_list[0], 501, 502, 503, 504, 505; // Sets the values [501, 502, 503, 504, 504] to .@item_list
set .@headgear_name$, "Valkyrie's Magic Bow";
setarray .@menu_items$[0], "Where should I go?", "About the Basic Interface", "Who the crap are you?!";

To read a variable's value, you simply use it as if it were a value in your script:


set .@player_name$, strcharinfo(0); // Here the variable's value is SET.

mes "[ A Really-Human NPC ]";
mes "Yo, what's up, " + .@player_name$ + "?!"; // Here the variable's value is READ.

 

Assuming that you already understand how basic variables and arrays really work, this is the magic of getd: It allows you to choose which variables you want to set/read WHILE the script is executing.

When you use basic variables and arrays, you're saying exactly where to place or to find the data you're looking for (e.g.: "I want to set the character's name to the variable named .@player_name$." or "I want to set [501, 502, 503, 504, 505] to the array named .@item_list."). This is fixed: after the server's loaded the script, you can't open an input and ask the player: "Hey, tell me the name of the variable you want me to store this amount of Jellopies in:".

With getd you actually can do that (even though you shouldn't! ). That certainly is not the only use for getd, nor the most common: it is often used to make scripting simpler, and although I will refrain from attempting to document all occasions when its use would be beneficial, I'll provide you with an example which I find both instructive and simple enough.

Let's say you have a Treasure Chest NPC, and whenever the player interacts with it, you want to give him a set of items. You have 5 different set of items, represented by 5 different arrays, and you want your script to randomly choose which set of items to reward the lucky player. So, you have something like this:

setarray .@rewards1[0], 501, 502, 503;
setarray .@rewards2[0], 620, 630, 640, 650;
setarray .@rewards3[0], 711, 722, 733, 744, 755;
setarray .@rewards4[0], 888, 999, 1010, 1111, 1212, 1313;
setarray .@rewards5[0], 1010, 1111, 1212, 1313, 1414, 1515, 1616;

How do you  randomly select one of these arrays to reward the player with its items?

Sure, you're definitely going to use the rand() function to generate a number that is in the range of [1, 5]. vvvv But, please, don't do this. vvvv

Spoiler

set .@picked_reward, rand(1,5);

switch (.@picked_reward) {
case 1:
    for (.@i = 0; .@i < getarraysize(.@rewards1); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 2:
    for (.@i = 0; .@i < getarraysize(.@rewards2); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 3:
    for (.@i = 0; .@i < getarraysize(.@rewards3); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 4:
    for (.@i = 0; .@i < getarraysize(.@rewards4); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
case 5:
    for (.@i = 0; .@i < getarraysize(.@rewards5); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
    break;
}

Or


set .@picked_reward, rand(1,5);

if (.@picked_reward == 1) {
    for (.@i = 0; .@i < getarraysize(.@rewards1); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 2) {
    for (.@i = 0; .@i < getarraysize(.@rewards2); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 3) {
    for (.@i = 0; .@i < getarraysize(.@rewards3); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 4) {
    for (.@i = 0; .@i < getarraysize(.@rewards4); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
} else if (.@picked_reward == 5) {
    for (.@i = 0; .@i < getarraysize(.@rewards5); .@i++) {
        giveitem .@rewards1[.@i], 1;
    }
}

 

With getd, you can simply do the following:

set .@picked_reward, rand(1,5); // The number of the picked reward

// Rewards array name
set .@chosen_rewards, ".@rewards" + .@picked_reward;

// How many of each item inside the rewards list to give the player
set .@amount_per_item, 1;

for (.@i = 0; .@i < getarraysize(getd(.@chosen_rewards)); .@i++) {
  giveitem getd(.@chosen_rewards + "[" + .@i + "]"), .@amount_per_item;
}

Line 1 picks a random number from 1 to 5 to identify which array of items it wants to give to the player.

Line 4 effectively adds the string ".@rewards" to the picked number, so ".@rewards" + 4, for example, yields ".@rewards4" and stores that in .@chosen_rewards.

Line 7 sets how many of each item in the rewards list to reward the player with.

Line 9 is where getd is first used. When you use the getd() function providing a string, you're effectively dealing with the value of the variable whose name is the provided string. So, in case the picked reward was number 4, you're actually dealing with .@rewards4, which is an array, hence why we're measuring it's size with getarraysize().

Line 10 concatenates the array's name with it's element so that we can actually access each of the array's elements. In case the picked reward was number 4, it concatenates the string ".@rewards4" and "[.@i]", with .@i being repeatedly replaced by numbers from 0 to x, where x is getarraysize(.@rewards4) - 1. So it goes over the array, item by item, giving the defined amount to the invoking character.

So, this is pretty much all there is to it. I hope this is as instructive as it is exhausting.

Edited by Tyrfing
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  625
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

Basically, @Tyrfing explained very detailed.

In short, setd and getd are used to create/read variables/arrays dynamical. 

As soon as you understand it, you can look at my Fame System, which is using it a lot. 

It might not be the best script regarding as an example, but it works ?. There are without doubt better scripts and better Scripter out there.

Regards,

Chris 

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...