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

[Eo] Multiple npc drops and percent chances


Officer Johnson
 Share

Recommended Posts

Saw a few people asking for stuff about multiple npc drops like tutorials not working and all so im just taking the code i used in Eclipse Renewal and bringing it to you here in a tutorial hope someone finds it helpful.

Lets get to the code:

Server:

first in **modConstants** under the general constants.

add:

```
Public Const MAX_NPC_DROPS As Byte = 10

```
now head over to **modTypes** and in **NpcRec**

change:

```
DropChance
DropItem
DropItemValue

```
to:

```
DropChance(1 to MAX_NPC_DROPS) As Double
DropItem(1 To MAX_NPC_DROPS) As Long
DropItemValue(1 To MAX_NPC_DROPS) As Long

```
now in **modCombat** in thesub **PlayerAttackNpc** find:

```
'Drop the goods if they get it
```
and **Replace**:

```
n = Int(Rnd * Npc(npcNum).DropChance) + 1

If n = 1 Then
Call SpawnItem(Npc(npcNum).DropItem, Npc(npcNum).DropItemValue, mapNum, MapNpc(mapNum).Npc(mapNpcNum).x, MapNpc(mapNum).Npc(mapNpcNum).y)
End If

```
with:

```
For n = 1 To MAX_NPC_DROPS
If Npc(NpcNum).DropItem(n) = 0 Then Exit For

If Rnd <= Npc(NpcNum).DropChance(n) Then
Call SpawnItem(Npc(NpcNum).DropItem(n), Npc(NpcNum).DropItemValue(n), MapNum, MapNpc(MapNum).Npc(mapNpcNum).x, MapNpc(MapNum).Npc(mapNpcNum).y)
End If
Next

```
If you have pets in your game you will need the following:

***ONLY ADD IF YOU HAVE PETS AND THE FOLLOWING SUB IN YOUR GAME.**

In **modCombat** in **NpcAttackNpc:**

find:

```
' Drop the goods if they get it
'For n = 1 to MAX_NPC_DROPS

```
under it add:

```
For n = 1 To MAX_NPC_DROPS
If Npc(vNpcNum).DropItem(n) = 0 Then Exit For
If Rnd <= Npc(vNpcNum).DropChance(n) Then
Call SpawnItem(Npc(vNpcNum).DropItem(n), Npc(vNpcNum).DropItemValue(n), MapNum, MapNpc(MapNum).Npc(Victim).x, MapNpc(MapNum).Npc(Victim).y)
End If
Next

```
Client Side:

in **modConstants** under the **General constants** add:

```
Public Const MAX_NPC_DROPS As Byte = 10

```
now in **modTypes** in **NpcRec**:

change:

```
DropChance
DropItem
DropItemValue 
```
to:

```
DropChance(1 to MAX_NPC_DROPS) As Double
DropItem(1 To MAX_NPC_DROPS) As Long
DropItemValue(1 To MAX_NPC_DROPS) As Long

```
Now in frmEditor_Npc code at the top under Option Explicit add:

```
Private DropIndex As Byte

```
Form Work:

add a scrlbar to the fraDrop named: **scrlDrop**

**make the scrlbars max 10 (or number of MAX_NPC_DROPS)**

now double click on the scrlBar and make the code the following:

```
Private Sub scrlDrop_Change()
DropIndex = scrlDrop.Value

fraDrop.Caption = "Drop - " & DropIndex
txtChance.text = NPC(EditorIndex).DropChance(DropIndex)
scrlNum.Value = NPC(EditorIndex).DropItem(DropIndex)
scrlValue.Value = NPC(EditorIndex).DropItemValue(DropIndex)

End Sub

```
now double click scrlNum 

change:

```
Npc(EditorIndex).DropItem = scrlNum.value

```
to:

```
NPC(EditorIndex).DropItem(scrlDrop.Value) = scrlNum.Value

```
now click scrlValue

change:

```
Npc(EditorIndex).DropItemValue = scrlValue.value

```
to:

```
NPC(EditorIndex).DropItemValue(scrlDrop.Value) = scrlValue.Value

```
click on txtChance and make it the following:

```
Private Sub txtChance_Change()
On Error GoTo chanceErr

if Not IsNumeric(txtChance.text) and not Right$(txtChance.text, 1) = "%" and not InStr(1, txtChance.text, "/") > 0 and not InStr(1, txtChance.text, ".") Then

txtChance.text = "0"
NPC(EditorIndex).DropChance(scrlDrop.Value) = 0
Exit Sub
end if

if Right$(txtChance.text, 1) = "%" Then
txtChance.text = Left(txtChance.text, Len(txtChance.text) - 1) / 100
Elseif InStr(1, txtChance.text, "/") > 0 Then
Dim i() as string
i = Split(txtChance.text = Int(i(0) / i(1) * 1000 / 1000
end if

If txtChance.text > 1 or txtChance.text < 0 Then
Err.Description = "Value must be between 0 and 1!"
GoTo chanceErr
End if

NPC(EditorIndex).DropChance(scrlDrop.Value) = txtChance.text
Exit sub

chanceErr:

MsgBox "Invalid entry for chance! " & Err.Description
txtChance.text = "0"
NPC(EditorIndex).DropChance(scrlDrop.Value) = 0
End Sub

```
that should be it, if any errors let me know :)

Credits: Ballie  for most of code
Link to comment
Share on other sites

Im not good at vb6 at all but here's a few things I had to do to get this working.

In modGameEditors find this

```
.txtChance.text = CStr(Npc(EditorIndex).DropChance)
.scrlNum.Value = Npc(EditorIndex).DropItem
.scrlValue.Value = Npc(EditorIndex).DropItemValue
```
and change it to this

```
.txtChance.text = CStr(Npc(EditorIndex).DropChance(1))
.scrlNum.Value = Npc(EditorIndex).DropItem(1)
.scrlValue.Value = Npc(EditorIndex).DropItemValue(1)
```
in the last block of code in the OP

```
i = Split(txtChance.text = Int(i(0) / i(1) * 1000 / 1000
```
just needs some end parentheses

```
i = Split(txtChance.text = Int(i(0) / i(1)) * 1000 / 1000)
```
I also set the scroll bar minimum to 1 that seems to help too.

WARNING! I don't know what I'm doing! This could all be wrong!!!
Link to comment
Share on other sites

> Im not good at vb6 at all but here's a few things I had to do to get this working.
>
> In modGameEditors find this
>
> ```
> .txtChance.text = CStr(Npc(EditorIndex).DropChance)
> .scrlNum.Value = Npc(EditorIndex).DropItem
> .scrlValue.Value = Npc(EditorIndex).DropItemValue
> ```
> and change it to this
> ```
> .txtChance.text = CStr(Npc(EditorIndex).DropChance(0))
> .scrlNum.Value = Npc(EditorIndex).DropItem(0)
> .scrlValue.Value = Npc(EditorIndex).DropItemValue(0)
> ```
> in the last block of code in the OP
> ```
> i = Split(txtChance.text = Int(i(0) / i(1) * 1000 / 1000
> ```
> just needs some end parentheses
> ```
> i = Split(txtChance.text = Int(i(0) / i(1)) * 1000 / 1000)
> ```WARNING! I don't know what I'm doing! This could all be wrong!!!

Nope it's good simple mistakes I made.
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...