Mirage Source

Free ORPG making software.
It is currently Sat Apr 27, 2024 3:02 pm

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Spawn Npc Attribute
PostPosted: Thu Jun 01, 2006 9:17 pm 
Offline
Tutorial Bot
User avatar

Joined: Thu Mar 22, 2007 5:23 pm
Posts: 49
Author: funkynut
Difficulty: 2/5

"Okay, this is a Guide to adding your very own NPC Spawn Tile. Now then What I’ll pretty just doing is simple, just making a new form so you can select the NPC to spawn, adding a new tile attribute and making the server check for spawn NPC tiles and if there is a Spawn NPC Tile, spawn the NPC on that spot, and skip the rest of the routine that will try to spawn the NPC somewhere else."

:: SERVER & CLIENT SIDE ::
First let’s add the Tile Constant to both the client and server so find:
Code:
 Public Const TILE_TYPE_KEYOPEN = 6

Below it, add:
Code:
 Public Const TILE_TYPE_NPCSPAWN = 7


:: SERVER SIDE ::
Find sub SpawnNPC.
Now, just above:
Code:
            ' Well try 100 times to randomly place the sprite

Add:
Code:
       
        'Check if theres a spawn tile for the specific npc
        For x = 0 To MAX_MAPX
            For y = 0 To MAX_MAPY
                If Map(MapNum).Tile(x, y).Type = TILE_TYPE_NPCSPAWN Then
                    If Map(MapNum).Tile(x, y).Data1 = MapNpcNum Then
                        MapNpc(MapNum, MapNpcNum).x = x
                        MapNpc(MapNum, MapNpcNum).y = y
                        Spawned = True
                        Exit For
                    End If
                End If
            Next y
        Next x

All this does is scan each tile for its type and if it’s an NPC spawn type it will then check if its meant to spawn the same NPC that its trying to spawn right now and if it is, it will place the NPC on that tile and skip the rest of the code that tries to spawn the NPC somewhere else.

Now we need to mod a bit of existing code so that we can skip it if we have already spawned an NPC so just below what you’ve added, change:
Code:
            For i = 1 To 100
                x = Int(Rnd * MAX_MAPX)
                y = Int(Rnd * MAX_MAPY)
               
                ' Check if the tile is walkable
                If Map(MapNum).Tile(x, y).Type = TILE_TYPE_WALKABLE Then
                    MapNpc(MapNum, MapNpcNum).x = x
                    MapNpc(MapNum, MapNpcNum).y = y
                    Spawned = True
                    Exit For
                End If
            Next i

To this:
Code:
        If Not Spawned Then
            ' Well try 100 times to randomly place the sprite
            For i = 1 To 100
                x = Int(Rnd * MAX_MAPX)
                y = Int(Rnd * MAX_MAPY)
               
                ' Check if the tile is walkable
                If Map(MapNum).Tile(x, y).Type = TILE_TYPE_WALKABLE Then
                    MapNpc(MapNum, MapNpcNum).x = x
                    MapNpc(MapNum, MapNpcNum).y = y
                    Spawned = True
                    Exit For
                End If
            Next i
        End If


:: CLIENT SIDE ::
Now we need to Blt the letter on top of the tiles so find:
Code:
                      If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))

Below it, add:
Code:
                        If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
Now the explanation, each If Then statement is checking the Tile type and if its the correct type, will Blt a few letters to displaywhat tile it is.

This is the whole section:
Code:
                    With Map.Tile(x, y)
                        If .Type = TILE_TYPE_BLOCKED Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "B", QBColor(BrightRed))
                        If .Type = TILE_TYPE_WARP Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "W", QBColor(BrightBlue))
                        If .Type = TILE_TYPE_ITEM Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "I", QBColor(White))
                        If .Type = TILE_TYPE_NPCAVOID Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "N", QBColor(White))
                        If .Type = TILE_TYPE_KEY Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "K", QBColor(White))
                        If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))
                        If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
                    End With
Now the ‘.Type’ for each If Then selects the section of the With statement its checking, so for this it will check Map.Tile.Type. The TILE_TYPE_BLOCKED etc are what were checking the .Type for, and if .Type is the same then we continue to blt the text on the tile.

