Jump to content

Rescripting with Rand (a7)


johnnylump

Recommended Posts

I have some code that includes a rand (a7) call in a rescripted function that's causing an in-game crash when it is called. This does not crash on startup, only when it is called, so it is not a virtual size, jump or parameter issue.

 

This code works just fine (it just doesn't do what I want):

07 8c 00 99 38 3a 00 6d 43 00 00 38 3a 24 0a 16 04 28

 

// End: 0x8c

if (eUFO >= 10)

{

return false;

}

 

But replacing that with either of these codes cause the in-game crash:

 

07 8c 00 99 38 3a 00 6d 43 00 00 38 3a a7 24 0a 16 16 04 28
07 8c 00 99 38 3a 00 6d 43 00 00 38 3a a7 2c 0a 16 16 04 28
// End: 0x8c
if (eUFO >= Rand (10))
{
return false;
}
UEExplorer shows no problem. The difference in size of the statements is covered by 0b (nulls), so shouldn't be a problem there.
(Context: I'm trying to modify XGStrategyAI.ShouldHunt to randomize when UFOs are launched to hunt for satellites. eUFO is a function parameter refers to the class of UFO that just "got away" and wasn't intercepted properly. This function would set the chance of a satellite hunter being launched against the type of UFO, with bigger UFOs (higher eUFO number) presenting a larger chance.)
Any idea what I'm doing wrong? I've seen 99 (>=) and a7 (rand) used together in if comparison statements before, so I'm a little flummoxed. Is there any limitations on the use of a7 that anyone has encountered?
Edited by johnnylump
Link to comment
Share on other sites

That was the clue I needed, thanks.

 

The 3a 38 (ByteToInt PrimitiveCast) was already in there before the eUFO reference. I mistakenly assumed it was part of the variable id, and it was left before the Rand call. Removed the second 3a 38 and crashing problem is gone.

 

Working code:

07 8c 00 99 38 3a 00 6d 43 00 00 a7 2c 0a 16 16 04 28

 

I've said it before: Yours is the superior intellect.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...