Simple rerolling script for RPG game

Subscribe to Simple rerolling script for RPG game 8 posts, 4 voices

 
faqop User

I was wondering how hard this would be, and if someone could possibly get me started in the right direction.

******** MORE INFORMATION IN 3rd POST *****************

There is a website I play on called http://www.sryth.com

And part of the user creation process is unlimited rolling for your stats, which are random from 6-20, I was wondering how hard it would be to disable the reroll button if you get perfect stats.

The html can be viewed by logging in and going to create a new character.
Here's an example of the text:

Your stats have been rolled.
Melee Rating [?]: 28 / 32 Superhuman
Stamina Points [?]: 30 / 33 Superhuman
Might [?]: 19 Incredible
Agility [?]: 13 Above Avg
Body [?]: 19 Incredible
Mind [?]: 19 Incredible
Spirit [?]: 13 Above Avg
Aura [?]: 14 Above Avg
Luck [?]: 19 Incredible

Skill Potential (Based on your stats)

Lore: 25% Exp. Bonus
Arcana: 15% Exp. Bonus
Weaponry: 15% Exp. Bonus
Woodsmanship: 15% Exp. Bonus
Archery: 15% Exp. Bonus
Unarmed Combat: 15% Exp. Bonus
Seamanship: 10% Exp. Bonus
Diplomacy: 10% Exp. Bonus
Horsemanship: 10% Exp. Bonus
Thievery: 10% Exp. Bonus

****% MORE INFORMATION IN MY SECOND POST %****

Thank you very much!

 
Descriptor Scriptwright

You can't paste html like that here (didn't you notice?), the easy way to get around that is to add a space like < input name="aname">.
I'm positive there's no Java in that code, but there may be some JavaScript handlers in the form or input buttons, which likely isn't much help, we'd need to see the JavaScript function that's called by the onclick and/ or onsubmit handler, most likely.

 
faqop User

I apologize descriptor, I was pulling an all nighter and pretty out of it.

I looked over the page again and there is no onsubmit or onclick, looks like it's all plain html w/ some css stuff at the top.

The easiest way I can see to know that I want the button removed is to search for the text strings:
"No Exp. Adj.","Exp. Penalty","25% Exp. Bonus","20% Exp. Bonus","15% Exp. Bonus","10% Exp. Bonus", or "5% Exp. Bonus"
and if any of these are found do nothing, otherwise remove the "reroll" button.

Here's the reroll button I want to remove when the stats are all 20:

< form method="POST" action="/game/ci.php" >
< input type="hidden" name="f_c" value="member_createpc.inc" >
< input type="hidden" name="f_task" value="roll" >
< td align=middle valign=middle >
< input type="submit" value="REROLL STATS" class="submitbutton2" >
< /td >
< /form >

In order to look and see if the stats are all 20 I think it's more involved, so it would probably be easier to see if the experience modifiers are all 30%, below I've listed what the html for that would look like:

< table cellpadding=0 cellspacing=0 border=0 class="table_basic" width=100% >
< tr >
< td align=right valign=top width=50% >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_arcana" target="_blank" style="color:#004f00;" >Arcana< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_diplomacy" target="_blank" style="color:#004f00;" >Diplomacy< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_woodsmanship" target="_blank" style="color:#004f00;" >Woodsmanship< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_weaponry" target="_blank" style="color:#004f00;" >Weaponry< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_unarmedcombat" target="_blank" style="color:#004f00;" >Unarmed Combat< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_seamanship" target="_blank" style="color:#004f00;" >Seamanship< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_horsemanship" target="_blank" style="color:#004f00;" >Horsemanship< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_lore" target="_blank" style="color:#004f00;" >Lore< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_archery" target="_blank" style="color:#004f00;" >Archery< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font style="font-size:11px;" >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< tr >
< td align=right valign=top width=50% >< font style="font-size:11px;" >< font color=#004f00 >< a href="/ci.php?f_c=docs.inc&f_nh=1#skills_thievery" target="_blank" style="color:#004f00;" >Thievery< /a>< /font >:  < /td >
< td align=left valign=top width=50% >< font style="font-size:11px;" >< font color="#000090" >30% Exp. Bonus< /font >< /td >
< /tr>
< /table >

Thank you very much for any help/responses.

 
Descriptor Scriptwright

OK, so there's no JavaScript, it's totally generated by the server. I see some unclosed font tags, I hope that doesn't effect this script.
I don't get why you want to remove the button, it's easy to disable it. I guess you are clicking it real fast and don't want to miss a good roll. So here's a function that will disable the or click the button.

// set global for our re-roll checks, true to disable button
var S_Stop = true;

// to disable button or reroll
function S_ReRoll(stop){
  var button = document.evaluate("//input[@value='REROLL STATS']", document, null, 9, null).singleNodeValue;
  if(stop){ button.disabled = true }
  // else stop = false, click button - or remove line to do nothing
  else{ button.click() }
}

If you don't want the script to re-roll, then just remove the button.click() line. You can exit the script with return true; (since Greasemonkey script is in a wrapper it will just quit).

Well, that's the easy part, checking the stats is a bit more complex.
Let me try the first option where we look for a list of strings. I will assume these are all in table cells.

// list of stats we don't want
var badsStats = [ "No Exp. Adj.", "Exp. Penalty", "25% Exp. Bonus", "20% Exp. Bonus", "15% Exp. Bonus", "10% Exp. Bonus", "5% Exp. Bonus" ];

for(var i=0; badsStats.length > i; i++){
  if(document.evaluate("//td//*[contains(text(), '" + badsStats[i] + "')]", document, null, 3, null).booleanValue){
    S_Stop = false;
    // done checking
    break;
  }
}

// check if we want to reroll
if(!S_Stop){
  S_ReRoll(S_Stop);
  return true;
}
// or just use S_ReRoll(S_Stop) if you dont use next function

In order to look and see if the stats are all 20, I think we can just count to 10.

// good stat value and the amount to match
var goodStats = [ "30% Exp. Bonus", 10 ];

var statsMatch = document.evaluate("//td//*[contains(text(), '" + goodStats[0] + "')]", document, null, 6, null);
if(statsMatch == null || statsMatch.snapshotLength < goodStats[1]){ S_Stop = false }
// check if we want to reroll
S_ReRoll(S_Stop);

Edit: whoops, there are 10 stats not 20 - fixed

 
faqop User

Thank you very much, I haven't been able to try this out because I've been working 14 hour days, but when I get some freetime I will, and I'll post back with how it worked out and my final script hopefully.

 
Boo Scriptwright

I'm trying to modify your script, Descriptor, and I'm having issues. If you'd be so kind to help...

I am attempting to read the rolled stat value for each stat.. for just the Might stat so far I have...


var statMatch = document.evaluate("//tr[td/font/b/a[.='Might']]/td[2]", document, null, 9, null).singleNodeValue;

However, that returns an object of type HTMLSpanElement which I dont know how to work with.. I tried statMatch.innerText but that comes back as undefined.. Any thoughts on what I am doing wrong.. or better yet, any thoughts on how this should be done right?

Thanks.

 
Mindeye Scriptwright

Try to use textContent. innerText is a Internet Explorer only property (not standard)

 
Boo Scriptwright

Mindeye,
Thank you so very much.