Octohunter Posted December 18, 2011 Author Share Posted December 18, 2011 In the spirit of Christmas, I've decided to release this. Paste it wherever you want (mine is in modCombat). This little snippet of code essentially detects blocked tiles between the player and the target, making it useful for stopping players from casting spells through walls.I ripped this straight from one of my projects, so feel free to comment out the "Subscript Out of Range Blocked" text, it was for testing purposes.Please also note that "range" in this case would be the length of the line.```Public Function collisionLine(ByVal index As Long, ByVal target As Long, ByVal range As Long) As BooleanDim Run As LongDim Rise As LongDim r As LongDim i As LongDim mapNum As LongDim pX As LongDim pY As LongDim tX As LongDim tY As LongDim nVal As LongmapNum = GetPlayerMap(index)collisionLine = TruepX = GetPlayerX(index)pY = GetPlayerY(index) If TempPlayer(index).targetType = TARGET_TYPE_NPC Then nVal = Sqr((GetPlayerX(index) - MapNpc(mapNum).Npc(target).x) ^ 2 + (GetPlayerY(index) - MapNpc(mapNum).Npc(target).y) ^ 2) Run = (MapNpc(mapNum).Npc(target).x - GetPlayerX(index)) / nVal Rise = (MapNpc(mapNum).Npc(target).y - GetPlayerY(index)) / nVal tX = MapNpc(mapNum).Npc(target).x tY = MapNpc(mapNum).Npc(target).y Else If TempPlayer(index).target = index Then Exit Function nVal = Sqr((GetPlayerX(target) - GetPlayerX(index)) ^ 2 + (GetPlayerY(target) - GetPlayerY(index)) ^ 2) Run = (GetPlayerX(target) - GetPlayerX(index)) / nVal Rise = (GetPlayerY(target) - GetPlayerY(index)) / nVal tX = GetPlayerX(target) tY = GetPlayerY(target) End If If Not isInRange(range, pX, pY, tX, tY) Then PlayerMsg index, "Target not in range", BrightRed End IfFor r = 1 To Int(nVal) If pX > tX And pY > tY Then If pX + (Run * r) < tX Or pY + (Rise * r) < tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX > tX And pY < tY Then If pX + (Run * r) < tX Or pY + (Rise * r) > tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX < tX And pY > tY Then If pX + (Run * r) > tX Or pY + (Rise * r) < tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX < tX And pY < tY Then If pX + (Run * r) > tX Or pY + (Rise * r) > tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX < tX And pY = tY Then If pX + (Run * r) > tX Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX > tX And pY = tY Then If pX + (Run * r) < tX Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX = tX And pY < tY Then If pY + (Rise * r) > tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If ElseIf pX = tX And pY > tY Then If pY + (Rise * r) < tY Then PlayerMsg index, "Subscript Out of Range Blocked!", BrightRed Exit For End If End If If Map(mapNum).Tile(pX + (Run * r), pY + (Rise * r)).Type = TILE_TYPE_BLOCKED Then PlayerMsg index, "Your attack hit the wall!", BrightRed Exit Function End IfNextcollisionLine = FalseEnd Function```No credit required, it's Christmas :DPlease do comment if this doesn't work. Link to comment Share on other sites More sharing options...
Esmeyana Posted December 19, 2011 Share Posted December 19, 2011 Nice work :DThanks and merry christmas :) 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