Mirage Source

Free ORPG making software.
It is currently Wed Jan 28, 2026 9:19 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Shorten CanMove
PostPosted: Mon Jun 30, 2008 7:08 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
This isn't really an optimization, more of a help when changing things in the CanMove function. If you ever had to change something in the CanMove function you know that you have to change every direction - Adding this CheckDirection function - you'll only need to edit the CheckDirection.

modGameLogic
Add the following:
Code:
Function CheckDirection(ByVal Direction As Byte) As Boolean
Dim X As Long, Y As Long, i As Long

    CheckDirection = False
   
    Select Case Direction
        Case DIR_UP
            X = GetPlayerX(MyIndex)
            Y = GetPlayerY(MyIndex) - 1
        Case DIR_DOWN
            X = GetPlayerX(MyIndex)
            Y = GetPlayerY(MyIndex) + 1
        Case DIR_LEFT
            X = GetPlayerX(MyIndex) - 1
            Y = GetPlayerY(MyIndex)
        Case DIR_RIGHT
            X = GetPlayerX(MyIndex) + 1
            Y = GetPlayerY(MyIndex)
    End Select
   
    ' Check to see if the map tile is blocked or not
    If Map.Tile(X, Y).Type = TILE_TYPE_BLOCKED Then
        CheckDirection = True
        Exit Function
    End If
                               
    ' Check to see if the key door is open or not
    If Map.Tile(X, Y).Type = TILE_TYPE_KEY Then
        ' This actually checks if its open or not
        If TempTile(X, Y).DoorOpen = NO Then
            CheckDirection = True
            Exit Function
        End If
    End If
   
    ' Check to see if a player is already on that tile
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            If GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                If (GetPlayerX(i) = X) And (GetPlayerY(i) = Y) Then
                    CheckDirection = True
                    Exit Function
                End If
            End If
        End If
    Next i

    ' Check to see if a npc is already on that tile
    For i = 1 To MAX_MAP_NPCS
        If MapNpc(i).Num > 0 Then
            If (MapNpc(i).X = X) And (MapNpc(i).Y = Y) Then
                CheckDirection = True
                Exit Function
            End If
        End If
    Next i
End Function


Replace Function CanMove with the following:
Code:
Function CanMove() As Boolean
Dim i As Long, d As Long

    CanMove = True
   
    ' Make sure they aren't trying to move when they are already moving
    If Player(MyIndex).Moving <> 0 Then
        CanMove = False
        Exit Function
    End If
   
    ' Make sure they haven't just casted a spell
    If Player(MyIndex).CastedSpell = YES Then
        If GetTickCount > Player(MyIndex).AttackTimer + 1000 Then
            Player(MyIndex).CastedSpell = NO
        Else
            CanMove = False
            Exit Function
        End If
    End If
   
    d = GetPlayerDir(MyIndex)
    If DirUp Then
        Call SetPlayerDir(MyIndex, DIR_UP)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerY(MyIndex) > 0 Then
            If CheckDirection(DIR_UP) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_UP Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Up > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
           
    If DirDown Then
        Call SetPlayerDir(MyIndex, DIR_DOWN)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerY(MyIndex) < MAX_MAPY Then
            If CheckDirection(DIR_DOWN) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_DOWN Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Down > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
               
    If DirLeft Then
        Call SetPlayerDir(MyIndex, DIR_LEFT)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerX(MyIndex) > 0 Then
            If CheckDirection(DIR_LEFT) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_LEFT Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Left > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
       
    If DirRight Then
        Call SetPlayerDir(MyIndex, DIR_RIGHT)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerX(MyIndex) < MAX_MAPX Then
            If CheckDirection(DIR_RIGHT) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_RIGHT Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Right > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
End Function


If there are any problems please let me know.


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Sun Aug 24, 2008 5:36 pm 
Offline
Regular
User avatar

Joined: Sun Jun 24, 2007 2:45 am
Posts: 62
Location: Texas, USA
Work's great! Thank's.

This made it a lot eaiser to add a nice "Walk Over Anything" Admin Feature to my Admin Panel.

_________________
Image
Image


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Sun Aug 24, 2008 6:01 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Dammit. I just spent ages re-writing mine when I could have C&P this. ;-;

_________________
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  
 
 Post subject: Re: Shorten CanMove