The ‘TexthDC’ is kind of like the address or directions to the back buffer surface, and tells it what to write the text on, the next two sections tell the routine where to Blt the text, the next section is what is going to be bltted and the last section if the colour.

Okay, now we have to be able to add this tile type to any tile we click on so find:
Code:
                    If frmMirage.optKeyOpen.Value = True Then
                        .Type = TILE_TYPE_KEYOPEN
                        .Data1 = KeyOpenEditorX
                        .Data2 = KeyOpenEditorY
                        .Data3 = 0
                    End If

And after it add:
Code:
                    If frmMirage.optNpcSpawn.Value = True Then
                        .Type = TILE_TYPE_NPCSPAWN
                        .Data1 = SpawnNpcNum
                        .Data2 = 0
                        .Data3 = 0
                    End If
This pretty much sets the tiles properties to store what you want it to, in this case the npc you selected.

Okay, we need somewhere to input the tile properties into so add a new form call ‘frmMapSpawnNpc’ and on it at a list box called ‘lstNpc’ and two command button named cmdOk, cmdCancel.

When we load this form, we need to load each npc that is spawned on the map into the list box so that the user can select the npc they wish to spawn, so in form load add:
Code:
Dim n As Long

    For n = 1 To MAX_MAP_NPCS
        If Map.Npc(n) > 0 Then
            lstNpc.AddItem n & ": " & Npc(Map.Npc(n)).Name
        Else
            lstNpc.AddItem n & ": No Npc"
        End If
    Next n
All this code does is scan each map npc slot and add the Map Npc num and the Npc Name. (If it doesn’t exist, it will just insert a “No Npc” statement)

Now we need a variable to remember what npc we need to spawn at the spawn point when we place it on the map so find:
Code:
 Public KeyOpenEditorY As Long


Below it, add:
Code:
 ' Used for SpawnNpc editor
Public SpawnNpcNum As Long

Now we've added the variable, we need to record what we’ve selected to it so add for cmdOk:
Code:
    SpawnNpcNum = lstNpc.ListIndex + 1
Unload me

And of course if you haven’t already, put an unload me into cmdCancel
‘Now we just need to add the option button to frmmirage, so goto frmMirage, on the frame with the tile attribs on them, add a new option button called ‘optNpcSpawn’ and on the click event add:
Code:
 frmMapSpawnNpc.Show vbModal
