Jump to content
  • 0

Battle refine script help.


_Dynosawr_

Question


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

I've been screwing around with this and I'm trying to use a FOR loop.

- script BattleRefine::BattleRefineScript1 -1,{
OnNPCKillEvent:
set refinechance,rand(1,100);
if(refinechance>=1)&&(refinechance<=100){

for(set part,rand(1,10); getequipid(part) == 0; return 1){

Right here, I'm trying to have it set the 'part' variable to a random integer between 1 and 10. Then the next part checks to see if the player has an item equipped there, and if he doesn't, re-set the variable to a different integer between 1 and 10 and check if that slot is empty or not. I want it to do this until it gets a slot that isn't empty.

for(set refineamt,getequiprefinerycnt(part); refineamt >= 100; return 3){

Here I'm trying to make the script find out if the item that is equipped has a refine amount of 100+, and if it does, restart from the first for loop.

successrefitem part;
set refinechance,null;
set refinechance2,null;
set part,null;
set refineamt,null;
end;}
}
}else{
end;
}
}

And finally, if the previous for statements worked correctly, and the slot had an item equipped in it, and it's refine was less than 100, it would refine the item once and set the variables to nothing.

Help would be much appreciated, leave a post or PM me. :3

Edited by Joey
Link to comment
Share on other sites

11 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

You can read about the loops here: http://rathena.org/wiki/For#For_Loop

I would do a "do ... while" loop for finding the part like this:

do {
   set .@i, rand(1,10);
} while (getequipid(.@i) == 0);

If you use temporary NPC variables, .@var/.@var$, you won't have to reset them.

Just make sure you never expect them to be set, always make sure to initialize variables.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

The concept is correct. There are a few things you're misinterpreting, though:

  • You're setting permanent character variables for everything. Since everything is temporary, you would want to use temporary scope variables, which start in ".@".
  • A "for" loop is structured in three parts: initialization, condition to loop, and variable increase per loop, i.e.:
    for(
    set .@i,0; // Initialization
    .@i < 10; // Loop until .@i hits 10
    set .@i,.@i+1 // Increase .@i by 1 each time
    )
    


So the fixed code would be something like:

OnNPCKillEvent:
set .@chance, rand(1,100);
// condition to continue
for (set .@i,0; .@i<20; set .@i,.@i+1) { // 20: Prevents infinity loop if nothing is equipped
set .@j, rand(1,10);
if (getequipisequiped(.@j) && getequiprefinerycnt(.@j) < 100) { successrefitem .@j; end; } }
end;

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

Ohhh okay. But, how would I be able to change the chance of it actually working? Say I want a random item refined once at a 5% chance. So that you'd have to kill approx 20 monsters to refine a random item once, and if the item slot is empty, it randomly tries to find one that isn't empty? ;o

PS: If you have MSN/Skype I'd appreciate you telling me so I could possibly get some live help on this. (Easier to understand xD)

Edited by Joey
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Where I wrote "// condition to continue", all you'd need is something like:

if (.@chance > 5) end; // 5% chance to continue the script

The rest of the script loops up to 20 times (you can change that) to find a refineable slot/item.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

Oh okay. I didn't understand that. I'll test it out, thanks :3

Edit:

Will this work? ;o

OnNPCKillEvent:
set .@chance, rand(1,100);
if(.@chance>5)end;
for (set .@i,0; .@i<20; set .@i,.@i+1) { // 20: Prevents infinity loop if nothing is equipped
set .@j, rand(1,10);
if (getequipisequiped(.@j) && getequiprefinerycnt(.@j) < 100) { successrefitem .@j; end; } }
end;
}

Edited by Joey
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

You don't really need the "if" brackets and "else end", since the script I posted would work fine. And currently your conditional would always activate, since the chance is always >= 1... did you mean "&&"? (That part isn't needed at all, actually.)

<NPC Header> {
OnNPCKillEvent:
if (rand(1,100) > 5) end; // 5% chance to continue the script
for (set .@i,0; .@i<20; set .@i,.@i+1) {
set .@j, rand(1,10);
if (getequipisequiped(.@j) && getequiprefinerycnt(.@j) < 100) { successrefitem .@j; end; } }
end;
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

Thanks, but now the problem is that even when I set the chance to 100, and have one item equipped it doesn't always work. I want it to be random, but I want it to be random on the items that are equipped, not the slots. Any ideas on how to fix that? (For example, 100% chance to refine would mean that if 1 item is equipped, it would refine after EVERY kill, not just every few kills)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Does it work if you set the loop count higher (increase 20 to, say, 40)? If it does, a way to optimize would be replacing this:

set .@j, rand(1,10);

With:

if (.@i<10) set .@j, rand(1,10);
else set .@j, .@i-9;

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

- script BattleRefine::BattleRefineScript1 -1,{
OnNPCKillEvent:
if(rand(1,100)>100)end;
for(set .@i,0; .@i<11; set .@i,.@i+1){
if (.@i<10) set .@j, rand(1,10);
else set .@j, .@i-9;
if(getequipisequiped(.@j)&&getequiprefinerycnt(.@j)<100){successrefitem .@j;end;}}
end;
}

It's working perfectly now! Thanks! ♥

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

The "for" loop needs to go up to 20, for the record, or you might run into problems in other equip slots (unlikely, but it should cover all cases).

for(set .@i,0; .@i<20; set .@i,.@i+1){

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  69
  • Reputation:   10
  • Joined:  05/14/12
  • Last Seen:  

Alright. Thanks for you help ;)

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