PostPosted: Tue Nov 02, 2021 4:40 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Quan201.5CHAPReprBenoDolbSideChriXVIISidnPrayIrrecoloMoozHarrAlexXVIIPezzDeanSonapapiMichTesc
XVIIAmerStopLuigVortPlanDaviKareEastKamiSweeMattAbbrCreaAquaJuliAlexFielGillKarlBonsFranThom
AccaAlbeBarbUndeFunkLineXVIIStevCircShelHearEdgaEmilBonuDickMuccLoweRoxyWindIoanPianPeteNavo
EidoArthThomJeweJakeSelaNikiLuxoRajnXVIIWorlDeusHUSTMagiBranPrelZoneXVIIArtsWillFallZoneRobe
ZoneZoneBallZoneZoneZoneJennChetZoneChriZoneZoneZoneZoneZoneJohnPhilMCRGZoneWindRichZoneZone
ZoneBernNorbBlueTielSamsndasStieBookPottDeviConvCrocDaliMBQiVanbLineSTARPionInfiBottImpoFolk
BussValiSlinPoweSmobRelaTrefMitsWindWindGiotBorkStevPuroIamsconsXVIIRichXVIIHoteBeteSignNash
XVIIYuryPoweAlbeBornJohnPayoKareNersFranJoseEmmaLeonEverpostShadNilsHoffRamzWindLeonFOREMark
JeweEnglKiyoJapaRecoConnBLACJillPandAndrClaiFourBodhJohnJimmTormKateMuchSambPaulMandBlueBlue
BluemailOZONWillSonyAdveMariAeroCharAmatRonnLamePatrtuchkasAdobStev


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Thu Feb 17, 2022 10:06 pm 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Extr192.5CHAPReprSchaAlfrSideSimoDinoXVIIHeleLondDekoStreJohnChriJuleBridMariAndrsapeJoseTesc
EricIntrDrBrDashOuveOZONXVIIArthCrazJardWinxJoueDancPenhKateFyodGammCharGillEnigShelMorbHans
FashZongAlbeRaymCottDAIWEdwaJudsFallCircXVIIJameCarlMissXXIIRobeAdrirosyAnatXVIIVoixJohnReco
WindShelJuliElwoNikosizeRobaWindMaryXVIISoliWindNikiJudiLoveDoroSwarConfArtsIsaaCircZoneAndr
ZoneZoneStarZoneZoneZoneKareZoneZonePeacZoneZoneZoneZoneZoneToccMounZoneZonePandSideZoneZone
ZonePLEWmadeBlueRoyaElecYukoElecBookDaxtJeweWindLeifWALLBradVanbPathSTARSTARLanzWestcompkbps
WindPersTuttNikeSCRAChevMegaWindwwwnTattWinxBorkLighIntrGourPhilBrigAdvaTheramouthisDarkCoal
XVIICeciMcKiJuleXVIIMarcRoalLopeXVIIwwwsXIIIMikhSaveGreeDamiwwwmCrunThisSamuhandEdgaProdStri
SaraSchlChinMollMeteStepAlicWindClivEmerJacqMoreXVIIJeffEndlAntoJohnXVIIXVIISweeEugeBlueBlue
BlueJohnThomMotiGeorShakMusiParaMagiJillTuomJillLiketuchkasFupzwwwm


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Tue Mar 15, 2022 1:31 pm 
Offline
Mirage Source Lover

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


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Fri Sep 16, 2022 12:24 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Vrin115.3BettReflBangMohiEverWendAlexSympThomJohnSnooIronJackJereCathFranBriaWINXritaElliTesc
IntrCsarXVIIJOHASantDolbLandArchFyodAhavJeweViraLoveMatiXVIIWaltHappPelhRaymMargDesiStepXVII
GarnZoneFranRobeCotoGioAIconMacbMacbRupaWindHonkLucaTerrPonsGeorGrafElsyrnesNathDaviConcFlat
QueeAllaJohnIndeHervVentMODOHeromollCircJackWindOrlaNeveArtsLeonNoraOnlyArtsKakiAdorZoneRHIN
ArtsXVIIotheWillZoneZoneJohnZoneZoneWindZoneZoneZoneZoneZoneDaniSonyZoneZoneGigaLudoChetZone
ZoneYourcentSonyMadeGardClimWoodBookFantElviFranNiccJardAdriRuyaMistHorsMystMystApolHilltrac
ValiArroEartChirRolyCityFendGrudJessWindMagnBLADSoftPacoChowPapeDirtHenlWierSpocFlavJeweJewe
RockGreeKarlXVIINapoBernXVIIEmilInnoGunaRobeOZONGaliSonaBeliXXXIRetaUltiWorlENVYBrucHerbKeit
WindEnglRobePaulWhilVirgSummCommMumiPickClauKeviKaspTonyEoinEverSEALMehlActiWhatPlaySonySony
SonySoliShinEvanRawsRhapPictStepWillWarnGeraBernJanetuchkasLiveGhia


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Sat Nov 05, 2022 9:46 pm 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Atra128CHAPBettKoboAlekLaruPostHenrTracBigbAgaiBlueSainJeweSimoRobePaulMichXVIITaniRosaAris
SounWishKhenEricOlivLeslAndrMarcSheiArouLibeBellMannVIIIXVIIClicOscaVisaAnneViviTescJohnLove
WrigEnidLaksProlCaroFemmFantTallELEGSelaFourSelaPeteHarrLloyPaliELEGEricBollMariSeveCamiXVII
EtniRomaTraiChocCircGIUDCircHansAwakCircXVIIJohnCircKarlZoneSharZoneXVIISupeHughToybZoneIntr
ZoneZonePadaZoneZoneSohaMachZoneZoneXVIIZoneZoneZoneMariZoneGranRobeZoneZoneZoneDreaZoneZone
ZoneChipKennTRASStanBasiTermCataEverSupeDennAskeSadiBeflGiglSomeProtBELLInfiUSSRPariveryCoun
CleaSpirVictKotlBlanBontLiveWindWindHuebYamaRedmUnitWhitRolfDaniAgatRobeBlueDraiJackDemaRobe
JohnversEditVictStefMicrEmileditRainPhedVivaHansRichJoseCariSimoVortHughMichGoldWelcMGMTSimp
WindBrucEnCEEnjoGabrBonnDrWeFedePaulJohnGipsDianFEARmixuElizSigmNyloBrinGinaHenrtermTRASTRAS
TRASStatBonuCrosCarmScorBillRemoDumbLifeKareHelpMonituchkasEuroJewe


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Sun Feb 05, 2023 5:43 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
dark263BettCHAPArthMaryModeXIIIGallMeniBHenEverDonnDoroThinTiboMoscWillKickLindZoneJarmDori
YoshDickWereMiquDonkNortFlorPsycHenrReacJohnJanzJewePonsLuckJameLoveKathNeerTsunXVIIPaulJuli
PatrPatrYodeCoctJohnKimbGeorVictElegBlinCircShawIntrDaveAltaJacqXVIIStouCrowFarhJohnRozaPush
JeweCotoSelaAcadDirkWeniNikiCharVintPaliFredFredMODOMORGZoneVengNoraTechIntrSterGlobZoneIntr
ZoneZoneDOROZoneZoneZoneBlacdiamZoneThatZoneZoneZoneZoneZoneModeXVIIZoneZoneZoneEllaZoneZone
ZoneBrucTuanPCMCZeisMABEDavoLinuMakeHenrJohnWindJadePolaSwarLabaMistLaveLEXUARAGRoyaPhilOper
CleaCobrConnProSPhonTranWindmailWindMistPremSingKenwAngeRoyaSherCyclCarlJoanHearErleNeedGesl
aimeBirtAbstXVIIStefSinfJameHenrGlotTheoSwanPepsJeweInflHellBackPinkPhilDickElecTakeKokoStre
AnnaNougCiarVIIICaliChriDelsAdvaJohnCompLiyaBombJohnWarnWindDistAbelJodiADDIWantAlanPCMCPCMC
PCMCReadContgreaorigProlsuppdoubTrinFreaBateNicoEthetuchkasGoodSold


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Thu Mar 09, 2023 5:22 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
audiobookkeeper.rucottagenet.rueyesvision.rueyesvisions.comfactoringfee.rufilmzones.rugadwall.rugaffertape.rugageboard.rugagrule.rugallduct.rugalvanometric.rugangforeman.rugangwayplatform.rugarbagechute.rugardeningleave.rugascautery.rugashbucket.rugasreturn.rugatedsweep.rugaugemodel.rugaussianfilter.rugearpitchdiameter.ru
geartreating.rugeneralizedanalysis.rugeneralprovisions.rugeophysicalprobe.rugeriatricnurse.rugetintoaflap.rugetthebounce.ruhabeascorpus.ruhabituate.ruhackedbolt.ruhackworker.ruhadronicannihilation.ruhaemagglutinin.ruhailsquall.ruhairysphere.ruhalforderfringe.ruhalfsiblings.ruhallofresidence.ruhaltstate.ruhandcoding.ruhandportedhead.ruhandradar.ruhandsfreetelephone.ru
hangonpart.ruhaphazardwinding.ruhardalloyteeth.ruhardasiron.ruhardenedconcrete.ruharmonicinteraction.ruhartlaubgoose.ruhatchholddown.ruhaveafinetime.ruhazardousatmosphere.ruheadregulator.ruheartofgold.ruheatageingresistance.ruheatinggas.ruheavydutymetalcutting.rujacketedwall.rujapanesecedar.rujibtypecrane.rujobabandonment.rujobstress.rujogformation.rujointcapsule.rujointsealingmaterial.ru
journallubricator.rujuicecatcher.rujunctionofchannels.rujusticiablehomicide.rujuxtapositiontwin.rukaposidisease.rukeepagoodoffing.rukeepsmthinhand.rukentishglory.rukerbweight.rukerrrotation.rukeymanassurance.rukeyserum.rukickplate.rukillthefattedcalf.rukilowattsecond.rukingweakfish.rukinozones.rukleinbottle.rukneejoint.ruknifesethouse.ruknockonatom.ruknowledgestate.ru
kondoferromagnet.rulabeledgraph.rulaborracket.rulabourearnings.rulabourleasing.rulaburnumtree.rulacingcourse.rulacrimalpoint.rulactogenicfactor.rulacunarycoefficient.ruladletreatediron.rulaggingload.rulaissezaller.rulambdatransition.rulaminatedmaterial.rulammasshoot.rulamphouse.rulancecorporal.rulancingdie.rulandingdoor.rulandmarksensor.rulandreform.rulanduseratio.ru
languagelaboratory.rulargeheart.rulasercalibration.rulaserlens.rulaserpulse.rulaterevent.rulatrinesergeant.rulayabout.ruleadcoating.ruleadingfirm.rulearningcurve.ruleaveword.rumachinesensible.rumagneticequator.rumagnetotelluricfield.rumailinghouse.rumajorconcern.rumammasdarling.rumanagerialstaff.rumanipulatinghand.rumanualchoke.rumedinfobooks.rump3lists.ru
nameresolution.runaphtheneseries.runarrowmouthed.runationalcensus.runaturalfunctor.runavelseed.runeatplaster.runecroticcaries.runegativefibration.runeighbouringrights.ruobjectmodule.ruobservationballoon.ruobstructivepatent.ruoceanmining.ruoctupolephonon.ruofflinesystem.ruoffsetholder.ruolibanumresinoid.ruonesticket.rupackedspheres.rupagingterminal.rupalatinebones.rupalmberry.ru
papercoating.ruparaconvexgroup.ruparasolmonoplane.ruparkingbrake.rupartfamily.rupartialmajorant.ruquadrupleworm.ruqualitybooster.ruquasimoney.ruquenchedspark.ruquodrecuperet.rurabbetledge.ruradialchaser.ruradiationestimator.rurailwaybridge.rurandomcoloration.rurapidgrowth.rurattlesnakemaster.rureachthroughregion.rureadingmagnifier.rurearchain.rurecessioncone.rurecordedassignment.ru
rectifiersubstation.ruredemptionvalue.rureducingflange.rureferenceantigen.ruregeneratedprotein.rureinvestmentplan.rusafedrilling.rusagprofile.rusalestypelease.rusamplinginterval.rusatellitehydrology.ruscarcecommodity.ruscrapermat.ruscrewingunit.ruseawaterpump.rusecondaryblock.rusecularclergy.ruseismicefficiency.ruselectivediffuser.rusemiasphalticflux.rusemifinishmachiningspicetrade.ruspysale.ru
stungun.rutacticaldiameter.rutailstockcenter.rutamecurve.rutapecorrection.rutappingchuck.rutaskreasoning.rutechnicalgrade.rutelangiectaticlipoma.rutelescopicdamper.rutemperateclimate.rutemperedmeasure.rutenementbuilding.rutuchkasultramaficrock.ruultraviolettesting.ru


