PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Server/src/modPlayer.bas

https://bitbucket.org/Helladen/eclipse-worlds
Visual Basic | 2456 lines | 1824 code | 386 blank | 246 comment | 1 complexity | 5775e0c6f7cd6d22f4d5d59121ca2904 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. Attribute VB_Name = "modPlayer"
  2. Option Explicit
  3. Sub HandleUseChar(ByVal index As Long)
  4. If Not IsPlaying(index) Then
  5. Call JoinGame(index)
  6. Call AddLog(GetPlayerLogin(index) & "/" & GetPlayerName(index) & " has began playing " & Options.Name & ".", "Player")
  7. Call TextAdd(GetPlayerLogin(index) & "/" & GetPlayerName(index) & " has began playing " & Options.Name & ".")
  8. Call UpdateCaption
  9. End If
  10. End Sub
  11. Sub JoinGame(ByVal index As Long)
  12. Dim i As Long
  13. Dim n As Long
  14. Dim Color As Long
  15. ' Set the flag so we know the person is in the game
  16. TempPlayer(index).InGame = True
  17. ' Update the log
  18. frmServer.lvwInfo.ListItems(index).SubItems(1) = GetPlayerIP(index)
  19. frmServer.lvwInfo.ListItems(index).SubItems(2) = GetPlayerLogin(index)
  20. frmServer.lvwInfo.ListItems(index).SubItems(3) = GetPlayerName(index)
  21. ' Send an ok to client to start receiving in game data
  22. Call SendLogin(index)
  23. TotalPlayersOnline = TotalPlayersOnline + 1
  24. ' Send data
  25. Call SendItems(index)
  26. Call SendAnimations(index)
  27. Call SendNPCs(index)
  28. Call SendShops(index)
  29. Call SendSpells(index)
  30. Call SendResources(index)
  31. Call SendInventory(index)
  32. Call SendWornEquipment(index)
  33. Call SendMapEquipment(index)
  34. Call CheckEquippedItems(index)
  35. Call SendHotbar(index)
  36. Call SendTitles(index)
  37. Call SendMorals(index)
  38. Call SendEmoticons(index)
  39. Call SendQuests(index)
  40. ' Spell Cooldowns
  41. For i = 1 To MAX_PLAYER_SPELLS
  42. If GetPlayerSpell(index, i) > 0 Then
  43. ' Check if the CD has expired
  44. If GetPlayerSpellCD(index, i) - timeGetTime < 1 Then Call SetPlayerSpellCD(index, i, 0)
  45. If GetPlayerSpellCD(index, i) - timeGetTime >= Spell(GetPlayerSpell(index, i)).CDTime * 1000 Then Call SetPlayerSpellCD(index, i, 0)
  46. If GetPlayerSpellCD(index, i) <= timeGetTime Then Call SetPlayerSpellCD(index, i, 0)
  47. ' Send it
  48. Call SendSpellCooldown(index, i)
  49. End If
  50. Next
  51. ' Check for glitches in the inventory
  52. Call UpdatePlayerItems(index)
  53. ' Check for glitches in equipment
  54. Call UpdatePlayerEquipmentItems(index)
  55. ' Send the player's data
  56. Call SendPlayerData(index)
  57. ' Send vitals to player of all other players online
  58. For n = 1 To Player_HighIndex
  59. For i = 1 To Vitals.Vital_Count - 1
  60. If IsPlaying(n) Then
  61. Call SendVitalTo(index, n, i) ' Sends all players to new player
  62. If Not index = n Then
  63. Call SendVitalTo(n, index, i) ' Sends new player to logged in players
  64. End If
  65. End If
  66. Next
  67. Next
  68. ' Send other data
  69. Call SendPlayerStatus(index)
  70. Call SendPlayerExp(index)
  71. ' Warp the player to their saved location
  72. Call PlayerWarp(index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index), True)
  73. ' Send welcome messages
  74. Call SendWelcome(index)
  75. ' Send Resource cache
  76. For i = 0 To ResourceCache(GetPlayerMap(index)).Resource_Count
  77. SendResourceCacheTo index, i
  78. Next
  79. Call UpdateClassData(index)
  80. ' Send a global message that they joined
  81. If GetPlayerAccess(index) <= STAFF_MODERATOR Then
  82. If Class(GetPlayerClass(index)).Color = Orange Then
  83. Color = RGB(255, 165, 0)
  84. Else
  85. Color = Class(GetPlayerClass(index)).Color
  86. End If
  87. Call GlobalMsg(GetPlayerName(index) & " has joined " & Options.Name & "!", Color)
  88. Else
  89. ' Color for access
  90. Select Case GetPlayerAccess(index)
  91. Case 0
  92. Color = 15
  93. Case 1
  94. Color = 3
  95. Case 2
  96. Color = 2
  97. Case 3
  98. Color = BrightBlue
  99. Case 4
  100. Color = Yellow
  101. Case 5
  102. Color = RGB(255, 165, 0)
  103. End Select
  104. Call GlobalMsg(GetPlayerName(index) & " has joined " & Options.Name & "!", Color)
  105. End If
  106. ' Send the flag so they know they can start doing stuff
  107. Call SendInGame(index)
  108. ' Refresh the friends list to all players online
  109. For i = 1 To Player_HighIndex
  110. Call UpdateFriendsList(i)
  111. Next
  112. ' Refresh the foes list to all players online
  113. For i = 1 To Player_HighIndex
  114. Call UpdateFoesList(i)
  115. Next
  116. ' Update guild list
  117. If GetPlayerGuild(index) > 0 Then
  118. Call SendPlayerGuildMembers(index)
  119. End If
  120. End Sub
  121. Sub LeftGame(ByVal index As Long)
  122. Dim n As Long, i As Long
  123. Dim TradeTarget As Long
  124. If TempPlayer(index).InGame Then
  125. TempPlayer(index).InGame = False
  126. ' Check if player was the only player on the map and stop npc processing if so
  127. If GetTotalMapPlayers(GetPlayerMap(index)) < 1 Then
  128. PlayersOnMap(GetPlayerMap(index)) = NO
  129. End If
  130. ' Clear any invites out
  131. If TempPlayer(index).TradeRequest > 0 Or TempPlayer(index).PartyInvite > 0 Or TempPlayer(index).GuildInvite > 0 Then
  132. If TempPlayer(index).TradeRequest > 0 Then
  133. Call DeclineTradeRequest(index)
  134. End If
  135. If TempPlayer(index).PartyInvite > 0 Then
  136. Call Party_InviteDecline(TempPlayer(index).PartyInvite, index)
  137. End If
  138. If TempPlayer(index).GuildInvite > 0 Then
  139. Call DeclineGuildInvite(index)
  140. End If
  141. End If
  142. ' Cancel any trade they're in
  143. If TempPlayer(index).InTrade > 0 Then
  144. TradeTarget = TempPlayer(index).InTrade
  145. PlayerMsg TradeTarget, Trim$(GetPlayerName(index)) & " has declined the trade!", BrightRed
  146. ' Clear out trade
  147. For i = 1 To MAX_INV
  148. TempPlayer(TradeTarget).TradeOffer(i).Num = 0
  149. TempPlayer(TradeTarget).TradeOffer(i).Value = 0
  150. Next
  151. TempPlayer(TradeTarget).InTrade = 0
  152. SendCloseTrade TradeTarget
  153. End If
  154. ' Leave party
  155. Party_PlayerLeave index
  156. ' Loop through entire map and purge npc targets from player
  157. For i = 1 To Map(GetPlayerMap(index)).NPC_HighIndex
  158. If MapNPC(GetPlayerMap(index)).NPC(i).Num > 0 Then
  159. If MapNPC(GetPlayerMap(index)).NPC(i).targetType = TARGET_TYPE_PLAYER Then
  160. If MapNPC(GetPlayerMap(index)).NPC(i).target = index Then
  161. MapNPC(GetPlayerMap(index)).NPC(i).target = 0
  162. MapNPC(GetPlayerMap(index)).NPC(i).targetType = TARGET_TYPE_NONE
  163. Call SendMapNPCTarget(GetPlayerMap(index), i, 0, 0)
  164. End If
  165. End If
  166. End If
  167. Next
  168. ' Refresh guild members
  169. For i = 1 To Player_HighIndex
  170. If IsPlaying(i) Then
  171. If Not i = index Then
  172. If GetPlayerGuild(i) = GetPlayerGuild(index) Then
  173. SendPlayerGuildMembers i, index
  174. End If
  175. End If
  176. End If
  177. Next
  178. ' Send a global message that they left
  179. If GetPlayerAccess(index) <= STAFF_MODERATOR Then
  180. Call GlobalMsg(GetPlayerName(index) & " has left " & Options.Name & "!", Grey)
  181. Else
  182. Call GlobalMsg(GetPlayerName(index) & " has left " & Options.Name & "!", DarkGrey)
  183. End If
  184. Call TextAdd(GetPlayerName(index) & " has disconnected from " & Options.Name & ".")
  185. Call SendLeftGame(index)
  186. TotalPlayersOnline = TotalPlayersOnline - 1
  187. ' Save and clear data
  188. Call SaveAccount(index)
  189. Call ClearAccount(index)
  190. ' Refresh the friends list of all players online
  191. For i = 1 To Player_HighIndex
  192. Call UpdateFriendsList(i)
  193. Next
  194. ' Refresh the foes list of all players online
  195. For i = 1 To Player_HighIndex
  196. Call UpdateFoesList(i)
  197. Next
  198. End If
  199. End Sub
  200. Sub PlayerWarp(ByVal index As Long, ByVal MapNum As Integer, ByVal X As Long, ByVal Y As Long, Optional ByVal NeedMap = False, Optional ByVal Dir As Integer = -1)
  201. Dim ShopNum As Long
  202. Dim OldMap As Long
  203. Dim i As Long
  204. Dim Buffer As clsBuffer
  205. ' Check for subscript out of range
  206. If IsPlaying(index) = False Or MapNum <= 0 Or MapNum > MAX_MAPS Then Exit Sub
  207. ' Check if you are out of bounds
  208. If X > Map(MapNum).MaxX Then X = Map(MapNum).MaxX
  209. If Y > Map(MapNum).MaxY Then Y = Map(MapNum).MaxY
  210. If X < 0 Then X = 0
  211. If Y < 0 Then Y = 0
  212. ' Save old map to send erase player data to
  213. OldMap = GetPlayerMap(index)
  214. If OldMap <> MapNum Then
  215. UpdateMapBlock OldMap, GetPlayerX(index), GetPlayerY(index), False
  216. End If
  217. Call SetPlayerX(index, X)
  218. Call SetPlayerY(index, Y)
  219. UpdateMapBlock MapNum, X, Y, True
  220. ' Set direction
  221. If Dir > -1 Then
  222. Call SetPlayerDir(index, Dir)
  223. End If
  224. ' if same map then just send their co-ordinates
  225. If MapNum = GetPlayerMap(index) And Not NeedMap Then
  226. Call SendPlayerPosition(index)
  227. ' Clear spell casting
  228. ClearAccountSpellBuffer index
  229. Exit Sub
  230. End If
  231. ' Clear events
  232. TempPlayer(index).EventProcessingCount = 0
  233. TempPlayer(index).EventMap.CurrentEvents = 0
  234. ' Clear target
  235. TempPlayer(index).target = 0
  236. TempPlayer(index).targetType = TARGET_TYPE_NONE
  237. SendPlayerTarget index
  238. ' Loop through entire map and purge npc targets from player
  239. For i = 1 To Map(GetPlayerMap(index)).NPC_HighIndex
  240. If MapNPC(GetPlayerMap(index)).NPC(i).Num > 0 Then
  241. If MapNPC(GetPlayerMap(index)).NPC(i).targetType = TARGET_TYPE_PLAYER Then
  242. If MapNPC(GetPlayerMap(index)).NPC(i).target = index Then
  243. MapNPC(GetPlayerMap(index)).NPC(i).target = 0
  244. MapNPC(GetPlayerMap(index)).NPC(i).targetType = TARGET_TYPE_NONE
  245. Call SendMapNPCTarget(OldMap, i, 0, 0)
  246. End If
  247. End If
  248. End If
  249. Next
  250. ' Leave the old map
  251. If Not OldMap = MapNum Then
  252. Call SendLeaveMap(index, OldMap)
  253. End If
  254. If Not OldMap = MapNum Then
  255. ' Set the new map
  256. Call SetPlayerMap(index, MapNum)
  257. End If
  258. ' Send player's equipment to new map
  259. SendMapEquipment index
  260. ' Send equipment of all people on new map
  261. If GetTotalMapPlayers(MapNum) > 0 Then
  262. For i = 1 To Player_HighIndex
  263. If IsPlaying(i) Then
  264. If GetPlayerMap(i) = MapNum Then
  265. SendMapEquipmentTo i, index
  266. End If
  267. End If
  268. Next
  269. End If
  270. ' Now we check if there were any players left on the map the player just left, and if not stop processing npcs
  271. If GetTotalMapPlayers(OldMap) = 0 Then
  272. PlayersOnMap(OldMap) = NO
  273. ' Get all NPCs' vitals
  274. For i = 1 To Map(OldMap).NPC_HighIndex
  275. If MapNPC(OldMap).NPC(i).Num > 0 Then
  276. MapNPC(OldMap).NPC(i).Vital(Vitals.HP) = GetNPCMaxVital(MapNPC(OldMap).NPC(i).Num, Vitals.HP)
  277. End If
  278. Next
  279. End If
  280. ' Clear spell casting
  281. ClearAccountSpellBuffer index
  282. ' Sets it so we know to process npcs on the map
  283. PlayersOnMap(MapNum) = YES
  284. TempPlayer(index).GettingMap = YES
  285. Set Buffer = New clsBuffer
  286. Call SendCheckForMap(index, MapNum)
  287. End Sub
  288. Sub PlayerMove(ByVal index As Long, ByVal Dir As Long, ByVal movement As Long, Optional ByVal SendToSelf As Boolean = False)
  289. Dim Buffer As clsBuffer, MapNum As Integer
  290. Dim X As Long, Y As Long, i As Long
  291. Dim Moved As Byte, MovedSoFar As Boolean
  292. Dim TileType As Long, VitalType As Long, Color As Long, Amount As Long
  293. Dim NewMapY As Long, NewMapX As Long
  294. ' Check for subscript out of range
  295. If IsPlaying(index) = False Or Dir < DIR_UP Or Dir > DIR_DOWNRIGHT Or movement < 1 Or movement > 2 Then Exit Sub
  296. ' Don't allow them to move if they are transfering to a new map
  297. If TempPlayer(index).GettingMap = YES Then Exit Sub
  298. ' Don't let them move if an event is waiting for their response
  299. If TempPlayer(index).EventProcessingCount > 0 Then
  300. For i = 1 To TempPlayer(index).EventProcessingCount
  301. If TempPlayer(index).EventProcessing(i).WaitingForResponse > 0 Then
  302. Call SendPlayerPosition(index)
  303. Exit Sub
  304. End If
  305. Next
  306. End If
  307. ' Prevent player from moving if they are casting a spell
  308. If TempPlayer(index).SpellBuffer.Spell > 0 Then Exit Sub
  309. ' If stunned, stop them moving
  310. If TempPlayer(index).StunDuration > 0 Then Exit Sub
  311. Call SetPlayerDir(index, Dir)
  312. Moved = NO
  313. MapNum = GetPlayerMap(index)
  314. Select Case Dir
  315. Case DIR_UPLEFT
  316. ' Check to make sure not outside of boundries
  317. If GetPlayerY(index) > 0 Or GetPlayerX(index) > 0 Then
  318. ' Check to make sure that the tile is walkable
  319. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_UP + 1) And Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_LEFT + 1) Then
  320. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index) - 1).Type <> TILE_TYPE_BLOCKED Then
  321. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index) - 1).Type <> TILE_TYPE_RESOURCE Then
  322. Call SetPlayerY(index, GetPlayerY(index) - 1)
  323. Call SetPlayerX(index, GetPlayerX(index) - 1)
  324. SendPlayerMove index, movement, SendToSelf
  325. Moved = YES
  326. End If
  327. End If
  328. End If
  329. Else
  330. ' Check to see if we can move them to the another map
  331. If Map(GetPlayerMap(index)).Up > 0 And Map(GetPlayerMap(index)).Left > 0 Then
  332. NewMapY = Map(Map(GetPlayerMap(index)).Up).MaxY
  333. Call PlayerWarp(index, Map(GetPlayerMap(index)).Up, GetPlayerX(index), NewMapY)
  334. Moved = YES
  335. ' clear their target
  336. TempPlayer(index).target = 0
  337. TempPlayer(index).targetType = TARGET_TYPE_NONE
  338. SendPlayerTarget index
  339. End If
  340. End If
  341. Case DIR_UPRIGHT
  342. ' Check to make sure not outside of boundries
  343. If GetPlayerY(index) > 0 Or GetPlayerX(index) < Map(MapNum).MaxX Then
  344. ' Check to make sure that the tile is walkable
  345. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_UP + 1) And Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_RIGHT + 1) Then
  346. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index) - 1).Type <> TILE_TYPE_BLOCKED Then
  347. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index) - 1).Type <> TILE_TYPE_RESOURCE Then
  348. Call SetPlayerY(index, GetPlayerY(index) - 1)
  349. Call SetPlayerX(index, GetPlayerX(index) + 1)
  350. SendPlayerMove index, movement, SendToSelf
  351. Moved = YES
  352. End If
  353. End If
  354. End If
  355. Else
  356. ' Check to see if we can move them to the another map
  357. If Map(GetPlayerMap(index)).Up > 0 And Map(GetPlayerMap(index)).Right > 0 Then
  358. NewMapY = Map(Map(GetPlayerMap(index)).Up).MaxY
  359. Call PlayerWarp(index, Map(GetPlayerMap(index)).Up, GetPlayerX(index), NewMapY)
  360. Moved = YES
  361. ' clear their target
  362. TempPlayer(index).target = 0
  363. TempPlayer(index).targetType = TARGET_TYPE_NONE
  364. SendPlayerTarget index
  365. End If
  366. End If
  367. Case DIR_DOWNLEFT
  368. ' Check to make sure not outside of boundries
  369. If GetPlayerY(index) < Map(MapNum).MaxY Or GetPlayerX(index) > 0 Then
  370. ' Check to make sure that the tile is walkable
  371. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_DOWN + 1) And Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_LEFT + 1) Then
  372. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index) + 1).Type <> TILE_TYPE_BLOCKED Then
  373. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index) + 1).Type <> TILE_TYPE_RESOURCE Then
  374. Call SetPlayerY(index, GetPlayerY(index) + 1)
  375. Call SetPlayerX(index, GetPlayerX(index) - 1)
  376. SendPlayerMove index, movement, SendToSelf
  377. Moved = YES
  378. End If
  379. End If
  380. End If
  381. Else
  382. ' Check to see if we can move them to the another map
  383. If Map(GetPlayerMap(index)).Down > 0 And Map(GetPlayerMap(index)).Left > 0 Then
  384. Call PlayerWarp(index, Map(GetPlayerMap(index)).Down, GetPlayerX(index), 0)
  385. Moved = YES
  386. ' clear their target
  387. TempPlayer(index).target = 0
  388. TempPlayer(index).targetType = TARGET_TYPE_NONE
  389. SendPlayerTarget index
  390. End If
  391. End If
  392. Case DIR_DOWNRIGHT
  393. ' Check to make sure not outside of boundries
  394. If GetPlayerY(index) < Map(MapNum).MaxY Or GetPlayerX(index) < Map(MapNum).MaxX Then
  395. ' Check to make sure that the tile is walkable
  396. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_DOWN + 1) And Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_RIGHT + 1) Then
  397. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index) + 1).Type <> TILE_TYPE_BLOCKED Then
  398. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index) + 1).Type <> TILE_TYPE_RESOURCE Then
  399. Call SetPlayerY(index, GetPlayerY(index) + 1)
  400. Call SetPlayerX(index, GetPlayerX(index) + 1)
  401. SendPlayerMove index, movement, SendToSelf
  402. Moved = YES
  403. End If
  404. End If
  405. End If
  406. Else
  407. ' Check to see if we can move them to the another map
  408. If Map(GetPlayerMap(index)).Down > 0 And Map(GetPlayerMap(index)).Right > 0 Then
  409. Call PlayerWarp(index, Map(GetPlayerMap(index)).Down, GetPlayerX(index), 0)
  410. Moved = YES
  411. ' clear their target
  412. TempPlayer(index).target = 0
  413. TempPlayer(index).targetType = TARGET_TYPE_NONE
  414. SendPlayerTarget index
  415. End If
  416. End If
  417. Case DIR_UP
  418. ' Check to make sure not outside of boundries
  419. If GetPlayerY(index) > 0 Then
  420. ' Check to make sure that the tile is walkable
  421. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_UP + 1) Then
  422. If Not IsPlayerBlocked(index, 0, -1) Then
  423. If Not IsEventBlocked(index, 0, -1) Then
  424. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type <> TILE_TYPE_BLOCKED Then
  425. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type <> TILE_TYPE_RESOURCE Then
  426. Call SetPlayerY(index, GetPlayerY(index) - 1)
  427. SendPlayerMove index, movement, SendToSelf
  428. Moved = YES
  429. End If
  430. End If
  431. End If
  432. End If
  433. End If
  434. Else
  435. ' Check to see if we can move them to the another map
  436. If Map(GetPlayerMap(index)).Up > 0 Then
  437. Call PlayerWarp(index, Map(GetPlayerMap(index)).Up, GetPlayerX(index), Map(MapNum).MaxY)
  438. Moved = YES
  439. ' Clear their target
  440. TempPlayer(index).target = 0
  441. TempPlayer(index).targetType = TARGET_TYPE_NONE
  442. SendPlayerTarget index
  443. End If
  444. End If
  445. Case DIR_DOWN
  446. ' Check to make sure not outside of boundries
  447. If GetPlayerY(index) < Map(MapNum).MaxY Then
  448. ' Check to make sure that the tile is walkable
  449. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_DOWN + 1) Then
  450. If Not IsPlayerBlocked(index, 0, 1) Then
  451. If Not IsEventBlocked(index, 0, 1) Then
  452. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type <> TILE_TYPE_BLOCKED Then
  453. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type <> TILE_TYPE_RESOURCE Then
  454. Call SetPlayerY(index, GetPlayerY(index) + 1)
  455. SendPlayerMove index, movement, SendToSelf
  456. Moved = YES
  457. End If
  458. End If
  459. End If
  460. End If
  461. End If
  462. Else
  463. ' Check to see if we can move them to the another map
  464. If Map(GetPlayerMap(index)).Down > 0 Then
  465. Call PlayerWarp(index, Map(GetPlayerMap(index)).Down, GetPlayerX(index), 0)
  466. Moved = YES
  467. ' Clear their target
  468. TempPlayer(index).target = 0
  469. TempPlayer(index).targetType = TARGET_TYPE_NONE
  470. SendPlayerTarget index
  471. End If
  472. End If
  473. Case DIR_LEFT
  474. ' Check to make sure not outside of boundries
  475. If GetPlayerX(index) > 0 Then
  476. ' Check to make sure that the tile is walkable
  477. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_LEFT + 1) Then
  478. If Not IsPlayerBlocked(index, -1, 0) Then
  479. If Not IsEventBlocked(index, -1, 0) Then
  480. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type <> TILE_TYPE_BLOCKED Then
  481. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type <> TILE_TYPE_RESOURCE Then
  482. Call SetPlayerX(index, GetPlayerX(index) - 1)
  483. SendPlayerMove index, movement, SendToSelf
  484. Moved = YES
  485. End If
  486. End If
  487. End If
  488. End If
  489. End If
  490. Else
  491. ' Check to see if we can move them to the another map
  492. If Map(GetPlayerMap(index)).Left > 0 Then
  493. Call PlayerWarp(index, Map(GetPlayerMap(index)).Left, Map(MapNum).MaxX, GetPlayerY(index))
  494. Moved = YES
  495. ' Clear their target
  496. TempPlayer(index).target = 0
  497. TempPlayer(index).targetType = TARGET_TYPE_NONE
  498. SendPlayerTarget index
  499. End If
  500. End If
  501. Case DIR_RIGHT
  502. ' Check to make sure not outside of boundries
  503. If GetPlayerX(index) < Map(MapNum).MaxX Then
  504. ' Check to make sure that the tile is walkable
  505. If Not IsDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_RIGHT + 1) Then
  506. If Not IsPlayerBlocked(index, 1, 0) Then
  507. If Not IsEventBlocked(index, 1, 0) Then
  508. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type <> TILE_TYPE_BLOCKED Then
  509. If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type <> TILE_TYPE_RESOURCE Then
  510. Call SetPlayerX(index, GetPlayerX(index) + 1)
  511. SendPlayerMove index, movement, SendToSelf
  512. Moved = YES
  513. End If
  514. End If
  515. End If
  516. End If
  517. End If
  518. Else
  519. ' Check to see if we can move them to the another map
  520. If Map(GetPlayerMap(index)).Right > 0 Then
  521. Call PlayerWarp(index, Map(GetPlayerMap(index)).Right, 0, GetPlayerY(index))
  522. Moved = YES
  523. ' Clear their target
  524. TempPlayer(index).target = 0
  525. TempPlayer(index).targetType = TARGET_TYPE_NONE
  526. SendPlayerTarget index
  527. End If
  528. End If
  529. End Select
  530. With Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index))
  531. ' Check to see if the tile is a warp tile, and if so warp them
  532. If .Type = TILE_TYPE_WARP Then
  533. MapNum = .Data1
  534. X = .Data2
  535. Y = .Data3
  536. Call PlayerWarp(index, MapNum, X, Y)
  537. Moved = YES
  538. End If
  539. ' Check for a shop, and if so open it
  540. If .Type = TILE_TYPE_SHOP Then
  541. X = .Data1
  542. If X > 0 Then ' Shop exists?
  543. If Len(Trim$(Shop(X).Name)) > 0 Then ' Name exists?
  544. SendOpenShop index, X
  545. TempPlayer(index).InShop = X ' Stops movement and the like
  546. End If
  547. End If
  548. End If
  549. ' Check to see if the tile is a bank, and if so send bank
  550. If .Type = TILE_TYPE_BANK Then
  551. SendBank index
  552. TempPlayer(index).InBank = True
  553. Moved = YES
  554. End If
  555. ' Check if it's a heal tile
  556. If .Type = TILE_TYPE_HEAL Then
  557. VitalType = .Data1
  558. Amount = .Data2
  559. If VitalType = Int(Vitals.HP) Then
  560. Color = BrightGreen
  561. ElseIf VitalType = Int(Vitals.MP) Then
  562. Color = BrightBlue
  563. End If
  564. If Not GetPlayerVital(index, VitalType) = GetPlayerMaxVital(index, VitalType) Then
  565. If GetPlayerVital(index, VitalType) + Amount > GetPlayerMaxVital(index, VitalType) Then
  566. Amount = GetPlayerMaxVital(index, VitalType) - GetPlayerVital(index, VitalType)
  567. End If
  568. SendActionMsg GetPlayerMap(index), "+" & Amount, Color, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32, 1
  569. SetPlayerVital index, VitalType, GetPlayerVital(index, VitalType) + Amount
  570. Call SendVital(index, VitalType)
  571. Else
  572. SendActionMsg GetPlayerMap(index), "+0", Color, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32, 1
  573. If TempPlayer(index).InParty > 0 Then SendPartyVitals TempPlayer(index).InParty, index
  574. End If
  575. Moved = YES
  576. End If
  577. ' Check if it's a trap tile
  578. If .Type = TILE_TYPE_TRAP Then
  579. VitalType = .Data1
  580. Amount = .Data2
  581. If VitalType = Int(Vitals.HP) Then
  582. Color = BrightRed
  583. ElseIf VitalType = Int(Vitals.MP) Then
  584. Color = Magenta
  585. End If
  586. If Not GetPlayerVital(index, VitalType) < 1 Then
  587. If GetPlayerVital(index, VitalType) - Amount < 1 Then
  588. Amount = GetPlayerVital(index, VitalType)
  589. End If
  590. SendActionMsg GetPlayerMap(index), "-" & Amount, Color, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32, 1
  591. If GetPlayerVital(index, HP) - Amount < 1 And VitalType = 1 Then
  592. KillPlayer index
  593. Call GlobalMsg(GetPlayerName(index) & " has been killed by a trap!", BrightRed)
  594. Else
  595. SetPlayerVital index, VitalType, GetPlayerVital(index, VitalType) - Amount
  596. Call SendVital(index, VitalType)
  597. End If
  598. Else
  599. SetPlayerVital index, HP, GetPlayerVital(index, HP) - Amount
  600. PlayerMsg index, "You're injured by a trap.", BrightRed
  601. Call SendVital(index, HP)
  602. ' Send vitals to party if in one
  603. If TempPlayer(index).InParty > 0 Then SendPartyVitals TempPlayer(index).InParty, index
  604. End If
  605. Moved = YES
  606. End If
  607. ' Checkpoint
  608. If .Type = TILE_TYPE_CHECKPOINT Then
  609. SetCheckpoint index, .Data1, .Data2, .Data3
  610. Moved = YES
  611. End If
  612. ' Slide
  613. If .Type = TILE_TYPE_SLIDE Then
  614. ForcePlayerMove index, MOVING_WALKING, GetPlayerDir(index)
  615. Moved = YES
  616. End If
  617. End With
  618. ' They tried to hack
  619. If Moved = NO Then
  620. Call PlayerWarp(index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index))
  621. Else
  622. X = GetPlayerX(index)
  623. Y = GetPlayerY(index)
  624. If Trim$(Account(index).Chars(GetPlayerChar(index)).Status) = "AFK" Then
  625. Account(index).Chars(GetPlayerChar(index)).Status = vbNullString
  626. Call SendPlayerStatus(index)
  627. End If
  628. ' Check to see if events are touched
  629. EventTouch index, X, Y
  630. End If
  631. End Sub
  632. Sub EventTouch(ByVal index As Long, ByVal X As Long, ByVal Y As Long)
  633. Dim EventTouched As Boolean, i As Long
  634. If TempPlayer(index).EventMap.CurrentEvents > 0 Then
  635. For i = 1 To TempPlayer(index).EventMap.CurrentEvents
  636. If Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Global = 1 Then
  637. If Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).X = X And Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Y = Y And Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Pages(TempPlayer(index).EventMap.EventPages(i).PageID).Trigger = 1 And TempPlayer(index).EventMap.EventPages(i).Visible = 1 Then EventTouched = True
  638. Else
  639. If TempPlayer(index).EventMap.EventPages(i).X = X And TempPlayer(index).EventMap.EventPages(i).Y = Y And Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Pages(TempPlayer(index).EventMap.EventPages(i).PageID).Trigger = 1 And TempPlayer(index).EventMap.EventPages(i).Visible = 1 Then EventTouched = True
  640. End If
  641. If EventTouched Then
  642. ' Process this event, it is on-touch and everything checks out.
  643. If Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Pages(TempPlayer(index).EventMap.EventPages(i).PageID).CommandListCount > 0 Then
  644. TempPlayer(index).EventProcessingCount = TempPlayer(index).EventProcessingCount + 1
  645. ReDim Preserve TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount)
  646. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).ActionTimer = timeGetTime
  647. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).CurList = 1
  648. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).CurSlot = 1
  649. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).eventID = TempPlayer(index).EventMap.EventPages(i).eventID
  650. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).PageID = TempPlayer(index).EventMap.EventPages(i).PageID
  651. TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).WaitingForResponse = 0
  652. ReDim TempPlayer(index).EventProcessing(TempPlayer(index).EventProcessingCount).ListLeftOff(0 To Map(GetPlayerMap(index)).Events(TempPlayer(index).EventMap.EventPages(i).eventID).Pages(TempPlayer(index).EventMap.EventPages(i).PageID).CommandListCount)
  653. End If
  654. EventTouched = False
  655. End If
  656. Next
  657. End If
  658. End Sub
  659. Sub ForcePlayerMove(ByVal index As Long, ByVal movement As Long, ByVal Direction As Long)
  660. If Direction < DIR_UP Or Direction > DIR_DOWNRIGHT Then Exit Sub
  661. If movement < 1 Or movement > 2 Then Exit Sub
  662. Select Case Direction
  663. Case DIR_UP
  664. If GetPlayerY(index) = 0 Then Exit Sub
  665. Case DIR_LEFT
  666. If GetPlayerX(index) = 0 Then Exit Sub
  667. Case DIR_DOWN
  668. If GetPlayerY(index) = Map(GetPlayerMap(index)).MaxY Then Exit Sub
  669. Case DIR_RIGHT
  670. If GetPlayerX(index) = Map(GetPlayerMap(index)).MaxX Then Exit Sub
  671. Case DIR_UPLEFT
  672. If GetPlayerY(index) = 0 And GetPlayerX(index) = 0 Then Exit Sub
  673. Case DIR_UPRIGHT
  674. If GetPlayerY(index) = 0 And GetPlayerX(index) = Map(GetPlayerMap(index)).MaxX Then Exit Sub
  675. Case DIR_DOWNLEFT
  676. If GetPlayerY(index) = Map(GetPlayerMap(index)).MaxY And GetPlayerX(index) = 0 Then Exit Sub
  677. Case DIR_DOWNRIGHT
  678. If GetPlayerY(index) = Map(GetPlayerMap(index)).MaxY And GetPlayerX(index) = Map(GetPlayerMap(index)).MaxX Then Exit Sub
  679. End Select
  680. PlayerMove index, Direction, movement, True
  681. End Sub
  682. Sub CheckEquippedItems(ByVal index As Long)
  683. Dim Slot As Long
  684. Dim ItemNum As Integer
  685. Dim i As Long
  686. ' We want to check incase an admin takes away an object but they had it equipped
  687. For i = 1 To Equipment.Equipment_Count - 1
  688. ItemNum = GetPlayerEquipment(index, i)
  689. If ItemNum > 0 Then
  690. If Not Item(ItemNum).Type = ITEM_TYPE_EQUIPMENT Or Not Item(ItemNum).EquipSlot = i Then SetPlayerEquipment index, 0, i
  691. Else
  692. SetPlayerEquipment index, 0, i
  693. End If
  694. Next
  695. End Sub
  696. Function FindOpenInvSlot(ByVal index As Long, ByVal ItemNum As Long) As Long
  697. Dim i As Long
  698. ' Check for subscript out of range
  699. If IsPlaying(index) = False Or ItemNum <= 0 Or ItemNum > MAX_ITEMS Then Exit Function
  700. If Item(ItemNum).Stackable = 1 Then
  701. ' If currency then check to see if they already have an instance of the item and add it to that
  702. For i = 1 To MAX_INV
  703. If GetPlayerInvItemNum(index, i) = ItemNum Then
  704. FindOpenInvSlot = i
  705. Exit Function
  706. End If
  707. Next
  708. End If
  709. For i = 1 To MAX_INV
  710. ' Try to find an open free slot
  711. If GetPlayerInvItemNum(index, i) = 0 Then
  712. FindOpenInvSlot = i
  713. Exit Function
  714. End If
  715. Next
  716. End Function
  717. Function FindOpenBankSlot(ByVal index As Long, ByVal ItemNum As Integer) As Byte
  718. Dim i As Long
  719. ' Check for subscript out of range
  720. If Not IsPlaying(index) Or ItemNum < 1 Or ItemNum > MAX_ITEMS Then Exit Function
  721. If Not Item(ItemNum).Type = ITEM_TYPE_EQUIPMENT Then
  722. For i = 1 To MAX_BANK
  723. If GetPlayerBankItemNum(index, i) = ItemNum Then
  724. FindOpenBankSlot = i
  725. Exit Function
  726. End If
  727. Next
  728. End If
  729. For i = 1 To MAX_BANK
  730. If GetPlayerBankItemNum(index, i) = 0 Then
  731. FindOpenBankSlot = i
  732. Exit Function
  733. End If
  734. Next
  735. End Function
  736. Function HasItem(ByVal index As Long, ByVal ItemNum As Integer) As Long
  737. Dim i As Long
  738. ' Check for subscript out of range
  739. If IsPlaying(index) = False Or ItemNum < 1 Or ItemNum > MAX_ITEMS Then Exit Function
  740. For i = 1 To MAX_INV
  741. ' Check to see if the player has the item
  742. If GetPlayerInvItemNum(index, i) = ItemNum Then
  743. If Item(ItemNum).Stackable = 1 Then
  744. HasItem = GetPlayerInvItemValue(index, i)
  745. Exit Function
  746. End If
  747. End If
  748. Next
  749. End Function
  750. Function TakeInvItem(ByVal index As Long, ByVal ItemNum As Integer, ByVal ItemVal As Long, Optional Update As Boolean = True) As Boolean
  751. Dim i As Long, II As Long, NPCNum As Long
  752. Dim n As Long
  753. Dim Parse() As String
  754. ' Check for subscript out of range
  755. If IsPlaying(index) = False Or ItemNum <= 0 Or ItemNum > MAX_ITEMS Then Exit Function
  756. For i = 1 To MAX_INV
  757. ' Check to see if the player has the item
  758. If GetPlayerInvItemNum(index, i) = ItemNum Then
  759. If Item(ItemNum).Stackable = 1 Then
  760. ' Is what we are trying to take away more then what they have? If so just set it to zero
  761. If ItemVal >= GetPlayerInvItemValue(index, i) Then
  762. TakeInvItem = True
  763. Else
  764. Call SetPlayerInvItemValue(index, i, GetPlayerInvItemValue(index, i) - ItemVal)
  765. If Update Then Call SendInventoryUpdate(index, i)
  766. 'check quests
  767. For II = 1 To MAX_QUESTS
  768. Parse() = Split(HasQuestItems(index, II, True), "|")
  769. If UBound(Parse()) > 0 Then
  770. NPCNum = Parse(0)
  771. If NPCNum > 0 Then
  772. Call SendShowTaskCompleteOnNPC(index, NPCNum, False)
  773. End If
  774. End If
  775. Next II
  776. Exit Function
  777. End If
  778. Else
  779. TakeInvItem = True
  780. End If
  781. If TakeInvItem Then
  782. Call SetPlayerInvItemNum(index, i, 0)
  783. Call SetPlayerInvItemValue(index, i, 0)
  784. Call SetPlayerInvItemDur(index, i, 0)
  785. Call SetPlayerInvItemBind(index, i, 0)
  786. End If
  787. End If
  788. Next
  789. 'check quests
  790. For II = 1 To MAX_QUESTS
  791. Parse() = Split(HasQuestItems(index, II, True), "|")
  792. If UBound(Parse()) > 0 Then
  793. NPCNum = Parse(0)
  794. If NPCNum > 0 Then
  795. Call SendShowTaskCompleteOnNPC(index, NPCNum, False)
  796. End If
  797. End If
  798. Next II
  799. ' Send the inventory update
  800. If Update Then Call SendInventory(index)
  801. End Function
  802. Function TakeInvSlot(ByVal index As Long, ByVal InvSlot As Byte, ByVal ItemVal As Long, Optional ByVal Update As Boolean = True) As Boolean
  803. Dim i As Long
  804. Dim n As Long
  805. Dim ItemNum As Integer
  806. ' Check for subscript out of range
  807. If IsPlaying(index) = False Or InvSlot < 1 Or InvSlot > MAX_ITEMS Then Exit Function
  808. ItemNum = GetPlayerInvItemNum(index, InvSlot)
  809. ' Prevent subscript out of range
  810. If ItemNum < 1 Then Exit Function
  811. If Item(ItemNum).Stackable = 1 Then
  812. ' Is what we are trying to take away more then what they have? If so just set it to zero
  813. If ItemVal >= GetPlayerInvItemValue(index, InvSlot) Then
  814. TakeInvSlot = True
  815. Else
  816. Call SetPlayerInvItemValue(index, InvSlot, GetPlayerInvItemValue(index, InvSlot) - ItemVal)
  817. ' Send the inventory update
  818. If Update Then
  819. Call SendInventoryUpdate(index, InvSlot)
  820. End If
  821. Exit Function
  822. End If
  823. Else
  824. TakeInvSlot = True
  825. End If
  826. If TakeInvSlot Then
  827. Call SetPlayerInvItemNum(index, InvSlot, 0)
  828. Call SetPlayerInvItemValue(index, InvSlot, 0)
  829. Call SetPlayerInvItemDur(index, InvSlot, 0)
  830. Call SetPlayerInvItemBind(index, InvSlot, 0)
  831. ' Send the inventory update
  832. If Update Then
  833. Call SendInventoryUpdate(index, InvSlot)
  834. End If
  835. End If
  836. End Function
  837. Function GiveInvItem(ByVal index As Long, ByVal ItemNum As Integer, ByVal ItemVal As Long, Optional ByVal ItemDur As Integer = -1, Optional ByVal ItemBind As Integer = 0, Optional ByVal SendUpdate As Boolean = True) As Byte
  838. Dim i As Long, II As Long, NPCNum As Long
  839. ' Check for subscript out of range
  840. If IsPlaying(index) = False Or ItemNum <= 0 Or ItemNum > MAX_ITEMS Then Exit Function
  841. i = FindOpenInvSlot(index, ItemNum)
  842. ' Check to see if inventory is full
  843. If i > 0 And i <= MAX_INV Then
  844. If CDec(GetPlayerInvItemValue(index, i)) + CDec(ItemVal) > 2147483468 Then
  845. Call PlayerMsg(index, "Cannot give it to you - it exceeds maximum limit!", BrightRed)
  846. GiveInvItem = 0
  847. Exit Function
  848. Else
  849. Call SetPlayerInvItemNum(index, i, ItemNum)
  850. Call SetPlayerInvItemValue(index, i, GetPlayerInvItemValue(index, i) + ItemVal)
  851. End If
  852. If Item(GetPlayerInvItemNum(index, i)).Type = ITEM_TYPE_EQUIPMENT Then
  853. If ItemDur = -1 Then
  854. Call SetPlayerInvItemDur(index, i, Item(ItemNum).Data1)
  855. Else
  856. Call SetPlayerInvItemDur(index, i, ItemDur)
  857. End If
  858. End If
  859. If ItemBind = BIND_ON_PICKUP Or Item(GetPlayerInvItemNum(index, i)).BindType = BIND_ON_PICKUP Then
  860. Call SetPlayerInvItemBind(index, i, BIND_ON_PICKUP)
  861. ElseIf ItemBind = BIND_ON_EQUIP Or Item(GetPlayerInvItemNum(index, i)).BindType = BIND_ON_EQUIP Then
  862. Call SetPlayerInvItemBind(index, i, BIND_ON_EQUIP)
  863. Else
  864. Call SetPlayerInvItemBind(index, i, 0)
  865. End If
  866. If SendUpdate Then Call SendInventoryUpdate(index, i)
  867. GiveInvItem = True
  868. 'check quests
  869. For II = 1 To MAX_QUESTS
  870. NPCNum = HasQuestItems(index, II)
  871. If NPCNum > 0 Then
  872. Call SendShowTaskCompleteOnNPC(index, NPCNum, True)
  873. End If
  874. Next II
  875. Else
  876. Call PlayerMsg(index, "Your inventory is full!", BrightRed)
  877. End If
  878. GiveInvItem = i
  879. End Function
  880. Function HasSpell(ByVal index As Long, ByVal SpellNum As Long) As Boolean
  881. Dim i As Long
  882. For i = 1 To MAX_PLAYER_SPELLS
  883. If GetPlayerSpell(index, i) = SpellNum Then
  884. HasSpell = True
  885. Exit Function
  886. End If
  887. Next
  888. End Function
  889. Function FindOpenSpellSlot(ByVal index As Long) As Long
  890. Dim i As Long
  891. For i = 1 To MAX_PLAYER_SPELLS
  892. If GetPlayerSpell(index, i) = 0 Then
  893. FindOpenSpellSlot = i
  894. Exit Function
  895. End If
  896. Next
  897. End Function
  898. Sub PlayerMapGetItem(ByVal index As Long, ByVal i As Long)
  899. Dim n As Long
  900. Dim MapNum As Integer
  901. Dim Msg As String
  902. Dim tempVal As Variant
  903. Dim ItemNum As Long, Value As Long, Dur As Long, Bind As Long
  904. ' Check for subscript out of range
  905. If Not IsPlaying(index) Then Exit Sub
  906. MapNum = GetPlayerMap(index)
  907. ' See if there's even an item here
  908. If (MapItem(MapNum, i).Num > 0) And (MapItem(MapNum, i).Num <= MAX_ITEMS) Then
  909. ' Can we pick the item up?
  910. If CanPlayerPickupItem(index, i) Then
  911. ' Check if item is at the same location as the player
  912. If (MapItem(MapNum, i).X = GetPlayerX(index)) Then
  913. If (MapItem(MapNum, i).Y = GetPlayerY(index)) Then
  914. ItemNum = MapItem(MapNum, i).Num
  915. Value = MapItem(MapNum, i).Value
  916. Dur = MapItem(MapNum, i).Durability
  917. Bind = Item(ItemNum).BindType
  918. If Value > 0 Then
  919. Msg = Value & " " & Trim$(Item(ItemNum).Name)
  920. Else
  921. Msg = Trim$(Item(ItemNum).Name)
  922. End If
  923. 'sure made this a lot simpler than it was, removing roughly 30 lines of code in exchange for 5. It could be done in 1 line
  924. 'but I chose to make it pretty and easy to debug had something went wrong.
  925. Call GiveInvItem(index, ItemNum, Value, Dur, Bind, True)
  926. ' Erase the item from the map
  927. MapItem(MapNum, i).Num = 0
  928. MapItem(MapNum, i).Value = 0
  929. MapItem(MapNum, i).Durability = 0
  930. MapItem(MapNum, i).X = 0
  931. MapItem(MapNum, i).Y = 0
  932. Call SendInventoryUpdate(index, n)
  933. Call SpawnItemSlot(i, 0, 0, 0, GetPlayerMap(index), 0, 0)
  934. SendActionMsg GetPlayerMap(index), Msg, Yellow, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)
  935. End If
  936. End If
  937. End If
  938. End If
  939. End Sub
  940. Function CanPlayerPickupItem(ByVal index As Long, ByVal MapItemNum As Integer)
  941. Dim MapNum As Integer
  942. MapNum = GetPlayerMap(index)
  943. ' Check for subscript out of range
  944. If MapNum < 1 Or MapNum > MAX_MAPS Then Exit Function
  945. If Moral(Map(MapNum).Moral).CanPickupItem = 1 Then
  946. ' No lock or locked to player?
  947. If Trim$(MapItem(MapNum, MapItemNum).playerName) = vbNullString Or Trim$(MapItem(MapNum, MapItemNum).playerName) = GetPlayerName(index) Then
  948. CanPlayerPickupItem = True
  949. Exit Function
  950. End If
  951. End If
  952. End Function
  953. Sub PlayerMapDropItem(ByVal index As Long, ByVal InvNum As Byte, ByVal Amount As Long)
  954. Dim i As Long
  955. Dim Msg As String
  956. If (GetPlayerInvItemNum(index, InvNum) <= MAX_ITEMS) Then
  957. i = FindOpenMapItemSlot(GetPlayerMap(index))
  958. If Not i = 0 Then
  959. MapItem(GetPlayerMap(index), i).Num = GetPlayerInvItemNum(index, InvNum)
  960. MapItem(GetPlayerMap(index), i).X = GetPlayerX(index)
  961. MapItem(GetPlayerMap(index), i).Y = GetPlayerY(index)
  962. MapItem(GetPlayerMap(index), i).playerName = Trim$(GetPlayerName(index))
  963. MapItem(GetPlayerMap(index), i).PlayerTimer = timeGetTime + ITEM_SPAWN_TIME
  964. MapItem(GetPlayerMap(index), i).CanDespawn = True
  965. MapItem(GetPlayerMap(index), i).DespawnTimer = timeGetTime + ITEM_DESPAWN_TIME
  966. If Item(GetPlayerInvItemNum(index, InvNum)).Type = ITEM_TYPE_EQUIPMENT Then
  967. MapItem(GetPlayerMap(index), i).Durability = GetPlayerInvItemDur(index, InvNum)
  968. Else
  969. MapItem(GetPlayerMap(index), i).Durability = 0
  970. End If
  971. If Item(GetPlayerInvItemNum(index, InvNum)).Stackable = 1 Then
  972. ' Check if its more then they have and if so drop it all
  973. If Amount >= GetPlayerInvItemValue(index, InvNum) Then
  974. MapItem(GetPlayerMap(index), i).Value = GetPlayerInvItemValue(index, InvNum)
  975. Msg = GetPlayerInvItemValue(index, InvNum) & " " & Trim$(Item(GetPlayerInvItemNum(index, InvNum)).Name)
  976. Call TakeInvSlot(index, InvNum, GetPlayerInvItemValue(index, InvNum), True)
  977. Else
  978. MapItem(GetPlayerMap(index), i).Value = Amount
  979. Msg = Amount & " " & Trim$(Item(GetPlayerInvItemNum(index, InvNum)).Name)
  980. Call TakeInvSlot(index, InvNum, Amount, True)
  981. End If
  982. Else
  983. ' It's not a currency object so this is easy
  984. Msg = Trim$(Item(GetPlayerInvItemNum(index, InvNum)).Name)
  985. MapItem(GetPlayerMap(index), i).Value = 0
  986. Call TakeInvSlot(index, InvNum, Amount, True)
  987. End If
  988. ' Send message
  989. SendActionMsg GetPlayerMap(index), Msg, BrightRed, 1, (GetPlayerX(index) * 32), (GetPlayerY(index) * 32)
  990. ' Spawn the item before we set the num or we'll get a different free map item slot
  991. Call SpawnItemSlot(i, MapItem(GetPlayerMap(index), i).Num, Amount, MapItem(GetPlayerMap(index), i).Durability, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index))
  992. Else
  993. Call PlayerMsg(index, "There are too many items on the ground to drop anything else.", BrightRed)
  994. End If
  995. End If
  996. End Sub
  997. Sub CheckPlayerLevelUp(ByVal index As Long)
  998. Dim i As Long
  999. Dim ExpRollOver As Long
  1000. Dim Level_Count As Long
  1001. If GetPlayerLeve

Large files files are truncated, but you can click here to view the full file