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

[EO] Collecting Resources Without a Weapon


Matt
 Share

Recommended Posts

This tutorial will make make resources be able to be collected without a weapon. If there's a tool requirement, you'll need a weapon of that tool type to collect the resource.

This has only been tested with EO 2.0\. If this doesn't work for your engine, just follow the structure.

Replace your entire CheckResource sub (server sided) with this

```

Sub CheckResource(ByVal index As Long, ByVal x As Long, ByVal y As Long)

Dim Resource_num As Long

Dim Resource_index As Long

Dim rX As Long, rY As Long

Dim i As Long

Dim Damage As Long

If Map(GetPlayerMap(index)).Tile(x, y).Type <> TILE_TYPE_RESOURCE Then Exit Sub

Resource_num = 0

Resource_index = Map(GetPlayerMap(index)).Tile(x, y).Data1

' Get the cache number

For i = 0 To ResourceCache(GetPlayerMap(index)).Resource_Count

If ResourceCache(GetPlayerMap(index)).ResourceData(i).x = x Then

If ResourceCache(GetPlayerMap(index)).ResourceData(i).y = y Then

Resource_num = i

End If

End If

Next

If Resource_num > 0 Then

If Resource(Resource_index).ToolRequired > 0 Then

If GetPlayerEquipment(index, weapon) > 0 Then

If Item(GetPlayerEquipment(index, weapon)).Data3 <> Resource(Resource_index).ToolRequired Then

PlayerMsg index, "You have the wrong type of tool equiped.", BrightRed

Exit Sub

Else

Damage = RAND(1, Item(GetPlayerEquipment(index, weapon)).Data2)

End If

Else

PlayerMsg index, "You need a tool to collect this resource!", BrightRed

Exit Sub

End If

Else

If GetPlayerEquipment(index, weapon) > 0 Then

Damage = RAND(1, Item(GetPlayerEquipment(index, weapon)).Data2)

Else

Damage = RAND(1, (GetPlayerStat(index, Stats.Strength) / 5))

End If

End If

' inv space?

If Resource(Resource_index).ItemReward > 0 Then

If FindOpenInvSlot(index, Resource(Resource_index).ItemReward) = 0 Then

PlayerMsg index, "You have no inventory space.", BrightRed

Exit Sub

End If

End If

' check if already cut down

If ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).ResourceState = 0 Then

rX = ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).x

rY = ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).y

' check if damage is more than health

If Damage > 0 Then

' cut it down!

If ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).cur_health - Damage <= 0 Then

SendActionMsg GetPlayerMap(index), "-" & ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).cur_health, BrightRed, 1, (rX * 32), (rY * 32)

ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).ResourceState = 1 ' Cut

ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).ResourceTimer = GetTickCount

SendResourceCacheToMap GetPlayerMap(index), Resource_num

' send message if it exists

If Len(Trim$(Resource(Resource_index).SuccessMessage)) > 0 Then

SendActionMsg GetPlayerMap(index), Trim$(Resource(Resource_index).SuccessMessage), BrightGreen, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)

End If

' carry on

GiveInvItem index, Resource(Resource_index).ItemReward, 1

SendAnimation GetPlayerMap(index), Resource(Resource_index).Animation, rX, rY

Else

' just do the damage

ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).cur_health = ResourceCache(GetPlayerMap(index)).ResourceData(Resource_num).cur_health - Damage

SendActionMsg GetPlayerMap(index), "-" & Damage, BrightRed, 1, (rX * 32), (rY * 32)

SendAnimation GetPlayerMap(index), Resource(Resource_index).Animation, rX, rY

End If

' send the sound

SendMapSound index, rX, rY, SoundEntity.seResource, Resource_index

Else

' too weak

SendActionMsg GetPlayerMap(index), "Miss!", BrightRed, 1, (rX * 32), (rY * 32)

End If

Else

' send message if it exists

If Len(Trim$(Resource(Resource_index).EmptyMessage)) > 0 Then

SendActionMsg GetPlayerMap(index), Trim$(Resource(Resource_index).EmptyMessage), BrightRed, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)

End If

End If

End If

End Sub

```

Let me know if you run into any problems!

Save, compile, and enjoy!
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...