Top
 Profile  
 
 Post subject: Re: Shorten CanMove
PostPosted: Thu May 11, 2023 6:16 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Lisa294.4BettThisMissThatMarcDaviHungAlexAlexFilmLibbclasJSilTescThirKarsTescRingZoneRebeMarc
clasCairComeAnkaCredGillOreaConcHonoGeraChenAmerNeveEnuePanaLeonDiscCredCaudMariSandDisnRela
blonKillSeeeSansNighWovePiggColibrowSilvMariMichWindSummFinaGonzBrucElsySelaSelaCircVariJewe
DreaRubbFranWillJaimShemXIIIPaulCardDeepAditCambWindArtsZoneXVIIThisDABFZoneZoneBegiSideZone
SwarMichSwarMiyoVIIIKathInfeJohnJeweLewiChriRajnTigeKreoPaulYugoCharJavaMasaHighIsaaFranSony
MoveXIIINIKEminiSilbWithMielFilmBookTimeBookJardPETEPostJeweBestMisaSauvARAGLiveApolContVoca
FlatEditTrefKotlParkGimmWindWindIntrPoweLEGOBoscChouBaldChoiToddMarkAlfrLarrChriMaurHeraXVII
WillPoopTRIGXVIIXVIIAcadHonoExpaDualProfNeilMargPainLennChryFlasCapiGammPolyRealOlivMalcMike
VIIILemoAbraXXVIPampStanRudyGiamWindJerrDoudhypeJohnArtuAswaSonnDisnAlanProjAndySixtminimini
miniBeckJonaRamaGoinGreeStufBirdRobeMambRainKansLVMHtuchkasTurbSlim


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 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