minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 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 Longx = 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 IfNextEnd 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 More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 How far in the sub PlayerMapGetItem (server side) is it getting? Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 ```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 More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 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 + 1PlayerY - 1Hope this helps. Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 okay so I need to find out how to use all 4 directions at the same time. lemme give it a try :D Link to comment Share on other sites More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 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 Suberrorhandler: HandleError "CheckMapGetItem", "modGameLogic", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd SubPrivate Sub HandleMapGetItem(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim 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 SubSub 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 NextEnd Sub``` Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 ```timeGetTime```Variable not defined. do I have to dim it? How so Link to comment Share on other sites More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 Oh. Use whatever you had there before. It was probably gettickcount, or something like that. Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 Okay everythings in but its still not working right do I have to replace the numbers or what? I appreciate your help. Link to comment Share on other sites More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 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 leftcall CheckMapGetItem(getplayerx(myindex) + 1, 0) ' item to my rightcall CheckMapGetItem(0, getplayery(myindex) - 1) ' item above mecall CheckMapGetItem(0, getplayery(myindex) + 1) ' item under meend sub```Then you can get fancy and do diagonals.```call CheckMapGetItem(getplayerx(myindex) - 1, getplayery(myindex) - 1)``` Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 Its only registering picking it up on the right. Link to comment Share on other sites More sharing options...
Matt Posted November 6, 2013 Share Posted November 6, 2013 Go to PlayerMapGetItem and see what the y and x values are being received as. If they're the coords you want, then there's something I overlooked. Link to comment Share on other sites More sharing options...
minipimp Posted November 6, 2013 Author Share Posted November 6, 2013 im just having a hard time understanding where the code goes. I placed in in the sub you said but nothings happening.Sorry for my lack of skills :/ Link to comment Share on other sites More sharing options...
Growlith1223 Posted November 6, 2013 Share Posted November 6, 2013 when i get home i'll help you out Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now