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

Pickup item infront of you-source question


minipimp
 Share

Recommended Posts

I made it so I can right click on any item and a function will happen.

What I dont know is how to make it so it picks up the mapitem 1 tile infront/back  or by both of his sides.  Basically a radius of 1 tile around the player.

Here is what I have it doing when it right clicks.. Basically picking up the item underneath him.

```
Public Sub CheckForMapItem()
Dim i, x, y As Long
x = GetPlayerX(MyIndex)
y = GetPlayerY(MyIndex)
For i = 1 To MAX_MAP_ITEMS
If MapItem(i).num > 0 Then
If MapItem(i).x = x And MapItem(i).y = y Then
CheckMapGetItem
End If
End If

Next
End Sub

```
Now this is what triggers the function to happen (rightclicking)

```
For i = 1 To MAX_MAP_ITEMS

If CurX = MapItem(i).x And CurY = MapItem(i).y Then

CheckMapGetItem

```
How would I make it so it will pick up items around the player , ive tried adding  -1  and +1's but nothing happens.
Link to comment
Share on other sites

```
If CanPlayerPickupItem(index, i) Then
' Check if item is at the same location as the player
If (MapItem(mapnum, i).x = GetPlayerX(index)) + 1 Then
If (MapItem(mapnum, i).y = GetPlayerY(index)) - 1 Then
' Find open slot
n = FindOpenInvSlot(index, MapItem(mapnum, i).num)

```
Okay  It works but not the way I want it to.  it made it so the player was +1 and -1 x,y of the item and i clicked it and it picked up .  how would i change this so it will only pick up   1 tile up and down left and right of the player.
Link to comment
Share on other sites

RIght now, the way you have it, is like this.

[ ]   [ ]   [ ]

[ ]  :)  [ ] 

[ ]   [ ]   [ ]

You want the selecting to be like this.

[ ]   [ ]
   [ ]

[ ]
  :)  [ ] 

[ ]   [ ]
  [ ]

But, your code checks the code of this square.

[ ]   [ ]   [ ]

[ ]  :)  [ ] 

[ ]   [ ]   [ ]

PlayerX + 1

PlayerY - 1

Hope this helps.
Link to comment
Share on other sites

Okay. I manipulated the code to work with what you want. It won't affect the other use the code has.

Replace the subs CheckMapGetItem (client), HandleMapGetItem (Server), and PlayerMapGetItem (Server) with the code I post below.

```
Sub CheckMapGetItem(Optional ByVal X As Long = 0, Optional ByVal Y As Long = 0)
Dim Buffer As New clsBuffer

' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

If timeGetTime > Player(MyIndex).MapGetTimer + 250 Then
If Trim$(MyText) = vbNullString Then
Player(MyIndex).MapGetTimer = timeGetTime
Buffer.WriteLong CMapGetItem
Buffer.WriteLong X
Buffer.WriteLong Y
SendData Buffer.ToArray()
End If
End If

Set Buffer = Nothing

' Error handler
Exit Sub
errorhandler:
HandleError "CheckMapGetItem", "modGameLogic", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub

Private Sub HandleMapGetItem(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim Buffer As clsBuffer
Dim X As Long, Y As Long

Set Buffer = New clsBuffer
Buffer.WriteBytes Data()
X = Buffer.ReadLong
Y = Buffer.ReadLong
Set Buffer = Nothing
Call PlayerMapGetItem(index, X, Y)

End Sub

Sub PlayerMapGetItem(ByVal index As Long, Optional X As Long = 0, Optional Y As Long = 0)
Dim i As Long
Dim n As Long
Dim MapNum As Long
Dim Msg As String

If Not IsPlaying(index) Then Exit Sub
MapNum = GetPlayerMap(index)
If X = 0 Then X = GetPlayerX(index)
If Y = 0 Then Y = GetPlayerY(index)

For i = 1 To MAX_MAP_ITEMS
' See if theres even an item here
If (MapItem(MapNum, i).Num > 0) And (MapItem(MapNum, i).Num <= MAX_ITEMS) Then
' our drop?
If CanPlayerPickupItem(index, i) Then
' Check if item is at the same location as the player
If (MapItem(MapNum, i).X = X) Then
If (MapItem(MapNum, i).Y = Y) Then
' Find open slot
n = FindOpenInvSlot(index, MapItem(MapNum, i).Num)

' Open slot available?
If n <> 0 Then
' Set item in players inventor
Call SetPlayerInvItemNum(index, n, MapItem(MapNum, i).Num)

If Item(GetPlayerInvItemNum(index, n)).Type = ITEM_TYPE_CURRENCY Then
Call SetPlayerInvItemValue(index, n, GetPlayerInvItemValue(index, n) + MapItem(MapNum, i).Value)
Msg = MapItem(MapNum, i).Value & " " & Trim$(Item(GetPlayerInvItemNum(index, n)).Name)
Else
Call SetPlayerInvItemValue(index, n, 0)
Msg = Trim$(Item(GetPlayerInvItemNum(index, n)).Name)
End If

' Erase item from the map
ClearMapItem i, MapNum

Call SendInventoryUpdate(index, n)
Call SpawnItemSlot(i, 0, 0, GetPlayerMap(index), 0, 0)
SendActionMsg GetPlayerMap(index), Msg, White, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)
Exit For
Else
Call PlayerMsg(index, "Your inventory is full.", BrightRed)
Exit For
End If
End If
End If
End If
End If
Next
End Sub
```
Link to comment
Share on other sites

Okay, well, right now, you have the option to set the x and y parameters. So make your sub look like this.

```
Public Sub CheckForMapItem()

call CheckMapGetItem(getplayerx(myindex) - 1, 0) ' item to my left
call CheckMapGetItem(getplayerx(myindex) + 1, 0) ' item to my right
call CheckMapGetItem(0, getplayery(myindex) - 1) ' item above me
call CheckMapGetItem(0, getplayery(myindex) + 1) ' item under me

end sub

```
Then you can get fancy and do diagonals.

```
call CheckMapGetItem(getplayerx(myindex) - 1, getplayery(myindex) - 1)

```
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...