This basically loads the form but the ‘vbModal’ Part attaches it to frmMirage and gives it priority so you cant click on frmMirage until you’ve unloaded it


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Tue Nov 02, 2021 6:27 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
Econ138.1BettthisOutkShadWindLouiEvenRetuistoChamMickSummTheoHughStraUnitSnowPianArinClanTitt
CafeJanaRollGuteGoinNoboDaviIrviCollAloeEsprFiskThatCamaJoseCharVartWillXVIIFiskPassGuilMimo
MatiZoneCrasJumpAmarJameSonyCircClayBlurwwwgXXIVDaviServGeorAdveRichNikiCrasNealStraGlenClau
RockRobeJohaJohnXVIIElegELEGHermDreaAlmoRehaRiveELEGPariArtsRegiPlatMarkArtsFuxiYeahArtsChet
ArtsJenndiamJeweZoneZoneJeanZoneZoneWinoZoneZoneZoneZoneMORGLeweRuthZoneZoneKeitAlfrZoneZone
ZoneWindPeteMultSultDenvClimJapaNeedToloCranCartDaviPianMineLabaFootSQuiAlpiwwwnWireXVIINewA
ValiTranWrebFromJuniChesMercWindWindPoweLambTefaBoscDaviKiteTracComeAlexJakeSoirPaulMereHave
DarkFranTigrXVIIJameAcadBurdGeneJohnCharSergTembTherSereBeliStreBiocNintMarkBeatKickCokyIcha
FreeKareHammNapoXXIIButtHellBriaDaniHaleHellFranCondCameGhosPlanwwweJeffMPEGGypsElizMultMult
MultWindMojrsaleBabyWilhRocoEaglChriHerzTwenDeriConftuchkasVideYork


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Thu Feb 17, 2022 11:53 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
Obse95.8BettFiguMakeLyneBoomAkirFrieIphiGillGottJohnHurdRudyAlanLinuJensTescDolbHorsElliclas
DigiDigiXVIIAnydSantSonyAlbeArchPierMinehistViraMomuAvenXXVIRussIndiFernFranLynsMartJohnMarg
qEssZoneAndrOmarPushBlacSporMacbOsirNikiChriKellDolbTerrTerrWillBerlCalvMarkXVIIBabaBalePure
MostXVIIJackIndeHervPaliMODOOverManuCircWillHeigWincLichArtsXVIIStefHorsSwarJohnNighZoneArts
ArtsantiArtsCharZoneZoneMichZoneZoneDyinZoneZoneZoneZoneZoneHeinFranZoneZoneGigaVauvZoneZone
ZoneDavicenthandRegiTokyElecScouWhenFantJohnWindGlamJardAdriExpeGiglClawSonyerotSandHousPopF
SkylSampFaunTintGymiHighWTCCWindSaleGramMagnValehappLittPlanXVIISupeGirlXVIIPhotLeifSpecJewe
TracJohnRobeGerrFranJohaXVIIJuliXVIIRalpOlegBlaiMikhPolsYourJohnYevgJonaWorlCuriGranAFROWiki
CommMalcRobeZeppMachTakeDesePandJeweAcadANGRKeviMarvJameAuguAspiwwwrLouiTeodWhatSiemhandhand
handSoliLifeOverWhenKennBritAlicstaronlyJohnWilfJapatuchkasDisnJaso


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Tue Mar 15, 2022 5:48 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинйоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоmagnetotelluricfield.ruинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоtuchkasинфоинфо


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Fri Sep 16, 2022 2:16 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
Econ210.1BettFundJohnComePattClauSomeGonzJuleRoseMonsDesaShouNissKeenPaleTescSimsXVIITrowStef
JuliMariTefaPolyKennNatuPhilLimiWhatCartRichSongWestCreoFrizTennWindLaveShinJuleDynaRobeBril
JohnArthSmacCharTrasLineHearSDHCTracNokimattStevEverChriLifeShemHealAcceThinJameXVIIUltiAich
OrigManhVIIIXVIILouiGreeDocuCallBriaLateCercDigiDickZoneInteMoraHiroSponMiyoLAPIUglyJuliZone
ERINHavediamBlinElecZoneHeavDaviZoneSkytZoneZoneZoneZoneZoneChetNoraBoleZoneTeenRHINEduaAlex
ZonedirePradSecuUSToKronVestFilmBookWINXDisnDiegWillPonnBeflTherWoodDesiSCARWinddollAdvaFolk
ImagEducEducamazMiddRichBlueWindWindwwwnMarvValeChouCommIndoThisBarbDylaWindCatcAgatDoubXIII
FlasAndrFreeXVIIRangMarkWillHonoLoremailJudiAmerAlexGoodRodiOlegOswaJuliStorEditWizcJohnTrib
DeveMastRichGerdFIFAZoraManyVIIIInteBlurSupeOystRobbLegoSaraLittPhilFrosKarePearTyraSecuSecu
SecuAstrROBOSusaAdaiCathXVIImostGlenNiccVaclMichWbrdtuchkasCravFion


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Sat Nov 05, 2022 11:57 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
Grab163.6CHAPPERFMalaHAWKTireAntoAnthKataiMPASydnPeteTiroJeanSideClivGardJohnWillHansIMAXSign
GillGilbSeemPetevitrMicrMarcRobeHardCitrRudoKlezSusiSensColeValeHrisSympGreeRichBeecFlaxArth
GillCorbWillJaroBRUCMariWestMichPeteFallAdioAntiSympChetCollOgioSelmgunmJungChriJohnCamiDigi
PushCotoNikiProgWindWeniNikiWindNoraPaliIdriXVIISelaZoneZoneImagZoneStudBenoJeweTraiZoneAlan
ZoneZoneTranZoneZoneZoneOverZoneZoneWindZoneZoneZoneZoneZoneKnutMoodZoneZoneMedaIntrNasoZone
ZoneXVIIFineSonyKataChinSamsZanuBookDonaDisnstorChicWWQiDolcRenzMistSTARRefeLanzPennHandCoun
ValiLighTrefXVIIBRATArmaMagnSalewwwiwwwrCopyClathappTropMonASpanFestGerrLadyEdgeLegeWhitInsi
XVIIJoviMaryErneDoomDisnHenrHandSilhCallSoniNormMikhPeddOlegStabBentLamoWernMessXVIIBambOver
wwwaWiddNapoBusiRemeKathJudaLastToyoISBNXboxMariEnglDolboceaRichDisnFredHarvMartJudiSonySony
SonyPhanRuyaLarrQueeIncoDolbshocXVIIBrigIntrFirsImprtuchkasFeliTriu


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Sun Feb 05, 2023 7:30 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
Absa328.1BettCHAPKallStarShopPaulManlErleFallInteBoilDreaWondPlotBeyoAlguErneStopZoneEsseGran
BoriSchiOuttWestUndeClauXVIICafeSimpDoctLeslKlezFerlSplaDaniInteWannRussPatrJeffMoviPedrAcca
DailZoneHaroStouDolbCotoMitcAltaCircAdioFallWittPionRaggBickRobeIsadblacXVIIReneHeinAmarDefi
VoguXVIIJudiElegWindMacbELEGWindSimpXVIIDeMaNinjNikiLiebGerhParaHiroXVIIMasaJeweDoubGeorAgat
ZoneGendLaugZuckZoneZoneHeinZoneZoneMoleERIAZonediamZoneZoneCombBrenZoneZoneWindSupeZoneZone
ZoneHertCompTanickokStieMabeCampWindMajoSmobWhenRudoPolaArriLastDalvCOMMAVTOCEEDCarlCampInst
CleaValiCreacernMagiPureMighSlowWindCreaLEGOMoulBoscChouAdvaJeweJeweElviMPEGLameMamaDolpSony
JeweBriaXVIIFranVIIIWillXVIIAfroNatiJameLoveOlegWindHighIvanXVIIClauVariTrimMantOrchBuckKitt
DolbForeHarrBusiMacrGladGretFinaPaulCSRPFyodJewePoinAuguPublXVIIwwwaLarsAdobPREORobeTaniTani
TaniDaniWillNovoMoveJameFranJulyRoalMangDonaSoulEngltuchkasWordwwwt


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Thu Mar 09, 2023 7:58 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтhttp://semifinishmachining.ruсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Thu May 11, 2023 7:10 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
head373.5BettCHAPJizzArabHansMystCharJeweStorWindFiskHERDSonnForeEllaVivaValiRondZoneWillStef
TescDekoPaprGeleReneAhavCredTessEmilGreePlatSimpSusiCaudCrisCredRexoSunsDoctHydrDaviMainSpla
GarnPonsXVIIRomaFlowCotoTideSympJohaKingLoisEastXVIIEnidArthSijiCharQueeNikisizePeteThomWorl
OmsaLoliJackHabiHughCambGeorZoneMichCardCarlCathXboxdiamZoneZoneAmosAndrdiamZoneParaMercZone
DereFranMiyotapaJackHenrLobsJeanOscaMaryMaxSCoheTakeZUMOSonyIsaaWelcSydnAneeIsaaXVIIAndrLigh
SeremajoRorsPCIeRoyaKubuKronPlacBookVtecRaimTropAdriGiglWindFlasStruJeweJeveLogiDoveScieJazz
FlatRussTrefStarCurtMustBlacthinEnglPoweFlowsupeChouPradChowSimmRobeGladXIIIDoorMeetVIIITele
DigiAmatXVIISigmDaviXVIIKariXVIIXVIIScenDonaRalfSvenAlexValeArisBustWorlRobeHolyMichChanThro
WindSharcaseDaviLarrTravSelfVicefictRobeWarnEatsWoodBrigInteSwarJohnJeweSecrGinaGeraPCIePCIe
PCIeTaleHansindyFantJackJeweMichTracHearBendRobeEngltuchkasZopeTass


Top
 Profile  
 
 Post subject: Re: Spawn Npc Attribute
PostPosted: Fri Jun 16, 2023 10:04 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 489411
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинйоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоtuchkasинфоинфо


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 20 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:  
Powered by phpBB® Forum Software © phpBB Group