tslusny Posted March 27, 2013 Author Share Posted March 27, 2013 What this does? It will simply disable casting spells throught walls or from corners. It is unreal when you can cast spell on someone who is for example behind castle wall, isn´t it?This is only **server side** edit:First, add this sub at bottom of modGameLogic:```Public Function isPathCleared(ByVal Index As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As BooleanDim DirX As IntegerDim DirY As IntegerDim IsXDirRight As Integer ' Yeah, it just makes it easierDim IsYDirDown As IntegerDim CurX As LongDim CurY As LongDim XInSquare As Single ' Fraction of the square we're looking at, CurX,CurYDim YInSquare As SingleDim TestX As Single ' TestX is the X value when Y = 0 or Y = 1, whichever is importantDim TestY As SingleDim slope As Single' How much y for 1 xCurX = x1CurY = y1XInSquare = 0.5 ' Middle of x1YInSquare = 0.5 ' Middle of y1If x1 = x2 ThenIf y1 = y2 ThenisPathCleared = TrueExit FunctionEnd IfEnd IfIf x2 - x1 = 0 Then ' Would be divide by zero' Vertical onlyDirX = 0IsXDirRight = 0If y2 > y1 ThenDirY = 1IsYDirDown = 1ElseDirY = -1IsYDirDown = 0End IfDo' Move to the next squareCurY = CurY + DirY' Check new squareIf CurY = y2 ThenExit Do' ======ElseIf Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_BLOCKED Or Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_RESOURCE Then' ElseIf Blocked(CurX, CurY) Then' /=====isPathCleared = FalseExit FunctionEnd IfLoop While (CurY <> y2)ElseIf y2 - y1 = 0 Then' Horiz onlyDirY = 0IsYDirDown = 0If x2 > x1 ThenDirX = 1IsXDirRight = 1ElseDirX = -1IsXDirRight = 0End IfDo' Move to the next squareCurX = CurX + DirX' Check new squareIf CurX = x2 ThenExit Do' ======ElseIf Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_BLOCKED Or Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_RESOURCE Then' ElseIf Blocked(CurX, CurY) Then' /=====isPathCleared = FalseExit FunctionEnd IfLoopElse' Some sort of diagonalIf x2 > x1 ThenDirX = 1IsXDirRight = 1ElseDirX = -1IsXDirRight = 0End IfIf y2 > y1 ThenDirY = 1IsYDirDown = 1ElseDirY = -1IsYDirDown = 0End Ifslope = (y2 - y1) / (x2 - x1)Do' Move to the next squareIf IsXDirRight ThenTestY = (1 - XInSquare) * slope + YInSquareElseTestY = -XInSquare * slope + YInSquareEnd IfIf IsYDirDown ThenTestX = (1 - YInSquare) / slope + XInSquareElseTestX = -YInSquare / slope + XInSquareEnd IfIf (TestX > 0 And TestX < 1) Then' Go up or downCurY = CurY + DirY' set the coords for the new squareXInSquare = TestXYInSquare = 1 - IsYDirDownElseIf (TestY > 0 And TestY < 1) Then' Go left or rightCurX = CurX + DirX' set the coords for the new squareXInSquare = 1 - IsXDirRightYInSquare = TestYElse' Go diagonallyCurX = CurX + DirXCurY = CurY + DirY' set the coords for the new squareXInSquare = 1 - IsXDirRightYInSquare = 1 - IsYDirDownEnd If' Check new squareIf CurX = x2 And CurY = y2 ThenExit Do' ======ElseIf Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_BLOCKED Or Map(GetPlayerMap(Index)).Tile(CurX, CurY).Type = TILE_TYPE_RESOURCE Then' ElseIf Blocked(CurX, CurY) Then' /=====isPathCleared = FalseExit FunctionEnd IfLoopEnd IfisPathCleared = TrueEnd Function```Then search for Sub CastSpell and in this sub search for this:```Case 1, 3 ' self-cast AOE & targetted AOEIf SpellCastType = 1 Thenx = GetPlayerX(Index)y = GetPlayerY(Index)ElseIf SpellCastType = 3 ThenIf TargetType = 0 Then Exit SubIf target = 0 Then Exit SubIf TargetType = targetPlayer Thenx = GetPlayerX(target)y = GetPlayerY(target)Elsex = MapNpc(MapNum).Npc(target).xy = MapNpc(MapNum).Npc(target).yEnd IfIf Not isInRange(Range, GetPlayerX(Index), GetPlayerY(Index), x, y) ThenPlayerMsg Index, "Target not in range.", BrightRedSendClearSpellBuffer IndexEnd If```And add this **under** it:```If Not isPathCleared(Index, GetPlayerX(Index), GetPlayerY(Index), x, y) ThenPlayerMsg Index, "Can not reach target.", BrightRedSendClearSpellBuffer IndexExit SubEnd If```Now search for this:```Case 2 ' targettedIf TargetType = 0 Then Exit SubIf target = 0 Then Exit SubIf TargetType = targetPlayer Thenx = GetPlayerX(target)y = GetPlayerY(target)Elsex = MapNpc(MapNum).Npc(target).xy = MapNpc(MapNum).Npc(target).yEnd IfIf Not isInRange(Range, GetPlayerX(Index), GetPlayerY(Index), x, y) ThenPlayerMsg Index, "Target not in range.", BrightRedSendClearSpellBuffer IndexExit SubEnd If```and add this **under** it:```If Not isPathCleared(Index, GetPlayerX(Index), GetPlayerY(Index), x, y) ThenPlayerMsg Index, "Can not reach target.", BrightRedSendClearSpellBuffer IndexExit SubEnd If``` Link to comment Share on other sites More sharing options...
abhi2011 Posted March 27, 2013 Share Posted March 27, 2013 Ain't the ability to cause damage if the person is behind something the biggest plus point of magic? Link to comment Share on other sites More sharing options...
tslusny Posted March 27, 2013 Author Share Posted March 27, 2013 > Ain't the ability to cause damage if the person is behind something the biggest plus point of magic?No, i hate that thing in EO ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png) Link to comment Share on other sites More sharing options...
Guest Posted March 27, 2013 Share Posted March 27, 2013 Magic in games is usually used in other games (including ranged) to hit people from spots where they cant hit you. Take Runescape for example. Link to comment Share on other sites More sharing options...
Alerd Posted March 27, 2013 Share Posted March 27, 2013 Very thanx for this tutorial Link to comment Share on other sites More sharing options...
WiseRock Posted March 27, 2013 Share Posted March 27, 2013 Some reason Now I cant attack NPCs with Spells Link to comment Share on other sites More sharing options...
Alerd Posted March 27, 2013 Share Posted March 27, 2013 Everything works flawlessly Link to comment Share on other sites More sharing options...
WiseRock Posted March 27, 2013 Share Posted March 27, 2013 i fixed put one of the things in the wrong place good job Death! Link to comment Share on other sites More sharing options...
tslusny Posted March 27, 2013 Author Share Posted March 27, 2013 > i fixed put one of the things in the wrong place good job Death!I am glad that it is working ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
DMF Posted March 28, 2013 Share Posted March 28, 2013 i understand wat you mean death, and realisticly , but also i think wat should be moded here is make it a check box with spellediter so you can choose spells that are limited or not? Link to comment Share on other sites More sharing options...
Guest Posted March 28, 2013 Share Posted March 28, 2013 I think a more usesful system is changing how spells work. Make it so you cast it and click where it is on the map, that adds aim to the game. That'd be a little more useful than this, although, this adds a realistic point of view. If you do that, you can mash my idea with this and it would be a pretty sweet spell system. Link to comment Share on other sites More sharing options...
Valentine90 Posted March 29, 2013 Share Posted March 29, 2013 Very nice! Link to comment Share on other sites More sharing options...
teamokell Posted September 30, 2013 Share Posted September 30, 2013 Added one more feature to the script: It appears only CASTING [NAME OF MAGIC]! if you can hit the magic. Otherwise it will be ignored avoiding spam on the screen.ModCombat ~ ServerSideSearch for:```If HasBuffered Then SendAnimation mapNum, Spell(spellnum).CastAnim, 0, 0, TARGET_TYPE_PLAYER, Index```An add this under it:```If isPathCleared(Index, GetPlayerX(Index), GetPlayerY(Index), x, y) Then```Search for:```If HasBuffered Then SendAnimation mapNum, Spell(spellnum).CastAnim, 0, 0, TARGET_TYPE_PLAYER, Index```An add it above this:```If targetType = TARGET_TYPE_PLAYER Then x = GetPlayerX(target) y = GetPlayerY(target) Else x = MapNpc(mapNum).Npc(target).x y = MapNpc(mapNum).Npc(target).y End If```Search for:```Function BufferSpell(ByVal Index As Long, ByVal spellslot As Long)```After```Dim targetType As ByteDim target As Long```Add it:```Dim x As LongDim y As Long```Search for:```TempPlayer(Index).SpellCD(spellslot) = GetTickCount + (Spell(spellnum).CDTime * 1000)Call SendCooldown(Index, spellslot)```An under it add:```If isPathCleared(Index, GetPlayerX(Index), GetPlayerY(Index), x, y) Then```After:```SendActionMsg mapNum, Trim$(Spell(spellnum).Name) & "!", BrightRed, ACTIONMSG_SCROLL, GetPlayerX(Index) * 32, GetPlayerY(Index) * 32```An Add under it:```End if``` Link to comment Share on other sites More sharing options...
Jed Posted December 22, 2013 Share Posted December 22, 2013 This code works just fine, but there are some instances where I get a subscript out of range error here:``` ' Check new square If CurX = x2 And CurY = y2 Then Exit Do ' ====== ElseIf Map(GetPlayerMap(index)).Tile(CurX, CurY).Type = TILE_TYPE_BLOCKED Or Map(GetPlayerMap(index)).Tile(CurX, CurY).Type = TILE_TYPE_RESOURCE Then ' ElseIf Blocked(CurX, CurY) Then ' /===== isPathCleared = False Exit Function End If Loop End If isPathCleared = True End Function```On this line:``` ElseIf Map(GetPlayerMap(index)).Tile(CurX, CurY).Type = TILE_TYPE_BLOCKED Or Map(GetPlayerMap(index)).Tile(CurX, CurY).Type = TILE_TYPE_RESOURCE Then```I've tried recreating the error and it seems to happen when an NPC moves into only horizontal or vertical range from the diagonal calculation. 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