Mirage Source
http://www.miragesource.net/forums/

[Feature] Random blood
http://www.miragesource.net/forums/viewtopic.php?f=183&t=5620
Page 1 of 39

Author:  GIAKEN [ Wed May 20, 2009 1:32 am ]
Post subject:  [Feature] Random blood

Difficulty: 1/5 - Copypasta mmm

Introduction: This tutorial will add some random blood splatters to your game when you attack NPCs / players.

Now, lets get started...

SERVER-SIDE

SPOILER: (click to show)
First thing, add this to the bottom of the "Public Enum ServerPackets":

Code:
SBloodSplatter


Now add this in modTypes:

Code:
Public TempTile() As TempTileRec

Type BloodRec
    Active As Boolean
    x As Long
    y As Long
    Pic As Long
    Timer As Currency
End Type

Type TempMapRec
    Blood(1 To 50) As BloodRec
End Type


Now under:

Code:
    ReDim MapCache(1 To MAX_MAPS) As String


Add this:

Code:
    ReDim TempTile(1 To MAX_MAPS) As TempTileRec


Find this:

Code:
Public Sub PlayerWarp(ByVal Index As Long, ByVal MapNum As Long, ByVal x As Long, ByVal y As Long)
Dim OldMap As Long
Dim LoopI As Long

    ' Check for subscript out of range
    If Not IsPlaying(Index) Or MapNum <= 0 Or MapNum > MAX_MAPS Then Exit Sub


Add this under it:

Code:
'sending the blood splatter packet without any data will tell the client to clear
    SendDataTo Index, SBloodSplatter & END_CHAR
   
    For LoopI = 1 To UBound(TempMap(MapNum).Blood)
        If TempMap(MapNum).Blood(LoopI).Active Then
            With TempMap(MapNum).Blood(LoopI)
                SendDataTo Index, SBloodSplatter & SEP_CHAR & LoopI & SEP_CHAR & .Active & SEP_CHAR & .x & SEP_CHAR & .y & SEP_CHAR & .Pic & END_CHAR
            End With
        End If
    Next


Add this Random function to modGameLogic or whatever:

Code:
Function Random(Lowerbound As Integer, Upperbound As Integer) As Integer
    Random = Int((Upperbound - Lowerbound + 1) * Rnd) + Lowerbound
End Function


Now add this Sub in modGameLogic or wherever:

Code:
Public Sub SendBlood(ByVal Map As Long, ByVal Target As Long, ByVal TargetType As Long)
Dim LoopI As Long

    ' 50% chance blood spawns
    'If Random(1, 2) = 2 Then
   
        For LoopI = 1 To UBound(TempMap(Map).Blood)
            If Not TempMap(Map).Blood(LoopI).Active Then
                With TempMap(Map).Blood(LoopI)
                    .Pic = Random(0, 5)
                   
                    If TargetType = TARGET_TYPE_NPC Then
                        If Random(1, 2) = 1 Then
                            .x = (MapNpc(Map, Target).x * 32) + Random(0, 20)
                        Else
                            .x = (MapNpc(Map, Target).x * 32) - Random(0, 20)
                        End If
                        If Random(1, 2) = 2 Then
                            .y = (MapNpc(Map, Target).y * 32) + Random(0, 20)
                        Else
                            .y = (MapNpc(Map, Target).y * 32) - Random(0, 20)
                        End If
                    ElseIf TargetType = TARGET_TYPE_PLAYER Then
                        If IsPlaying(Target) Then
                            If Random(1, 2) = 1 Then
                                .x = (GetPlayerX(Target) * 32) + Random(0, 20)
                            Else
                                .x = (GetPlayerX(Target) * 32) - Random(0, 20)
                            End If
                            If Random(1, 2) = 2 Then
                                .y = (GetPlayerY(Target) * 32) + Random(0, 20)
                            Else
                                .y = (GetPlayerY(Target) * 32) - Random(0, 20)
                            End If
                        End If
                    End If
                   
                    .Timer = GetTickCountNew + 30000
                    .Active = True
                   
                    SendDataToMap Map, SBloodSplatter & SEP_CHAR & LoopI & SEP_CHAR & .Active & SEP_CHAR & .x & SEP_CHAR & .y & SEP_CHAR & .Pic & END_CHAR
                   
                End With
                Exit For
            End If
        Next
   
    'End If
