Mirage Source

Free ORPG making software.
It is currently Thu Mar 28, 2024 6:16 pm

All times are UTC




Post new topic Reply to topic  [ 1362 posts ]  Go to page 1, 2, 3, 4, 5 ... 55  Next
Author Message
PostPosted: Thu Oct 01, 2009 12:42 am 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
Currently, the GameAI sub is triggered using a timer on the server which is set to run every 4 seconds. As some of you know I am creating a text-based mud game. The problem here is that if there are 3 monsters in the same room, all 3 monsters will attack you at the same time every 4 seconds.
What I want to do is add a timer to the individual room NPC (Known as MapNPC() on normal MS engines), which works using GetTickCount. This means that when the NPC dies, the timer is reset for that room NPC until they respawn.
Hopefully, this will stop NPCs from attacking all at the same time, and also allow me to set different attack intervals for different monsters :)

I'm not familiar with how GetTickCount timers work, but I'm sure I can use it to my advantage if it was to be explained.


Top
 Profile  
 
PostPosted: Thu Oct 01, 2009 12:46 am 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Xlithan wrote:
Currently, the GameAI sub is triggered using a timer on the server which is set to run every 4 seconds. As some of you know I am creating a text-based mud game. The problem here is that if there are 3 monsters in the same room, all 3 monsters will attack you at the same time every 4 seconds.
What I want to do is add a timer to the individual room NPC (Known as MapNPC() on normal MS engines), which works using GetTickCount. This means that when the NPC dies, the timer is reset for that room NPC until they respawn.
Hopefully, this will stop NPCs from attacking all at the same time, and also allow me to set different attack intervals for different monsters :)

I'm not familiar with how GetTickCount timers work, but I'm sure I can use it to my advantage if it was to be explained.


They shouldn't all be attacking at the same time >_>; Each MapNpc has it's own attack timer.

_________________
Quote:
Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?


Image


Top
 Profile  
 
PostPosted: Thu Oct 01, 2009 1:12 am 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
I'm using Mirage Source 3.0.3


Top
 Profile  
 
PostPosted: Thu Oct 01, 2009 1:19 am 
Offline
Pro
User avatar

Joined: Wed Sep 20, 2006 1:06 pm
Posts: 368
Location: UK
Google Talk: steve.bluez@googlemail.com
Here's my code:

Code:
Public Sub GameAI()


Dim i         As Long
Dim x         As Long
Dim y         As Long
Dim n         As Long
Dim x1        As Long
Dim y1        As Long
Dim TickCount As Long

Dim Damage    As Long
Dim DistanceX As Long
Dim DistanceY As Long
Dim NpcNum    As Long
Dim Target    As Long
Dim DidWalk   As Boolean
    For y = 1 To MAX_ROOMS
            TickCount = GetTickCount
            For x = 1 To MAX_ROOM_NPCS
                NpcNum = RoomNpc(y, x).Num
                ' /////////////////////////////////////////
                ' // This is used for ATTACKING ON SIGHT //
                ' /////////////////////////////////////////
                ' Make sure theres a npc with the map
                    If NpcNum > 0 Then
                        ' If the npc is a attack on sight, search for a player on the Room
                        If Npc(NpcNum).Behavior = NPC_BEHAVIOR_ATTACKONSIGHT Or Npc(NpcNum).Behavior = NPC_BEHAVIOR_GUARD Then
                            For i = 1 To MAX_PLAYERS
                                If IsPlaying(i) Then
                                    If GetPlayerRoom(i) = y Then
                                        If RoomNpc(y, x).Target = 0 Then
                                            If Npc(NpcNum).Behavior = NPC_BEHAVIOR_ATTACKONSIGHT Or GetPlayerPK(i) = YES Then
                                                If LenB(Trim$(Npc(NpcNum).AttackSay)) Then
                                                    PlayerMsg i, "A " & Trim$(Npc(NpcNum).Name) & " says, '" & Trim$(Npc(NpcNum).AttackSay) & "' to you."
                                                End If
                                                RoomNpc(y, x).Target = i
                                            End If
                                        End If
                                    End If
                                End If
                            Next i
                        End If
                    End If
                ' /////////////////////////////////////////////
                ' // This is used for npcs to attack players //
                ' /////////////////////////////////////////////
                ' Make sure theres a npc with the Room
                    If NpcNum > 0 Then
                       
                        Target = RoomNpc(y, x).Target
                        ' Check if the npc can attack the targeted player player
                        If Target > 0 Then
                            ' Is the target playing and on the same Room?
                            If IsPlaying(Target) And GetPlayerRoom(Target) = y Then
                                ' Can the npc attack the player?
                                If CanNpcAttackPlayer(x, Target) Then
                                    If Not CanPlayerBlockHit(Target) Then
                                        Damage = Npc(NpcNum).STR - GetPlayerProtection(Target)
                                        If Damage > 0 Then
                                            NpcAttackPlayer x, Target, Damage
                                        Else 'NOT DAMAGE...
                                            PlayerMsg Target, "The " & Trim$(Npc(NpcNum).Name) & "'s hit didn't even phase you!"
                                        End If
                                    Else 'NOT NOT...
                                        PlayerMsg Target, "Your " & Trim$(Item(GetPlayerInvItemNum(Target, GetPlayerShieldSlot(Target))).Name) & " blocks the " & Trim$(Npc(NpcNum).Name) & "'s hit!"
                                    End If
                                End If
                            Else 'NOT ISPLAYING(TARGET)...
                                ' Player left Room or game, set target to 0
                                RoomNpc(y, x).Target = 0
                            End If
                        End If
                    End If
                ' ////////////////////////////////////////////
                ' // This is used for regenerating NPC's HP //
                ' ////////////////////////////////////////////
                ' Check to see if we want to regen some of the npc's hp
                With RoomNpc(y, x)
                    If .Num > 0 Then
                        If TickCount > GiveNPCHPTimer + 6000 Then
                            If .HP > 0 Then
                                .HP = .HP + GetNpcHPRegen(NpcNum)
                                ' Check if they have more then they should and if so just set it to max
                                If .HP > GetNpcMaxHP(NpcNum) Then
                                    .HP = GetNpcMaxHP(NpcNum)
                                End If
                            End If
                        End If
                    End If
                End With 'RoomNpc(y, x)
                ' //////////////////////////////////////
                ' // This is used for spawning an NPC //
                ' //////////////////////////////////////
                ' Check if we are supposed to spawn an npc or not
                If RoomNpc(y, x).Num = 0 Then
                    If Room(y).Npc(x) > 0 Then
                        If TickCount > RoomNpc(y, x).SpawnWait + (Npc(Room(y).Npc(x)).SpawnSecs * 1000) Then
                            SpawnNpc x, y
                        End If
                    End If
                End If
            Next x
        DoEvents
    Next y
    ' Make sure we reset the timer for npc hp regeneration
    If GetTickCount > GiveNPCHPTimer + 6000 Then
        GiveNPCHPTimer = GetTickCount
    End If
    ' Make sure we reset the timer for door closing
    If GetTickCount > KeyTimer + 15000 Then
        KeyTimer = GetTickCount
    End If

