From 2d3024a574858935aac4c4a4fa078b357498531a Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 13 Apr 2021 18:36:47 -0300 Subject: Add LOCATION$ support (but it is not being saved yet) --- db/constants.conf | 5 +- npc/000-1/exit.txt | 5 +- npc/commands/debug.txt | 2 +- npc/functions/location.txt | 143 +++++++++++++++++++++++++++++++++++++++++++++ npc/scripts.conf | 1 + 5 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 npc/functions/location.txt diff --git a/db/constants.conf b/db/constants.conf index 21a6dc01..8a5a7aa0 100644 --- a/db/constants.conf +++ b/db/constants.conf @@ -5257,11 +5257,10 @@ more than one separator can be used in a row (so 12_3___456 is illegal). comment__: "Location Constants" TP_NONE: 0 - TP_ARTIS: 1 + TP_CANDOR: 1 TP_TULIM: 2 TP_HURNS: 4 - TP_CANDOR: 8 - TP_ARGAES: 16 + TP_NIVAL: 8 comment__: "Rossy Quest Constants" ROSSY_PROLOGUE: 1 diff --git a/npc/000-1/exit.txt b/npc/000-1/exit.txt index a3c4f6c7..4c8f167e 100644 --- a/npc/000-1/exit.txt +++ b/npc/000-1/exit.txt @@ -8,11 +8,14 @@ OnTouch: OnTalk: OnTalkNearby: + if (LOCATION$ != "") goto L_ToLoc; if (Sex) warp "029-2", 25, 24; else warp "029-2", 22, 24; end; - +L_ToLoc: + ReturnTown(); + end; } diff --git a/npc/commands/debug.txt b/npc/commands/debug.txt index a033fe67..269fdb60 100644 --- a/npc/commands/debug.txt +++ b/npc/commands/debug.txt @@ -592,7 +592,7 @@ OnSClear: dispbottom l("Status Condition Cleared"); end; -OnAllperms: +OnAllPerms: if (@allperms) end; charcommand("@addperm all_skill"); charcommand("@addperm all_equipment"); diff --git a/npc/functions/location.txt b/npc/functions/location.txt new file mode 100644 index 00000000..093764af --- /dev/null +++ b/npc/functions/location.txt @@ -0,0 +1,143 @@ +// TMW2 Script +// Author: Jesusalva +// Location Config + +- script loc_config 32767,{ + end; + +OnInit: + // TP_FORT TP_BOSSR + setarray $@LOCMASTER_TP, TP_CANDOR,TP_TULIM,TP_HURNS,TP_NIVAL; + setarray $@LOCMASTER_LOC$, "Candor", "Tulim", "Hurns", "Nival"; + setarray $@LOCMASTER_MAP$, "029-1", "001-1", "009-1", "020-1"; + setarray $@LOCMASTER_X, 46, 51, 52, 75; + setarray $@LOCMASTER_Y, 97, 78, 41, 85; + + //debugmes "Locmaster: Index 0: %s [%s.gat (%d, %d)]", $@LOCMASTER_LOC$[0], $@LOCMASTER_MAP$[0], $@LOCMASTER_X[0], $@LOCMASTER_Y[0]; + //debugmes "Locmaster: Index 2: %s [%s.gat (%d, %d)]", $@LOCMASTER_LOC$[2], $@LOCMASTER_MAP$[2], $@LOCMASTER_X[2], $@LOCMASTER_Y[2]; + //debugmes "Locmaster: Index 5: %s [%s.gat (%d, %d)]", $@LOCMASTER_LOC$[5], $@LOCMASTER_MAP$[5], $@LOCMASTER_X[5], $@LOCMASTER_Y[5]; + end; +} + +// Resaves your respawn point +function script ResaveRespawn { + .@i=array_find($@LOCMASTER_LOC$, LOCATION$); + savepoint $@LOCMASTER_MAP$[.@i], $@LOCMASTER_X[.@i], $@LOCMASTER_Y[.@i]; + return; +} + +// Warps you to last visited town +function script ReturnTown { + .@i=array_find($@LOCMASTER_LOC$, LOCATION$); + warp $@LOCMASTER_MAP$[.@i], $@LOCMASTER_X[.@i], $@LOCMASTER_Y[.@i]; + return; +} + +// Convert map name to location id +// LocToMap( LocName ) +function script LocToMap { + // Fill variable + .@v$=getarg(0); + + // Error code + if (playerattached()) + .@err=RB_DEFAULT; + else + .@err=RB_DEBUGMES; + + // Validade variable, see npc/config/location.txt first + .@lx=array_find($@LOCMASTER_LOC$, .@v$); + if (.@lx < 0) + return Exception("Invalid location passed to LocToMap: "+.@v$, .@err); + + return $@LOCMASTER_MAP$[.@lx]; +} + +// Convert map name to location id +// MapToLoc( MapName ) +function script MapToLoc { + // Fill variable + .@v$=getarg(0); + + // Error code + if (playerattached()) + .@err=RB_DEFAULT; + else + .@err=RB_DEBUGMES; + + // Validade variable, see npc/config/location.txt first + .@lx=array_find($@LOCMASTER_MAP$, .@v$); + if (.@lx < 0) + return Exception("Invalid map passed to MapToLoc: "+.@v$, .@err); + + return $@LOCMASTER_LOC$[.@lx]; +} + +// Gets the location code for TP code +function script TPToLoc { + .@i=array_find($@LOCMASTER_TP, getarg(0)); + return $@LOCMASTER_MAP$[.@i]; + return; +} + +// Convert LOC (uppercase) to a TP variable +// POL_LocToTP( {TOWNCODE} ) +function script POL_LocToTP { + .@tw$=strtoupper(getarg(0, LOCATION$)); + + if (.@tw$ == "TULIM") + return TP_TULIM; + + if (.@tw$ == "HALIN") + return TP_HALIN; + + if (.@tw$ == "HURNS") + return TP_HURNS; + + if (.@tw$ == "LOF") + return TP_LOF; + + if (.@tw$ == "NIVAL") + return TP_NIVAL; + + if (.@tw$ == "ARTIS") + return TP_ARTIS; + + if (.@tw$ == "CANDOR") + return TP_CANDOR; + + if (.@tw$ == "LILIT") + return TP_LILIT; + + // TODO: Change this to use npc/config/location.txt instead + if (.@tw$ == "FROSTIA") + return TP_FROST; + + return Exception("Invalid town requested / POL_LocToTP", RB_DEFAULT|RB_SPEECH, -1); +} + +// Upon entering a town +// EnterTown( LocName ) +function script EnterTown { + // Fill variable + .@v$=getarg(0); + + // Validade variable, see npc/config/location.txt first + if (array_find($@LOCMASTER_LOC$, .@v$) < 0) + return Exception("Invalid location passed to EnterTown: "+.@v$); + + LOCATION$=.@v$; + return; +} + +// Warps home and updates LOCATION$ +function script teleporthome { + warp "Save", 0, 0; + .@i=array_find($@LOCMASTER_MAP$, getmap()); + if (.@i >= 0) + EnterTown($@LOCMASTER_LOC$[.@i]); + else + debugmes("[ERROR] Invalid Town Map for Time Flask: %s", getmap()); + return; +} + diff --git a/npc/scripts.conf b/npc/scripts.conf index 26805df0..9c166fbb 100644 --- a/npc/scripts.conf +++ b/npc/scripts.conf @@ -47,6 +47,7 @@ "npc/functions/motdconfig.txt", "npc/functions/miriam.txt", "npc/functions/ghost.txt", +"npc/functions/location.txt", // Items "npc/items/purification_potion.txt", -- cgit v1.2.3-70-g09d2