Guest Lucilla Frost Posted April 19, 2009 Share Posted April 19, 2009 Hello Question from a relative newcomer here with a bit of programming experience. I'm trying to set up a script that has a random chance of going one way, and a random chance of going another way. I've based my code on the dog fight at the Copper Coronet which has a 50/50 of player win lose. ~ From my NPC.d file ~ IF ~~ THEN BEGIN OPPC4 SAY ~Lets try it and see what happens.~ IF ~~ THEN DO ~StartCutScene("OPTST")~ EXIT END ~OPTST.baf~ IF True() THEN RESPONSE #50 StartCutSceneMode() StartCutScene("OPPCF1") RESPONSE #50 StartCutSceneMode() StartCutScene("OPPCM1") END The cut scenes OPPCF1 and OPPCM1 work fine individually, but my attempt at randomising them always results in the first placed being implemented. In this case OPPCF1. As far as I can see I haven't done anything wrong, but it doesn't work. Have I made a basic error through copying code I don't actually understand? If anyone can help I will be eternally in your debt. xx Lou Link to comment
devSin Posted April 19, 2009 Share Posted April 19, 2009 Cutscenes don't work the same as normal scripts. Change your dialogue: IF ~~ THEN BEGIN OPPC4 SAY ~Let's try it and see what happens.~ IF ~RandomNum(2,1)~ THEN DO ~StartCutSceneMode() StartCutScene("OPPCF1")~ EXIT IF ~RandomNum(2,2)~ THEN DO ~StartCutSceneMode() StartCutScene("OPPCM1")~ EXIT END You can then get rid of OPTST. Link to comment
berelinde Posted April 19, 2009 Share Posted April 19, 2009 They're supposed to have equal chances of coming up, but it never seems to work that way, does it? Maybe it would be more equal if you tried 40/60 or 30/70? The numbers don't have to total 100%, by the way. It's just convenient. Edit: DevSin must have been posting at the same time. He's the expert. Link to comment
Guest Lucilla Frost Posted April 19, 2009 Share Posted April 19, 2009 Thank you so much. I love you forever! (In a purely friendly fashion). Link to comment
Mike1072 Posted April 19, 2009 Share Posted April 19, 2009 They're supposed to have equal chances of coming up, but it never seems to work that way, does it? Maybe it would be more equal if you tried 40/60 or 30/70? The numbers don't have to total 100%, by the way. It's just convenient. I think that each response is supposed to have a 1/num_of_responses chance of being chosen, and whatever number is associated with the response indicates the probability that when chosen, the response will actually happen. So, 2 RESPONSE #100s should make one of them happen, and give an equal chance of it being either one. Supposedly this doesn't work out in practise - the first RESPONSE always gets weighted higher than the rest - and the RandomNum trigger ends up being more reliable for producing random results. Link to comment
Ardanis Posted April 19, 2009 Share Posted April 19, 2009 Afaik the chance for RESPONSE #X is X/(X+Y+Z). the first RESPONSE always gets weighted higher than the restYep, have seen that mentioned somewhere before. Link to comment
Mike1072 Posted April 20, 2009 Share Posted April 20, 2009 Afaik the chance for RESPONSE #X is X/(X+Y+Z). Oh, maybe I was mistaken about that. Boo to scripting. Link to comment
Qwinn Posted April 20, 2009 Share Posted April 20, 2009 One thing I discovered in my PS:T modding is that the total weights allocated to the RESPONSEs -does- matter. If your total weight is under 400 or so, then it seems to work okay. But if you have more than four or five RESPONSE #100's, those after the first four or five will never come up. This actually kept a whole lot of lines from showing up as stringheads in the game (some characters were supposed to have as many as 15 different strings appear their heads). I fix this for PS:T... I wonder if anyone has tested or fixed this in the other IE games, assuming it happens? Qwinn Link to comment
Taimon Posted April 20, 2009 Share Posted April 20, 2009 Pseudo-code for response picking: r = rand(0, sum(R1 ... Rn) - 1) sum_so_far = 0 for resp in responses do: sum_so_far += resp.prop if (r <= sum_so_far) return resp Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.