Interact with resource with no item/empty hands

In the code you need to equip an item "If GetPlayerEquipment(Index, Weapon) > 0 Then"

! 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 ! 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 GetPlayerEquipment(Index, Weapon) > 0 Then ! If Item(GetPlayerEquipment(Index, Weapon)).Data3 = Resource(Resource_index).ToolRequired Then ! ' 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 ! ! Damage = Item(GetPlayerEquipment(Index, Weapon)).Data2 ! ! ' 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 ! Else ! PlayerMsg Index, "You have the wrong type of tool equiped.", BrightRed ! End If ! Else ! PlayerMsg Index, "You need a tool to interact with this resource.", BrightRed ! End If ! End If ! End If ! End Sub !

Can you help me? I was trying to recode it but I failed, I want to interact a resource with no item equipped

(The idea is to open a chest with empty hands)

…I hope my english wasnt very bad…


If GetPlayerEquipment(Index, Weapon) > 0 then

if Item(GetPlayerEquipment(Index, Weapon)).Data3 = Resource(Resource_index).ToolRequired then

Is the bit that checks for the weapon and makes sure that the data type is the same as required. The easiest way would be to add an else for```
If GetPlayerEquipment(Index, Weapon) > 0 Then


If GetPlayerEquipment(Index, Weapon) > 0 then

if Item(GetPlayerEquipment(Index, Weapon)).Data3 = Resource(Resource_index).ToolRequired then

Is the bit that checks for the weapon and makes sure that the data type is the same as required. The easiest way would be to add an else for```
If GetPlayerEquipment(Index, Weapon) > 0 Then

Can´t understand at all :(

You would make it along the the lines of this.


If getplayerequipment(index, weapon) > 0 then

' resource logic here

else

' resource logic here

end if

Does that make more sense?

You would make it along the the lines of this.


If getplayerequipment(index, weapon) > 0 then

' resource logic here

else

' resource logic here

end if

Does that make more sense?

Oh, like repeating the code, Ok I will try!

Again, that would be the easiest method. There are better ways to do it, but I don’t have enough time to go through the mess that is Sub CheckResource to fix it today. Good luck ^_^

ALL RIGHT, Works fine! Thx so much Matthew

This is the code that I change and works! ^^

! ! 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 ! 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 ResourceCache(GetPlayerMap(Index)).ResourceData(Resource_num).cur_health = 0 Then ! ' 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 ! ! Damage = 1 ! ! ' 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 ! ! Else ! ! If GetPlayerEquipment(Index, Weapon) > 0 Then ! If Item(GetPlayerEquipment(Index, Weapon)).Data3 = Resource(Resource_index).ToolRequired Then ! ' 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 ! ! Damage = Item(GetPlayerEquipment(Index, Weapon)).Data2 ! ! ' 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 ! Else ! PlayerMsg Index, "You have the wrong type of tool equiped.", BrightRed ! End If ! Else ! PlayerMsg Index, "You need a tool to interact with this resource.", BrightRed ! End If ! End If ! End If ! End If ! End Sub !

All of that was becouse I added the projectile system and with a projectile-item equipped can not interact with resources, really dont know why…

Edit: Well now a projectile-item can interact with resources ^^

! In Server side
! Search Public Sub HandleProjecTile Under:
! ! ' hit a block ! If Map(GetPlayerMap(Index)).Tile(x, y).Type = TILE_TYPE_BLOCKED Then ! ' hit a block, clear it. ! ClearProjectile Index, PlayerProjectile ! Exit Sub ! End If !
Type:
! ! ' hit a resource ! If Map(GetPlayerMap(Index)).Tile(x, y).Type = TILE_TYPE_RESOURCE Then ! ' hit a resource, clear it. ! CheckResource Index, x, y ! ClearProjectile Index, PlayerProjectile ! Exit Sub ! End If !
In Client side
! Search Public Sub BltProjectile Under:
! ! ' check if we hit a block ! If Map.Tile(x, y).Type = TILE_TYPE_BLOCKED Then ! ClearProjectile Index, PlayerProjectile ! Exit Sub ! End If !
Type:
! ! ' check if we hit a resource ! If Map.Tile(x, y).Type = TILE_TYPE_RESOURCE Then ! ClearProjectile Index, PlayerProjectile ! Exit Sub ! End If !
It will allow you to interact with resources as far the projectile can arrive

Hope it helps for the community

Log in to reply