End Sub


Now find this in Sub AttackNpc:

Code:
' Check for weapon
    n = 0
    If GetPlayerEquipmentSlot(Attacker, Weapon) > 0 Then
        n = GetPlayerInvItemNum(Attacker, GetPlayerEquipmentSlot(Attacker, Weapon))
    End If


Under add this:

Code:
SendBlood GetPlayerMap(Attacker), MapNpcNum, TARGET_TYPE_NPC


Find this in Sub AttackPlayer:

Code:
' reduce dur. on victims equipment
    Call DamageEquipment(Victim, Armor)
    Call DamageEquipment(Victim, Helmet)


Under add:

Code:
SendBlood GetPlayerMap(Victim), Victim, TARGET_TYPE_PLAYER


Find:

Code:
Do While ServerOnline
        Tick = GetTickCountNew


Under add:

Code:
For x = 1 To MAX_MAPS
            For y = 1 To UBound(TempMap(x).Blood)
                If TempMap(x).Blood(y).Active Then
                    With TempMap(x).Blood(y)
                        If .Timer < GetTickCountNew Then
                            .Pic = 0
                            .x = 0
                            .y = 0
                            .Active = False
                            SendDataToMap x, SBloodSplatter & SEP_CHAR & y & SEP_CHAR & .Active & SEP_CHAR & .x & SEP_CHAR & .y & SEP_CHAR & .Pic & END_CHAR
                        End If
                    End With
                End If
            Next
        Next


And now ~.............

CLIENT-SIDE

SPOILER: (click to show)
First thing, add this to the bottom of the "Public Enum ServerPackets":

Code:
SBloodSplatter


Now add this in modTypes:

Code:
Public Blood(1 To 50) As BloodRec

Type BloodRec
    Active As Boolean
    X As Long
    Y As Long
    Pic As Long
End Type


At the top of modDirectDraw7 add this:

Code:
Public DDS_Blood As DirectDrawSurface7
Public DDSD_Blood As DDSURFACEDESC2


Then in Sub InitSurfaces add this:

Code:
InitDDSurf "blood", DDSD_Blood, DDS_Blood


Now add this sub to modDirectDraw or wherever:

Code:
Public Sub DrawBloods()
Dim LoopI As Long
Dim rec As DxVBLib.RECT

    For LoopI = 1 To UBound(Blood)
        If Blood(LoopI).Active Then
            With Blood(LoopI)
                rec = Get_RECT(.Pic * PIC_Y)
                DDS_BackBuffer.BltFast .X, .Y, DDS_Blood, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
            End With
        End If
    Next

End Sub


Now find:

Code:
BltMapTiles


Under add:

Code:
If BloodHighIndex > 0 Then DrawBloods


Now at the bottom of modHandleData add:

Code:
Private Sub HandleBloodSplatter(ByRef Parse() As String)

    If UBound(Parse) < 1 Then
        Dim LoopI As Long
        For LoopI = 1 To UBound(Blood)
            ZeroMemory ByVal VarPtr(Blood(LoopI)), LenB(Blood(LoopI))
        Next
        Exit Sub
    End If
   
    If CBool(Parse(2)) = True Then
        BloodHighIndex = BloodHighIndex + 1
        If BloodHighIndex >= UBound(Blood) Then BloodHighIndex = UBound(Blood)
    Else
        BloodHighIndex = BloodHighIndex - 1
        If BloodHighIndex < 1 Then BloodHighIndex = 0
    End If
   
    With Blood(Val(Parse(1)))
        .Active = CBool(Parse(2))
        .X = Val(Parse(3))
        .Y = Val(Parse(4))
        .Pic = Val(Parse(5))
    End With
End Sub


Now find:

Code:
Select Case Parse(0)


Under add:

Code:
Case SBloodSplatter
            HandleBloodSplatter Parse


Finally in modGlobals add this to the top:

Code:
Public BloodHighIndex As Long


And that SHOULD be it...I might have left something out...

-----------------------------------

Oh yeah, and in your gfx folder add this:

CREDITS GO TO BLODYAVENGER IF YOU USE.
STYLE IS FOR 16-BIT GAMES, LIKE FF1.

http://mayhem.auburnflame.com/blood.bmp

