Set NPC HP/EXP - Tutorial Bot - 02-06-2006
Author: grimsk8ter11
Difficulty: 1/5
:: SERVER SIDE ::
In modTypes, fin:
Beneath, add:Code: MaxHP As Long
GiveEXP As Long
Find Sub ClearNPC(ByVal Index As Long), replace it with:Code: Sub ClearNpc(ByVal Index As Long)
Npc(Index).Name = ""
Npc(Index).AttackSay = ""
Npc(Index).Sprite = 0
Npc(Index).SpawnSecs = 0
Npc(Index).Behavior = 0
Npc(Index).Range = 0
Npc(Index).DropChance = 0
Npc(Index).DropItem = 0
Npc(Index).DropItemValue = 0
Npc(Index).STR = 0
Npc(Index).DEF = 0
Npc(Index).SPEED = 0
Npc(Index).MAGI = 0
Npc(Index).MaxHP = 0
Npc(Index).GiveEXP = 0
End Sub
In modGameLogic, find:Code: ' Calculate exp to give attacker
Change it to:Code: ' Calculate exp to give attacker
Exp = Npc(NpcNum).GiveEXP
In modHandleData, find:Replace with:Code: ' :::::::::::::::::::::
' :: Save npc packet ::
' :::::::::::::::::::::
If LCase(Parse(0)) = "savenpc" Then
' Prevent hacking
If GetPlayerAccess(Index) < ADMIN_DEVELOPER Then
Call HackingAttempt(Index, "Admin Cloning")
Exit Sub
End If
N = Val(Parse(1))
' Prevent hacking
If N < 0 Or N > MAX_NPCS Then
Call HackingAttempt(Index, "Invalid NPC Index")
Exit Sub
End If
' Update the npc
Npc(N).Name = Parse(2)
Npc(N).AttackSay = Parse(3)
Npc(N).Sprite = Val(Parse(4))
Npc(N).SpawnSecs = Val(Parse(5))
Npc(N).Behavior = Val(Parse(6))
Npc(N).Range = Val(Parse(7))
Npc(N).DropChance = Val(Parse(8))
Npc(N).DropItem = Val(Parse(9))
Npc(N).DropItemValue = Val(Parse(10))
Npc(N).STR = Val(Parse(11))
Npc(N).DEF = Val(Parse(12))
Npc(N).SPEED = Val(Parse(13))
Npc(N).MAGI = Val(Parse(14))
Npc(N).MaxHP = Val(Parse(15))
Npc(N).GiveEXP = Val(Parse(16))
' Save it
Call SendUpdateNpcToAll(N)
Call SaveNpc(N)
Call AddLog(GetPlayerName(Index) & " saved npc #" & N & ".", ADMIN_LOG)
Exit Sub
End If
Find:Code: Sub SendEditNpcTo(ByVal Index As Long, ByVal NpcNum As Long)
Replace with:Code: Sub SendEditNpcTo(ByVal Index As Long, ByVal NpcNum As Long)
Dim Packet As String
Packet = "EDITNPC" & SEP_CHAR & NpcNum & SEP_CHAR & Trim(Npc(NpcNum).Name) & SEP_CHAR & Trim(Npc(NpcNum).AttackSay) & SEP_CHAR & Npc(NpcNum).Sprite & SEP_CHAR & Npc(NpcNum).SpawnSecs & SEP_CHAR & Npc(NpcNum).MaxHP & SEP_CHAR & Npc(NpcNum).GiveEXP & SEP_CHAR & Npc(NpcNum).Behavior & SEP_CHAR & Npc(NpcNum).Range & SEP_CHAR & Npc(NpcNum).DropChance & SEP_CHAR & Npc(NpcNum).DropItem & SEP_CHAR & Npc(NpcNum).DropItemValue & SEP_CHAR & Npc(NpcNum).STR & SEP_CHAR & Npc(NpcNum).DEF & SEP_CHAR & Npc(NpcNum).SPEED & SEP_CHAR & Npc(NpcNum).MAGI & SEP_CHAR & END_CHAR
Call SendDataTo(Index, Packet)
End Sub
Find "Sub SaveNpc(ByVal NpcNum As Long)" in modDatabase. Replace it with:Code: Sub SaveNpc(ByVal NpcNum As Long)
Dim FileName As String
FileName = App.Path & "\npcs.ini"
Call PutVar(FileName, "NPC" & NpcNum, "Name", Trim(Npc(NpcNum).Name))
Call PutVar(FileName, "NPC" & NpcNum, "AttackSay", Trim(Npc(NpcNum).AttackSay))
Call PutVar(FileName, "NPC" & NpcNum, "Sprite", Trim(Npc(NpcNum).Sprite))
Call PutVar(FileName, "NPC" & NpcNum, "SpawnSecs", Trim(Npc(NpcNum).SpawnSecs))
Call PutVar(FileName, "NPC" & NpcNum, "Behavior", Trim(Npc(NpcNum).Behavior))
Call PutVar(FileName, "NPC" & NpcNum, "MaxHP", Trim(Npc(NpcNum).MaxHP))
Call PutVar(FileName, "NPC" & NpcNum, "GiveEXP", Trim(Npc(NpcNum).GiveEXP))
Call PutVar(FileName, "NPC" & NpcNum, "Range", Trim(Npc(NpcNum).Range))
Call PutVar(FileName, "NPC" & NpcNum, "DropChance", Trim(Npc(NpcNum).DropChance))
Call PutVar(FileName, "NPC" & NpcNum, "DropItem", Trim(Npc(NpcNum).DropItem))
Call PutVar(FileName, "NPC" & NpcNum, "DropItemValue", Trim(Npc(NpcNum).DropItemValue))
Call PutVar(FileName, "NPC" & NpcNum, "STR", Trim(Npc(NpcNum).STR))
Call PutVar(FileName, "NPC" & NpcNum, "DEF", Trim(Npc(NpcNum).DEF))
Call PutVar(FileName, "NPC" & NpcNum, "SPEED", Trim(Npc(NpcNum).SPEED))
Call PutVar(FileName, "NPC" & NpcNum, "MAGI", Trim(Npc(NpcNum).MAGI))
End Sub
Find:
Replace with:Code: Sub LoadNpcs()
On Error Resume Next
Dim FileName As String
Dim I As Long
Call CheckNpcs
FileName = App.Path & "\npcs.ini"
For I = 1 To MAX_NPCS
Call SetStatus("Loading NPCs " & I & "/" & MAX_NPCS & " : " & (I / MAX_NPCS) * 100 & "%")
frmLoad.pbarLoad.Min = I
frmLoad.pbarLoad.Max = MAX_NPCS
Npc(I).Name = GetVar(FileName, "NPC" & I, "Name")
Npc(I).AttackSay = GetVar(FileName, "NPC" & I, "AttackSay")
Npc(I).Sprite = GetVar(FileName, "NPC" & I, "Sprite")
Npc(I).SpawnSecs = GetVar(FileName, "NPC" & I, "SpawnSecs")
Npc(I).Behavior = GetVar(FileName, "NPC" & I, "Behavior")
Npc(I).Range = GetVar(FileName, "NPC" & I, "Range")
Npc(I).DropChance = GetVar(FileName, "NPC" & I, "DropChance")
Npc(I).DropItem = GetVar(FileName, "NPC" & I, "DropItem")
Npc(I).DropItemValue = GetVar(FileName, "NPC" & I, "DropItemValue")
Npc(I).STR = GetVar(FileName, "NPC" & I, "STR")
Npc(I).DEF = GetVar(FileName, "NPC" & I, "DEF")
Npc(I).SPEED = GetVar(FileName, "NPC" & I, "SPEED")
Npc(I).MAGI = GetVar(FileName, "NPC" & I, "MAGI")
Npc(I).MaxHP = GetVar(FileName, "NPC" & I, "MaxHP")
Npc(I).GiveEXP = GetVar(FileName, "NPC" & I, "GiveEXP")
DoEvents
Next I
End Sub
Find:Code: Function GetNpcMaxHP(ByVal NpcNum As Long)
Replace with:Code: Function GetNpcMaxHP(ByVal NpcNum As Long)
' Prevent subscript out of range
If NpcNum MAX_NPCS Then
GetNpcMaxHP = 0
Exit Function
End If
GetNpcMaxHP = Npc(NpcNum).MaxHP
End Function
:: CLIENT SIDE ::
In frmNpcEditor, delete the labels next to Start HP and EXP Given (the ones that show their values). Next, open the code and find these:Code: Private Sub scrlSTR_Change()
Code: Private Sub scrlDEF_Change()
Make them look like this:Code: Private Sub scrlSTR_Change()
lblSTR.Caption = STR(scrlSTR.Value)
End Sub
Private Sub scrlDEF_Change()
lblDEF.Caption = STR(scrlDEF.Value)
End Sub
In modTypes, find:
Add these somewhere in there:Code: MaxHP As Long
GiveEXP As Long
In modGameLogic, find:Code: Public Sub NpcEditorInit()
Repalce with:Code: Public Sub NpcEditorInit()
On Error Resume Next
frmNpcEditor.picSprites.Picture = LoadPicture(App.Path & "\gfx\sprites.bmp")
frmNpcEditor.txtName.Text = Trim(Npc(EditorIndex).Name)
frmNpcEditor.txtAttackSay.Text = Trim(Npc(EditorIndex).AttackSay)
frmNpcEditor.scrlSprite.Value = Npc(EditorIndex).Sprite
frmNpcEditor.txtSpawnSecs.Text = STR(Npc(EditorIndex).SpawnSecs)
frmNpcEditor.cmbBehavior.ListIndex = Npc(EditorIndex).Behavior
frmNpcEditor.scrlRange.Value = Npc(EditorIndex).Range
frmNpcEditor.txtChance.Text = STR(Npc(EditorIndex).DropChance)
frmNpcEditor.scrlNum.Value = Npc(EditorIndex).DropItem
frmNpcEditor.scrlValue.Value = Npc(EditorIndex).DropItemValue
frmNpcEditor.scrlSTR.Value = Npc(EditorIndex).STR
frmNpcEditor.scrlDEF.Value = Npc(EditorIndex).DEF
frmNpcEditor.scrlSPEED.Value = Npc(EditorIndex).SPEED
frmNpcEditor.scrlMAGI.Value = Npc(EditorIndex).MAGI
frmNpcEditor.txtMaxHP.Text = Trim(Npc(EditorIndex).MaxHP)
frmNpcEditor.txtGiveEXP.Text = Trim(Npc(EditorIndex).GiveEXP)
frmNpcEditor.Show vbModal
End Sub
Find:Code: Public Sub NpcEditorOk()
Replace with:Code: Public Sub NpcEditorOk()
Npc(EditorIndex).Name = frmNpcEditor.txtName.Text
Npc(EditorIndex).AttackSay = frmNpcEditor.txtAttackSay.Text
Npc(EditorIndex).Sprite = frmNpcEditor.scrlSprite.Value
Npc(EditorIndex).SpawnSecs = Val(frmNpcEditor.txtSpawnSecs.Text)
Npc(EditorIndex).Behavior = frmNpcEditor.cmbBehavior.ListIndex
Npc(EditorIndex).Range = frmNpcEditor.scrlRange.Value
Npc(EditorIndex).DropChance = Val(frmNpcEditor.txtChance.Text)
Npc(EditorIndex).DropItem = frmNpcEditor.scrlNum.Value
Npc(EditorIndex).DropItemValue = frmNpcEditor.scrlValue.Value
Npc(EditorIndex).STR = frmNpcEditor.scrlSTR.Value
Npc(EditorIndex).DEF = frmNpcEditor.scrlDEF.Value
Npc(EditorIndex).SPEED = frmNpcEditor.scrlSPEED.Value
Npc(EditorIndex).MAGI = frmNpcEditor.scrlMAGI.Value
Npc(EditorIndex).MaxHP = frmNpcEditor.txtMaxHP.Text
Npc(EditorIndex).GiveEXP = frmNpcEditor.txtGiveEXP.Text
Call SendSaveNpc(EditorIndex)
InNpcEditor = False
Unload frmNpcEditor
End Sub
In modClientTCP, find:Code: Sub SendSaveNpc(ByVal NpcNum As Long)
Replace with:Code: Sub SendSaveNpc(ByVal NpcNum As Long)
Dim Packet As String
Packet = "SAVENPC" & SEP_CHAR & NpcNum & SEP_CHAR & Trim(Npc(NpcNum).Name) & SEP_CHAR & Trim(Npc(NpcNum).AttackSay) & SEP_CHAR & Npc(NpcNum).Sprite & SEP_CHAR & Npc(NpcNum).SpawnSecs & SEP_CHAR & Npc(NpcNum).MaxHP & SEP_CHAR & Npc(NpcNum).GiveEXP & SEPCHAR & Npc(NpcNum).Behavior & SEP_CHAR & Npc(NpcNum).Range & SEP_CHAR & Npc(NpcNum).DropChance & SEP_CHAR & Npc(NpcNum).DropItem & SEP_CHAR & Npc(NpcNum).DropItemValue & SEP_CHAR & Npc(NpcNum).STR & SEP_CHAR & Npc(NpcNum).DEF & SEP_CHAR & Npc(NpcNum).SPEED & SEP_CHAR & Npc(NpcNum).MAGI & SEP_CHAR & END_CHAR
Call SendData(Packet)
End Sub
Find partial code)Code: ' :::::::::::::::::::::::
' :: Update npc packet ::
' :::::::::::::::::::::::
Repalce with:Code: ' :::::::::::::::::::::::
' :: Update npc packet ::
' :::::::::::::::::::::::
If (LCase(Parse(0)) = "updatenpc") Then
n = Val(Parse(1))
' Update the item
Npc(n).Name = Parse(2)
Npc(n).AttackSay = ""
Npc(n).Sprite = Val(Parse(3))
Npc(n).SpawnSecs = 0
Npc(n).Behavior = 0
Npc(n).Range = 0
Npc(n).DropChance = 0
Npc(n).DropItem = 0
Npc(n).DropItemValue = 0
Npc(n).STR = 0
Npc(n).DEF = 0
Npc(n).SPEED = 0
Npc(n).MAGI = 0
Npc(n).MaxHP = 0
Npc(n).GiveEXP = 0
Exit Sub
End If
Find partial code)[code] ' :::::::::::::::::::::
' :: Edit npc packet ::
Re: Set NPC HP/EXP - Sh4d0ws - 19-10-2007
In one of the packets on the client, your SEP_CHAR is missing an _
Re: Set NPC HP/EXP - Robin - 19-10-2007
We have a Tutorial Bot?
Re: Set NPC HP/EXP - William - 19-10-2007
Yeah, I just dont know how it works. Cruzn said something about all the tutorials being stored in him.
Re: Set NPC HP/EXP - Rezeyu - 19-10-2007
grimsk8ter11 = Tutorialbot?
Re: Set NPC HP/EXP - Matt - 19-10-2007
No. His posts in here were just converted to the "bot".
Re: Set NPC HP/EXP - ZipZap - 28-01-2008
' Calculate exp to give attacker
Exp = Npc(NpcNum).GiveEXP
Variable not defined.
Any help?
Re: Set NPC HP/EXP - Anthony - 28-01-2008
Is it saying NpcNum isn't defined? Thats sort of weird, make sure something like, Dim NpcNum as Long is at the top of the sub AttackNpc.
Re: Set NPC HP/EXP - ZipZap - 28-01-2008
I added that, but still same thing...
I also removed
Code: frmLoad.pbarLoad.Min = I
frmLoad.pbarLoad.Max = MAX_NPCS
Becuase it said:
frmLoad.pbarLoad.Min = I
frmLoad.pbarLoad.Max = MAX_NPCS
Variable not defined... (But, would that make any diference?) I am using mirage source 3.0.3
Edit: Ahh, hah! There were two " ' Calculate exp to give attacker"s!
I just went with the first one I saw. I put it in Sub AttackPlayer, when it was supposed to go in Sub AttackNpc. That pbarload that i deleted shouldn't mess anything up should it?
Re: Set NPC HP/EXP - ZipZap - 29-01-2008
(Sorry for double-posting, please don't kill me. I won't do it again... My other post was just getting kinda jumbled up.)
Has anyone else used this successfully? This messed my whole NPC system..
I can't attack with Ctrl now, and the stats don't save, or load up again correctly...
Re: Set NPC HP/EXP - Anthony - 29-01-2008
Probably your not parsing information across properly would be the reason they aren't saving and loading right. The best thing I would suggest you do is go to your client, fine /editnpc and then follow every step through to the end back and forth from server to client and make sure all the data being sent is the same as the data being received. Then, when all thats right, make sure you Sub AttackNpc isn't all screwed up. By the sounds of things, it probably is . Compare it to a Vanilla MSE.
|