Print Page | Close Window

You set NPC HP and EXP

Printed From: Mirage Source
Category: Tutorials
Forum Name: Temporary Archive (Read Only)
Forum Discription: Temporary 3.0.3 archive tutorials, will be deleted when converted.
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=186
Printed Date: 20 December 2006 at 5:53pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: You set NPC HP and EXP
Posted By: Sync
Subject: You set NPC HP and EXP
Date Posted: 11 February 2006 at 3:21pm
Meh, took me awhile to find everything, but for lazy peoples here you go. :-)

::::::::::::::::::::::::::
:::::: Client Side ::::::
::::::::::::::::::::::::::

Now, Open frmNpcEditor

Delete the lables next to Start HP and EXP Given or whatnot. :-) Next open the code and find these.

Private Sub scrlSTR_Change()

Private Sub scrlDEF_Change()


Make them look like this.

Private Sub scrlSTR_Change()
    lblSTR.Caption = STR(scrlSTR.Value)
End Sub

Private Sub scrlDEF_Change()
    lblDEF.Caption = STR(scrlDEF.Value)
End Sub


Now....Open ModTypes. Find
Type NpcRec
. Add these somewhere in there.,
    MaxHP As Long
    GiveEXP As Long


Now find
Public Sub NpcEditorInit()
in ModGameLogic. Repalce it with this.
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


Now find
Public Sub NpcEditorOk()
. Replace it with this:
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


Open ModClientTCP. Find
Sub SendSaveNpc(ByVal NpcNum As Long)


Replace it with:
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


Now find    
    ' :::::::::::::::::::::::
    ' :: Update npc packet ::
    ' :::::::::::::::::::::::


Repalce it with this:
    ' :::::::::::::::::::::::
    ' :: 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


Now find
    ' :::::::::::::::::::::
    ' :: Edit npc packet :: <- Used for item editor admins only
    ' :::::::::::::::::::::


Replace it with:
    ' :::::::::::::::::::::
    ' :: Edit npc packet :: <- Used for item editor admins only
    ' :::::::::::::::::::::
    If (LCase(Parse(0)) = "editnpc") Then
        n = Val(Parse(1))
       
        ' 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))
       
        ' Initialize the npc editor
        Call NpcEditorInit

        Exit Sub
    End If


That is ALL for the client side! w00t w00t! Haha. Now....

::::::::::::::::::::::::::
::::: Server Side ::::::
::::::::::::::::::::::::::

Open ModTypes. Find
Type NpcRec
. Add these:
    MaxHP As Long
    GiveEXP As Long


Now find Sub ClearNPC(ByVal Index As Long)

Replace it with:
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

Now open ModGameLogic. Find      
' Calculate exp to give attacker

Change to:
        ' Calculate exp to give attacker
        Exp = Npc(NpcNum).GiveEXP

Now Open ModServerTCP. Find
Save NPC Packet
. Replace it with this:
    ' :::::::::::::::::::::
    ' :: 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

Now find
Sub SendEditNpcTo(ByVal Index As Long, ByVal NpcNum As Long)
Replace it with:
 
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

Now find Sub SaveNpc(ByVal NpcNum As Long) in ModDatabase. Replace it with:
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

Now find
Sub LoadNpcs()
Replace it with:
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

Now find
Function GetNpcMaxHP(ByVal NpcNum As Long)
Replace it with:
Function GetNpcMaxHP(ByVal NpcNum As Long)

    ' Prevent subscript out of range
    If NpcNum <= 0 Or NpcNum > MAX_NPCS Then
        GetNpcMaxHP = 0
        Exit Function
    End If
   
    GetNpcMaxHP = Npc(NpcNum).MaxHP
End Function


That is IT! :-) Hoorah. I think you have to delete your NPCs but whatever! It works. Haha! :-D



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info