damian666 Posted March 30, 2013 Author Share Posted March 30, 2013 i was recently looking over my old pokemon game, and find the encounter code not very accurate.so i went to look for a good one online, and cant find one xdbulbapedia has this:```Determining the rate of encounterThe rate of Pokémon encounter is determined from a simple mathematical formula: 1 in (187.5 / ( x )) per step Let x equal the a value which determines how rare the Pokémon is. The higher the encounter rate, the more common the Pokémon is. Encounter-rate table Encounter type / Encounter rate Very common / 10 Common / 8.5 Semi-rare / 6.75 Rare / 3.33 Very rare / 1.25 ```but i cant get my head around the way i would put this in vb6.so any help would be apriciated ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)Dami Link to comment Share on other sites More sharing options...
Mal Posted March 30, 2013 Share Posted March 30, 2013 Every step the character takes, randomize a number between 1 and 200\. Check if the number is greater than or equal to 187.5 / x. Link to comment Share on other sites More sharing options...
damian666 Posted March 30, 2013 Author Share Posted March 30, 2013 thanx for replying mate, I'll test that out in a sec.next problem I have is the different spawn rates, how would I check if its a rare or common encounter?and care to explain why its 200 and not 100, that way I understand the code, instead of just copy paste :-)```Dim Y As Long, Z As Long 'Y = Format(Rnd * 200, "0.00") Y = Random(1, 200) 'Z = Format(18.75 / 1.25, "0.00") Z = 187.5 / 1.25 If Y >= Z Then PlayerMsg Index, "very rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'Z = Format(18.75 / 3.33, "0.00") Z = 187.5 / 3.33 If Y >= Z Then PlayerMsg Index, "rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'Z = Format(18.75 / 6.75, "0.00") Z = 187.5 / 6.75 If Y >= Z Then PlayerMsg Index, "semi-rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'Z = Format(18.75 / 8.5, "0.00") Z = 187.5 / 8.5 If Y >= Z Then PlayerMsg Index, "common encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'Z = Format(18.75 / 10, "0.00") Z = 187.5 / 10 If Y >= Z Then PlayerMsg Index, "very common encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'no encounter PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen End If End If End If End If End If```this is what i currently have… Link to comment Share on other sites More sharing options...
tslusny Posted March 30, 2013 Share Posted March 30, 2013 > thanx for replying mate, I'll test that out in a sec.> > next problem I have is the different spawn rates, how would I check if its a rare or common encounter?> > and care to explain why its 200 and not 100, that way I understand the code, instead of just copy paste :-)> > ```> > Dim Y As Long, Z As Long> > 'Y = Format(Rnd * 200, "0.00")> > Y = Random(1, 200)> > 'Z = Format(18.75 / 1.25, "0.00")> > Z = 187.5 / 1.25> > If Y >= Z Then> > PlayerMsg Index, "very rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 3.33, "0.00")> > Z = 187.5 / 3.33> > If Y >= Z Then> > PlayerMsg Index, "rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 6.75, "0.00")> > Z = 187.5 / 6.75> > If Y >= Z Then> > PlayerMsg Index, "semi-rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 8.5, "0.00")> > Z = 187.5 / 8.5> > If Y >= Z Then> > PlayerMsg Index, "common encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 10, "0.00")> > Z = 187.5 / 10> > If Y >= Z Then> > PlayerMsg Index, "very common encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'no encounter> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > End If> > End If> > End If> > End If> > End If> ```> > this is what i currently have…Use Select Case ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png) Link to comment Share on other sites More sharing options...
damian666 Posted March 30, 2013 Author Share Posted March 30, 2013 i thought about that, but as i said in first post, i have no clue how to get it in vb6anyway, the calculation i have up there doesnt work anyway, so select case wont help with that, its just faster then if then's ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)as it goes now, its always a rare encounter, it doesnt even get to common or very common xd Link to comment Share on other sites More sharing options...
blkcrow Posted April 1, 2013 Share Posted April 1, 2013 to calculate the chances you have to encounter a pokemon use this formula```y = (100 / (187.5 / x)) * num_of_steps```y would be a double variable that will hold the % chances of encountering that pokemon then get a random number from 0 to 100 and compare it with y. Because i dont think that the random number generator in eclipse can generate float point values you can multiply y with 1000 and then pass it into a long variable then generate a random number between 0 and 100000 this will give you a 3 digit precision.My english really sucks so i cant explain it properly i hope you got what i meant to say Link to comment Share on other sites More sharing options...
damian666 Posted April 2, 2013 Author Share Posted April 2, 2013 ```Public Sub CheckSpawn(ByVal Index As Long, ByVal SpawnType As Byte) Dim Y As Double, Z As Long Y = Format(100 / (187.5 / 1.25) * 1, "0.00") Z = rand(1, 100) If Z <= Y Then PlayerMsg Index, "very rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else Y = Format(100 / (187.5 / 3.33) * 1, "0.00") If Z <= Y Then PlayerMsg Index, "rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else Y = Format(100 / (187.5 / 6.75) * 1, "0.00") If Z <= Y Then PlayerMsg Index, "semi-rare encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else If Z <= Y Then Y = Format(100 / (187.5 / 8.5) * 1, "0.00") PlayerMsg Index, "common encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else If Z <= Y Then Y = Format(100 / (187.5 / 10) * 1, "0.00") PlayerMsg Index, "very common encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen Else 'no encounter PlayerMsg Index, "no encounter!", BrightRed PlayerMsg Index, "Y = " & Y, BrightGreen PlayerMsg Index, "Z = " & Z, BrightGreen End If End If End If End If End IfEnd Sub```i dunno man, it does'nt spawn much this way, not even common ones, but perhaps i misunderstood, so check the above code ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png) Link to comment Share on other sites More sharing options...
DeathKnight Posted April 2, 2013 Share Posted April 2, 2013 well a problem I see right off the bat is that with the equations, the very rare encounter is literally impossible. your Y will equal .666666, however your range for your Z is 1-100, so Z will never be less than Y. Even your very common encounter has only a 5.33% chance of it triggering. Either you will have to play with the forumlas, or you can take a stepcount into it. Make a step counter and use something like```Y = Format(100 / (187.5 / 1.25) * 1, "0.00") + (GetPlayerStepCount(index)*.05)```I wouldn't do it EXACTLY like that, I would put a cap on it so you can't go above, say, 35% chance of an encounter. Link to comment Share on other sites More sharing options...
JohnPony Posted April 2, 2013 Share Posted April 2, 2013 [http://pastebin.com/wB1APV24](http://pastebin.com/wB1APV24)Sorry, I haven't used Vb6 in ages. Link to comment Share on other sites More sharing options...
Mal Posted April 2, 2013 Share Posted April 2, 2013 > well a problem I see right off the bat is that with the equations, the very rare encounter is literally impossible. your Y will equal .666666, however your range for your Z is 1-100, so Z will never be less than Y. Even your very common encounter has only a 5.33% chance of it triggering. Either you will have to play with the forumlas, or you can take a stepcount into it. Make a step counter and use something like> > ```> > Y = Format(100 / (187.5 / 1.25) * 1, "0.00") + (GetPlayerStepCount(index)*.05)> > ```> > I wouldn't do it EXACTLY like that, I would put a cap on it so you can't go above, say, 35% chance of an encounter./yawn. Already told this guy how to implement it using the algorithm he shared. Link to comment Share on other sites More sharing options...
damian666 Posted April 2, 2013 Author Share Posted April 2, 2013 > /yawn. Already told this guy how to implement it using the algorithm he shared.yes you did, and then I asked for some extra info, which I didn't get /yawnthanx guys, I'll check your info and code. it seems harder then I thought to get a working, accurate function :-) Link to comment Share on other sites More sharing options...
damian666 Posted April 2, 2013 Author Share Posted April 2, 2013 > well a problem I see right off the bat is that with the equations, the very rare encounter is literally impossible. your Y will equal .666666, however your range for your Z is 1-100, so Z will never be less than Y. Even your very common encounter has only a 5.33% chance of it triggering. Either you will have to play with the forumlas, or you can take a stepcount into it. Make a step counter and use something like> > ```> > Y = Format(100 / (187.5 / 1.25) * 1, "0.00") + (GetPlayerStepCount(index)*.05)> > ```> > I wouldn't do it EXACTLY like that, I would put a cap on it so you can't go above, say, 35% chance of an encounter.yes, i see what you mean ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)i want it to be close to the real games, so i wont do a step counter, this is just something to run when stepped on spawntile.yours doesnt generate the right feeling either General, i think i am a bit stuck xd Link to comment Share on other sites More sharing options...
blkcrow Posted April 2, 2013 Share Posted April 2, 2013 i think the real game does have a step counter thats why i multiplied with the number of steps in the formula i gave you. Look the chances you will get a common encounter is only 5% its so low because you dont want to encounter a pokemon every time you step on the grass but if you leave it like that the chance is to low so you got to make it scale with the number of steps he make in the grassIn your code you are multipling it with 1```Y = Format(100 / (187.5 / 1.25) * 1, "0.00")```this way the formula works like you are always on the first step. So you got to change 1 with the number of steps you make```Y = Format(100 / (187.5 / 1.25) * num_of_steps, "0.00")```another thing that might be a problem is that your random number hasnt got float point precision while your chances do.for example your rare encounter has a 1,77% per step chance while your very rare has a 0,66% per step but your random number is a whole number between 0 and 100 that means your rare encounter will triger only when you get <=1 and your very rare only when you get 0 that means that the rare encounter has a 2% chance per step to happen while the very rare has a 1% per step Link to comment Share on other sites More sharing options...
damian666 Posted April 2, 2013 Author Share Posted April 2, 2013 it has a step counter? i never saw that xdhow would that work, step +1 on every step, or only on spawn tiles?would it reset after every encounter? Link to comment Share on other sites More sharing options...
blkcrow Posted April 2, 2013 Share Posted April 2, 2013 only on spawn tiles and resets when you step outside a spawn tile Link to comment Share on other sites More sharing options...
damian666 Posted April 2, 2013 Author Share Posted April 2, 2013 k, that should be easy ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png) Link to comment Share on other sites More sharing options...
Mal Posted April 2, 2013 Share Posted April 2, 2013 > thanx for replying mate, I'll test that out in a sec.> > next problem I have is the different spawn rates, how would I check if its a rare or common encounter?> > and care to explain why its 200 and not 100, that way I understand the code, instead of just copy paste :-)> > ```> > Dim Y As Long, Z As Long> > 'Y = Format(Rnd * 200, "0.00")> > Y = Random(1, 200)> > 'Z = Format(18.75 / 1.25, "0.00")> > Z = 187.5 / 1.25> > If Y >= Z Then> > PlayerMsg Index, "very rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 3.33, "0.00")> > Z = 187.5 / 3.33> > If Y >= Z Then> > PlayerMsg Index, "rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 6.75, "0.00")> > Z = 187.5 / 6.75> > If Y >= Z Then> > PlayerMsg Index, "semi-rare encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 8.5, "0.00")> > Z = 187.5 / 8.5> > If Y >= Z Then> > PlayerMsg Index, "common encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'Z = Format(18.75 / 10, "0.00")> > Z = 187.5 / 10> > If Y >= Z Then> > PlayerMsg Index, "very common encounter!", BrightRed> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > Else> > 'no encounter> > PlayerMsg Index, "Y = " & Y, BrightGreen> > PlayerMsg Index, "Z = " & Z, BrightGreen> > End If> > End If> > End If> > End If> > End If> ```> > this is what i currently have…Do the math, man. Geeze. 187.5 / 1.25 = 150\. You can't use 1 to 100\. You'd never hit it. Use a random 1 to 200 and switch the floating-point numbers for the specified encounter type (common, rare, etc). Here:Encounter type / Encounter rateVery common / 1.25Common / 3.35Semi-rare / 6.75Rare / 8.5Very rare / 10Every step the character makes, randomize 1 to 200 and select case the result with (x <= encounterType). If encounters are too frequent then increase the random number. 1 to 400\. That leaves 250 numbers that have no encounters rather than just 50 numbers. If that's still not enough padding then run the logic every 2 steps. If it's still not enough run it every 3 steps. Link to comment Share on other sites More sharing options...
blkcrow Posted April 2, 2013 Share Posted April 2, 2013 no you are doing it completly wrong the idea behind this is to have 1 in 150 (187.5 / 1.25) per step this translates in 0.66% with the way you are saying you have a 75% chance per step Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now