Also about "Double of Gold". If sucess, what's happen if mobs are level 40? you used iValue*4 and the double it's iValue*2. Don't it's iValue*8 for mobs 40?
In my modified script, If a creature's CR is >=39.0, then a successful 'double gold' check takes the multiplier to effectively 8x the base iValue, yes. In your original script, the multiplier was 7x the base iValue (not truly doubling the value of the gold - you gave the iValue to the creature, then twice the 3x iValue).
How this happens is by resetting the value of iValue each time. That way, what we're multiplying *2 in the 'doubling' section is the value of the 4x value of iValue (not the base original value).
For example:
First, let's say that the script comes up with an even 100gp as the starting value of iValue.
At the first CR check, if the CR is below the threshold, the creature is given 100gp and exits. Done. But, if the CR is 40, we increase the value of iValue by 4x. So, the value of iValue is changed from 100 to 400 (4x the 100 original value). By expressing that iValue = iValue * 4, we are saying that from here on out in the script, iValue is now equal to 400 (not 100 any longer).
Then, if a 'doubling' check is successful, we do the same thing, but this time only need to multiply iValue by 2. So, our 400 iValue *2 = 800 gp. And again, by expressing that iValue = iValue*2, we change the value of iValue permanently from 400 to 800 (8x the original 100 starting value).
if you wanted to see this in action, you could put a little debug code in the script and then remove it later once you're satisfied:
SendMessageToPC(GetFirstPC(), "DEBUG: iValue = "+IntToString(iValue));
You put a copy of that statement after each of the 3 times that iValue is changed (after the variable is initialized, after the CR check, and then after the doubling check. You could also add a further statement within the doubling check to say that the double check was successful.
Hope that helps.