Customizing and explanations:

With that blood.bmp, there are 6 different bloods able to be selected. If you want to change that, simply change this line in server-side:

Code:
.Pic = Random(0, 5)


That randomly selects between 6 blood pictures.

If you want to control if blood disappears faster, change this in the server in Sub SendBlood:

Code:
.Timer = GetTickCountNew + 30000


That tells the server to get rid of the blood in 30 seconds.

If you want to make a chance the blood appears, get rid of the comment on the second line here in Sub SendBlood:

Code:
' 50% chance blood spawns
        'If Random(1, 2) = 2 Then


THAT SHOULD BE ALL! I might have missed something. This was made on my engine made from MS4...so make sure you test with MS4 and post here, please.

Author:  Nean [ Wed May 20, 2009 1:36 am ]
Post subject:  Re: [Feature] Random blood

Looks awesome man. Great tut.

Author:  GIAKEN [ Wed May 20, 2009 1:39 am ]
Post subject:  Re: [Feature] Random blood

Oh yeah, here's an example (giving another hint here of another possible tutorial)

Image

Author:  Robin [ Sat May 30, 2009 5:15 pm ]
Post subject:  Re: [Feature] Random blood

Pretty cool. Nothing I can't do, but I'm sure many people find it useful.

+5 rating.

Author:  wanai [ Wed Dec 01, 2021 8:58 am ]
Post subject:  Re: [Feature] Random blood

audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatormagnetotelluricfieldmailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffuserhttp://semiasphalticflux.rusemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchuckинфоtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimate.rutemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting

Author:  wanai [ Tue Jan 04, 2022 11:53 pm ]
Post subject:  Re: [Feature] Random blood

Econ

Author:  wanai [ Tue Jan 04, 2022 11:54 pm ]
Post subject:  Re: [Feature] Random blood

95

Author:  wanai [ Tue Jan 04, 2022 11:56 pm ]
Post subject:  Re: [Feature] Random blood

Bett

Author:  wanai [ Tue Jan 04, 2022 11:57 pm ]
Post subject:  Re: [Feature] Random blood

Bett

Author:  wanai [ Tue Jan 04, 2022 11:58 pm ]
Post subject:  Re: [Feature] Random blood

Clif

Author:  wanai [ Tue Jan 04, 2022 11:59 pm ]
Post subject:  Re: [Feature] Random blood

Dean

Author:  wanai [ Wed Jan 05, 2022 12:00 am ]
Post subject:  Re: [Feature] Random blood

Mich

Author:  wanai [ Wed Jan 05, 2022 12:01 am ]
Post subject:  Re: [Feature] Random blood

Harl

Author:  wanai [ Wed Jan 05, 2022 12:02 am ]
Post subject:  Re: [Feature] Random blood

Esta

Author:  wanai [ Wed Jan 05, 2022 12:03 am ]
Post subject:  Re: [Feature] Random blood

Mere

Author:  wanai [ Wed Jan 05, 2022 12:05 am ]
Post subject:  Re: [Feature] Random blood

Fiel

Author:  wanai [ Wed Jan 05, 2022 12:06 am ]
Post subject:  Re: [Feature] Random blood

Clar

Author:  wanai [ Wed Jan 05, 2022 12:07 am ]
Post subject:  Re: [Feature] Random blood

Barb

Author:  wanai [ Wed Jan 05, 2022 12:08 am ]
Post subject:  Re: [Feature] Random blood

Colu

Author:  wanai [ Wed Jan 05, 2022 12:09 am ]
Post subject:  Re: [Feature] Random blood

Stok

Author:  wanai [ Wed Jan 05, 2022 12:10 am ]
Post subject:  Re: [Feature] Random blood

Kona

Author:  wanai [ Wed Jan 05, 2022 12:11 am ]
Post subject:  Re: [Feature] Random blood

Myst

Author:  wanai [ Wed Jan 05, 2022 12:12 am ]
Post subject:  Re: [Feature] Random blood

Rond

Author:  wanai [ Wed Jan 05, 2022 12:14 am ]
Post subject:  Re: [Feature] Random blood

Bill

Author:  wanai [ Wed Jan 05, 2022 12:15 am ]
Post subject:  Re: [Feature] Random blood

Hard

Page 1 of 39 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/