Originally posted by Obsidian
Original Code - GodSentDeath
Difficulty - 2/5
::::::::::::::::::::: ::CLIENT SIDE:: :::::::::::::::::::::
In modClientTCP (or modHandleData, depending on which version of MS you're using) go to the sub "HandleData" and at the bottom before
end sub
add
' :::::::::::::::::::::::: ' :: Blit Player Damage :: ' :::::::::::::::::::::::: If LCase(Parse(0)) = "blitplayerdmg" Then DmgDamage = Val(Parse(1)) NPCWho = Val(Parse(2)) DmgTime = GetTickCount iii = 0 Exit Sub End If ' ::::::::::::::::::::: ' :: Blit NPC Damage :: ' ::::::::::::::::::::: If LCase(Parse(0)) = "blitnpcdmg" Then NPCDmgDamage = Val(Parse(1)) NPCDmgTime = GetTickCount ii = 0 Exit Sub End If
Now go into modGameLogic, at the top of that module, in the declares statements, add these statements
Public DmgDamage As Long Public DmgTime As Long Public NPCDmgDamage As Long Public NPCDmgTime As Long Public NPCWho As Long Public ii As Long, iii As Long
' Variables Public NewPlayerX As Long Public NewPlayerY As Long Public NewXOffset As Long Public NewYOffset As Long Public NewX As Long Public NewY As Long Public sx as Long
The "Variables" listed above, may be duplicates of something you already have, if they are, you can just delete them. Now, still in modGameLogic go into the GameLoop Sub and under the comment that says
' Lock the backbuffer so we can draw text and names
add this code
If NPCWho > 0 Then If MapNpc(NPCWho).Num > 0 Then If GetTickCount < NPCDmgTime + 2000 Then Call DrawText(TexthDC, (Player(MyIndex).x) * PIC_X + sx + (Int(Len(NPCDmgDamage)) / 2) * 3 + Player(MyIndex).XOffset - NewXOffset, (Player(MyIndex).y) * PIC_Y + sx - 30 + Player(MyIndex).YOffset - NewYOffset - ii, NPCDmgDamage, QBColor(BrightRed)) End If ii = ii + 1 End If End If If NPCWho > 0 Then If MapNpc(NPCWho).Num > 0 Then If GetTickCount < DmgTime + 2000 Then Call DrawText(TexthDC, (MapNpc(NPCWho).x - NewPlayerX) * PIC_X + sx + (Int(Len(DmgDamage)) / 2) * 3 + MapNpc(NPCWho).XOffset - NewXOffset, (MapNpc(NPCWho).y - NewPlayerY) * PIC_Y + sx - 57 + MapNpc(NPCWho).YOffset - NewYOffset - iii, DmgDamage, QBColor(White)) End If iii = iii + 1 End If End If
If you have ANY problems with this code, view the note at the bottom of this tutorial.
Carrying on...
:::::::::::::::::::::: ::SERVER SIDE:: ::::::::::::::::::::::
In modGameLogic the sub NPCAttackPlayer, at the bottom of the sub, but before the
end sub
add
Call SendDataTo(Victim, "BLITNPCDMG" & SEP_CHAR & Damage & SEP_CHAR & END_CHAR)
Now in modServerTCP (or possibly modHandleData... does the MSE server use modHandleData for both?) find the HandleDataSub find the "Player Attack Packet" the parse line looks like
If LCase(Parse(0)) = "attack" Then
Ok, now scroll down in that code, just before the bottom of that packet there is a line that looks like this
' Try to attack a npc
if you scroll down just a little bit further, you will see a line that looks like
If Damage > 0 Then
from that line to the FIRST EXIT SUB should be changed to look like this
If Damage > 0 Then Call AttackNpc(Index, i, Damage) Call SendDataTo(Index, "BLITPLAYERDMG" & SEP_CHAR & Damage & SEP_CHAR & i & SEP_CHAR & END_CHAR) Else Call PlayerMsg(Index, "Your attack does nothing.", BrightRed) Call SendDataTo(Index, "BLITPLAYERDMG" & SEP_CHAR & Damage & SEP_CHAR & i & SEP_CHAR & END_CHAR) End If Exit Sub
Okay, that is all if you have problems with the red text (npcs attacking you) then you may need to change that line to look like
Call DrawText(TexthDC, (Int(Len(NPCDmgDamage)) / 2) * 3 + NewX + sx, NewY - 22 - ii + sx, NPCDmgDamage, QBColor(BrightRed))
That code did not work for me, so i rewrote it as shown at the beginning of the tutorial. Please Post Any Comments/Mistakes.
~Obsidian
|