Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to make a good encounter formula?


damian666
 Share

Recommended Posts

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 xd

bulbapedia has this:

```

Determining the rate of encounter

The 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

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

> 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

i thought about that, but as i said in first post, i have no clue how to get it in vb6

anyway, 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

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

```

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 If

End 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

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

> 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

> /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 /yawn

thanx 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

> 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

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 grass

In 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

> 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 rate

Very common / 1.25

Common / 3.35

Semi-rare / 6.75

Rare / 8.5

Very rare / 10

Every 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...