bomo99 Posted December 19, 2021 Share Posted December 19, 2021 Hello, i have this idea to take what Skyrim's enchantment of chaos damage was, "50% chance for each element of fire, frost, and shock to do X points of damage." and use as a enchantment on a weapon i have a few ideas but don't really know how oblivion will respond to itsince it has to be able to do this1 in 8 chance (12.5%): For just Fire1 in 8 chance (12.5%): For just Frost1 in 8 chance (12.5%): For just Shock1 in 8 chance (12.5%): For Fire & Frost1 in 8 chance (12.5%): For Frost & Shock1 in 8 chance (12.5%): For Shock & Fire1 in 8 chance (12.5%): For all 31 in 8 chance (12.5%): For nonei have an idea to use GetRandomPercent to get the chance need to do any of the above^ but of course here is the problem that i am running intoi want to take the number generated and divide that by 12.5 and whatever comes out is the effect used, but here is the issue let's say that the random number is 67 and we divide that by 12.5 we get 5.36 so how does oblivion take this? does it round up or down(for the decimals) or for the code since i use floats, decimals aren't a problem but if i put if chance == 5 ;enter code here endif will oblivion just remove the decimal to make it correct or do i need to add a range for the decimals.also for the effects i want to do it by spells, but if it can be done by scripting that would be awesome Link to comment Share on other sites More sharing options...
Lanceor Posted December 19, 2021 Share Posted December 19, 2021 I noticed that you're dividing by 12.5 - shouldn't you be dividing by 8 since you have eight possibilities? To answer your question, while GetRandomPercent always outputs an integer, you could divide the output and store it either as a float to retain the decimal places or a short/long for it to be rounded (not sure whether down or nearest). Float will be more accurate, but you are going to have to use < instead of ==. Short/long may have rounding errors so not all results will have an equal chance of happening. A simpler option might be to use rand instead: set n to rand 0 8if n < 1 (just fire damage)elseif n < 2 (just frost damage)...etc Probably the simplest would be for Fire, Frost and Shock damage each having a 1/3 chance of occurring, independent of each other. :) Link to comment Share on other sites More sharing options...
bomo99 Posted December 19, 2021 Author Share Posted December 19, 2021 (edited) I noticed that you're dividing by 12.5 - shouldn't you be dividing by 8 since you have eight possibilities? To answer your question, while GetRandomPercent always outputs an integer, you could divide the output and store it either as a float to retain the decimal places or a short/long for it to be rounded (not sure whether down or nearest). Float will be more accurate, but you are going to have to use < instead of ==. Short/long may have rounding errors so not all results will have an equal chance of happening. A simpler option might be to use rand instead: set n to rand 0 8if n < 1 (just fire damage)elseif n < 2 (just frost damage)...etc Probably the simplest would be for Fire, Frost and Shock damage each having a 1/3 chance of occurring, independent of each other. :smile:to answer the first point, in my head it made more sense to divide the random number by the chance rather than the whole number(more accurate read as the final number ends at 8 itself) instead either way i would have to still deal with decimalsalso i take it rand is a CSE command, i would rather like it to stay as a CS command use if possible as i would like to use this enchantment without the use of OBSE Edited December 19, 2021 by bomo99 Link to comment Share on other sites More sharing options...
Lanceor Posted December 19, 2021 Share Posted December 19, 2021 Ah, I didn't realise this needed to be OBSE free. In that case, rather than dividing, I'd just stick to integers: set n to GetRandomPercentif n < 12 (fire damage)elseif n < 24 (frost damage)etc Each possibility has 12/100 chance of happening. There will be 4/100 left over which you can distribute to whichever result you want to be slightly favour. Link to comment Share on other sites More sharing options...
bomo99 Posted December 19, 2021 Author Share Posted December 19, 2021 but then it wouldn't be 1 in 8 chance (12.5%): i was just going to leave the no effects 1 in 8 chance (12.5%): For none be blank, i guess no effect could be worse but would prefer it to be equal if possible, could this work? (Result < 0) && (Result >= 0.99) or am i still stuck with just whole numbers? Link to comment Share on other sites More sharing options...
RomanR Posted December 19, 2021 Share Posted December 19, 2021 (edited) What about this ? float chance short damselect ..... set damselected to 0 set chance to GetRandomPercent set chance to chance/12.5 ;it will give 8 possibilities ;here begins cascade of ifs if chance > 0 set damselect to 1 endif if chance >= 1 set damselect to 2 endif if chance >= 2 set damselect to 3 endif if chance >= 3 set damselect to 4 endif if chance >= 4 set damselect to 5 endif if chance >= 5 set damselect to 6 endif if chance >= 6 set damselect to 7 endif if chance >= 7 set damselect to 8 endif if chance != 0 ..... endif This cascade of ifs looks kind of stupid, but in the end you should get right value free of rounding errors. But it still not guarantee true 12.5% chance, it's just scaling. Edited December 19, 2021 by RomanR Link to comment Share on other sites More sharing options...
bomo99 Posted December 19, 2021 Author Share Posted December 19, 2021 (edited) What about this ? float chance short damselect ..... set damselected to 0 set chance to GetRandomPercent set chance to chance/12.5 ;it will give 8 possibilities ;here begins cascade of ifs if chance > 0 set damselect to 1 endif if chance >= 1 set damselect to 2 endif if chance >= 2 set damselect to 3 endif if chance >= 3 set damselect to 4 endif if chance >= 4 set damselect to 5 endif if chance >= 5 set damselect to 6 endif if chance >= 6 set damselect to 7 endif if chance >= 7 set damselect to 8 endif if chance != 0 ..... endif This cascade of ifs looks kind of stupid, but in the end you should get right value free of rounding errors. But it still not guarantee true 12.5% chance, it's just scaling.is that similar to doing it like this? float rnd set rnd to 8.0/99 * Getrandompercent ; => 0.00 to 8.00 just did the calculations on all possible answers the above will spit out and i have a good idea of what will happen here are the results0 = 121 = 122 = 133 = 124 = 125 = 136 = 127 = 128 = 2this is all done by doing this (8/99*(1-100)) i just grabbed how many all equal 0.00 and just put it into a chart just to see that variables it appears to be not even like i wanted gonna try something else Edited December 19, 2021 by bomo99 Link to comment Share on other sites More sharing options...
Lanceor Posted December 19, 2021 Share Posted December 19, 2021 To ensure all possibilities have equal chance, simply roll again if the result is 96 - 99. From a practical perspective, would any player actually notice if some options are 1% more likely, even if they tally results with a pen and paper? Link to comment Share on other sites More sharing options...
bomo99 Posted December 20, 2021 Author Share Posted December 20, 2021 To ensure all possibilities have equal chance, simply roll again if the result is 96 - 99. From a practical perspective, would any player actually notice if some options are 1% more likely, even if they tally results with a pen and paper?i would agree, but i would know and thats the issue i just wanted all of them to be equal but use the whole range but if there is 4 left over i could do this13: For just Fire13: For just Frost13: For just Shock12: For Fire & Frost12: For Frost & Shock12: For Shock & Fire12: For all 313: For nonemakes it more likely to get none or 1 element and making the 2 elements and all 3 of them a little bit more difficult Link to comment Share on other sites More sharing options...
RomanR Posted December 20, 2021 Share Posted December 20, 2021 What about comparing the result against the old one ? So for my example it would continue like this: .... short damselectold ;extra variable .... if chance != 0 && damselect != 0 if damselect == damselectold ;same dam.type as before set damselect to damselect + 1 if damselect > 8 set damselect to 1 endif set damselectold to damselect endif ...... endif It should at least avoid repeating the same damage type. Link to comment Share on other sites More sharing options...
Recommended Posts