End Sub



Code:
Public Function CanNpcAttackPlayer(ByVal RoomNpcNum As Long, _
                                   ByVal Index As Long) As Boolean


Dim RoomNum As Long
Dim NpcNum As Long

    CanNpcAttackPlayer = False
    ' Check for subscript out of range
    If RoomNpcNum <= 0 Or RoomNpcNum > MAX_ROOM_NPCS Or IsPlaying(Index) = False Then
        Exit Function
    End If
    ' Check for subscript out of range
    If RoomNpc(GetPlayerRoom(Index), RoomNpcNum).Num <= 0 Then
        Exit Function
    End If
    RoomNum = GetPlayerRoom(Index)
    NpcNum = RoomNpc(RoomNum, RoomNpcNum).Num
    ' Make sure the npc isn't already dead
    If RoomNpc(RoomNum, RoomNpcNum).HP <= 0 Then
        Exit Function
    End If
    ' Make sure npcs dont attack more then once a second
    If GetTickCount < RoomNpc(RoomNum, RoomNpcNum).AttackTimer + 1000 Then
        Exit Function
    End If
    ' Make sure we dont attack the player if they are switching maps
    'If Player(Index).GettingMap = YES Then
    '    Exit Function
    'End If
    RoomNpc(RoomNum, RoomNpcNum).AttackTimer = GetTickCount
    ' Make sure they are on the same map
    If IsPlaying(Index) Then
        If NpcNum > 0 Then
            ' Check if at same coordinates
            If GetPlayerRoom(Index) = RoomNum Then
                CanNpcAttackPlayer = True
            Else 'NOT (GETPLAYERY(INDEX)...
                Exit Function
            End If
        End If
    End If

End Function


Top
 Profile  
 
PostPosted: Wed Dec 01, 2021 11:52 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatormagnetotelluricfieldmailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffuserhttp://semiasphalticflux.rusemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchuckинфоtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimate.rutemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:41 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
MPEG


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:42 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
156.8


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:43 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Bett


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:44 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Bett


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:45 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Fion


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:46 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Eras


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:48 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Remi


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:49 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Mika


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:50 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Ivan


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:51 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Chac


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:52 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Widt


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:53 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Rond


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:54 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Chri


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:55 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Atla


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:56 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Alai


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:58 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Orie


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 5:59 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Kath


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 6:00 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Bren


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 6:01 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Stou


Top
 Profile  
 
PostPosted: Fri Jan 21, 2022 6:02 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Erne


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1362 posts ]  Go to page 1, 2, 3, 4, 5 ... 55  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group