Expanded @Script.Delay with ItemCount DelayType

Also made each Script Delay be defined with an identifier so you can have multiple delays running at the same time!

* arg0 = Identifier
* arg1 = Script Path
* arg2 = Delay Type (Steps, ItemCount)
// Steps
* arg3 = Amount of steps
* arg4 = Whether to display the remaining steps in the start menu
//ItemCount
* arg3 = Item ID
* arg4 = Compare Type (Equal, Below, EqualOrBelow, Above, EqualOrAbove)
* arg5 = Item Amount

With the ItemCount type you can run a script when you do or do not have a certain amount of items
This commit is contained in:
JappaWakka 2024-12-28 19:26:01 +01:00
parent d49217ff95
commit 9b942ab977
9 changed files with 244 additions and 24 deletions

View File

@ -663,7 +663,7 @@
_mainMenuItemList.Clear()
Select Case BattleScreen.BattleMode
Case BattleSystem.BattleScreen.BattleModes.Safari
Dim safariBallText As String = "Safari Ball x" & Core.Player.Inventory.GetItemAmount(181.ToString).ToString()
Dim safariBallText As String = Localization.GetString("item_name_181", "Safari Ball") & " x" & Core.Player.Inventory.GetItemAmount(181.ToString).ToString()
If Core.Player.Inventory.GetItemAmount(181.ToString) = 0 Then
safariBallText = "No Safari Balls."
End If
@ -832,6 +832,8 @@
BattleScreen.BattleQuery.Insert(0, New ToggleMenuQueryObject(True))
Core.SetScreen(New BattleCatchScreen(BattleScreen, Item.GetItemByID(181.ToString)))
Core.Player.UsedItemsToCheckScriptDelayFor.Add("181")
Dim safariBallText As String = "Safari Ball x" & Core.Player.Inventory.GetItemAmount(181.ToString).ToString()
If Core.Player.Inventory.GetItemAmount(181.ToString) = 0 Then
safariBallText = "No Safari Balls."

View File

@ -180,6 +180,7 @@
ItemID = Me.Item.ID.ToString
End If
Core.Player.Inventory.AddItem(ItemID, 1)
Core.Player.CheckItemCountScriptDelay(ItemID)
PlayerStatistics.Track("Items found", 1)
Core.Player.AddPoints(1, "Found an item.")

View File

@ -151,6 +151,14 @@
End Set
End Property
Public Property ScriptDelayItems() As String
Get
Return _ScriptDelayItems
End Get
Set(value As String)
_ScriptDelayItems = value
End Set
End Property
Public Property ScriptDelaySteps() As Integer
Get
Return _ScriptDelaySteps
@ -159,6 +167,14 @@
_ScriptDelaySteps = value
End Set
End Property
Public Property ScriptDelayDisplaySteps() As Boolean
Get
Return _ScriptDelayDisplaySteps
End Get
Set(value As Boolean)
_ScriptDelayDisplaySteps = value
End Set
End Property
Public Property SaveCreated() As String
Get
@ -391,6 +407,7 @@
Public TempRideSkin As String = ""
Public Statistics As String = ""
Public CheckForTrainersLater As Boolean = False
Public UsedItemsToCheckScriptDelayFor As New List(Of String)
'Secure fields:
Private _name As String = "<player.name>"
@ -410,6 +427,8 @@
Private _lastSavePlacePosition As String = "1,0.1,3"
Private _repelSteps As Integer = 0
Private _ScriptDelaySteps As Integer = 0
Private _ScriptDelayItems As String = ""
Private _ScriptDelayDisplaySteps As Boolean = False
Private _saveCreated As String = "Pre 0.21"
Private _daycareSteps As Integer = 0
Private _poisonSteps As Integer = 0
@ -746,8 +765,12 @@
End If
Case "repelsteps"
RepelSteps = CInt(Value)
Case "scriptdelayitems"
ScriptDelayItems = Value
Case "scriptdelaysteps"
ScriptDelaySteps = CInt(Value)
Case "scriptdelaydisplaysteps"
ScriptDelayDisplaySteps = CBool(Value)
Case "lastsaveplace"
LastSavePlace = Value
Case "lastsaveplaceposition"
@ -1252,7 +1275,9 @@
"LastRestPlacePosition|" & LastRestPlacePosition & Environment.NewLine &
"DiagonalMovement|" & DiagonalMovement.ToNumberString() & Environment.NewLine &
"RepelSteps|" & RepelSteps.ToString() & Environment.NewLine &
"ScriptDelayItems|" & ScriptDelayItems.ToString() & Environment.NewLine &
"ScriptDelaySteps|" & ScriptDelaySteps.ToString() & Environment.NewLine &
"ScriptDelayDisplaySteps|" & ScriptDelayDisplaySteps.ToNumberString() & Environment.NewLine &
"LastSavePlace|" & LastSavePlace & Environment.NewLine &
"LastSavePlacePosition|" & LastSavePlacePosition & Environment.NewLine &
"Difficulty|" & DifficultyMode.ToString() & Environment.NewLine &
@ -1791,13 +1816,29 @@
If ScriptDelaySteps <= 0 Then
If CurrentScreen.Identification = Screen.Identifications.OverworldScreen Then
If CanFireStepEvent() = True Then
If ActionScript.IsRegistered("SCRIPTDELAY") = True Then
Dim registerContent() As Object = ActionScript.GetRegisterValue("SCRIPTDELAY")
Dim Data() As String = Core.Player.RegisterData.Split(CChar(","))
Dim StepDelayRegisterName As String = ""
For Each line As String In Data
If line.StartsWith("[") = True And line.Contains("]") = True And line.EndsWith("]") = False Then
Dim lineName As String = line.Remove(0, line.IndexOf("]") + 1)
Dim delayID As String = ""
If lineName.StartsWith("SCRIPTDELAY_") Then
Dim registerContent() As Object = ActionScript.GetRegisterValue(lineName)
Dim delayType As String = CStr(registerContent(0)).GetSplit(0, ";")
If delayType.ToLower = "steps" Then
StepDelayRegisterName = lineName
End If
End If
End If
Next
If StepDelayRegisterName <> "" Then
ScriptDelayDisplaySteps = False
Dim registerContent() As Object = ActionScript.GetRegisterValue(StepDelayRegisterName)
If registerContent(0) Is Nothing Or registerContent(1) Is Nothing Then
Logger.Log(Logger.LogTypes.Warning, "ScriptComparer.vb: No valid script has been set to be executed.")
ActionScript.UnregisterID("SCRIPTDELAY", "str")
ActionScript.UnregisterID("SCRIPTDELAY")
ActionScript.UnregisterID(StepDelayRegisterName, "str")
ActionScript.UnregisterID(StepDelayRegisterName)
Exit Sub
End If
@ -1806,8 +1847,8 @@
Dim DelayValue As String = CStr(registerContent(0)).GetSplit(1, ";")
CType(CurrentScreen, OverworldScreen).ActionScript.StartScript(DelayValue, 0, False)
ActionScript.UnregisterID("SCRIPTDELAY", "str")
ActionScript.UnregisterID("SCRIPTDELAY")
ActionScript.UnregisterID(StepDelayRegisterName, "str")
ActionScript.UnregisterID(StepDelayRegisterName)
End If
End If
Else
@ -1958,6 +1999,72 @@
#End Region
Public Sub CheckItemCountScriptDelay(itemID As String)
Dim ItemDelayList As List(Of String) = Core.Player.ScriptDelayItems.Split(";").ToList
For Each entry As String In ItemDelayList
If entry.GetSplit(1, ",").ToLower = itemID.ToLower Then
Dim inventoryAmount As Integer = Core.Player.Inventory.GetItemAmount(itemID)
Dim Match As Boolean = False
Select Case entry.GetSplit(2, ",")
Case "=", "equal"
If inventoryAmount = CInt(entry.GetSplit(3, ",")) Then
Match = True
End If
Case "<", "below"
If inventoryAmount < CInt(entry.GetSplit(3, ",")) Then
Match = True
End If
Case "<=", "equalorbelow"
If inventoryAmount <= CInt(entry.GetSplit(3, ",")) Then
Match = True
End If
Case ">", "above"
If inventoryAmount > CInt(entry.GetSplit(3, ",")) Then
Match = True
End If
Case ">=", "equalorabove"
If inventoryAmount >= CInt(entry.GetSplit(3, ",")) Then
Match = True
End If
End Select
If Match = True Then
Dim DelayRegisterName As String = "SCRIPTDELAY_" & entry.GetSplit(0, ",")
Dim Data() As String = Core.Player.RegisterData.Split(CChar(","))
ScriptDelayDisplaySteps = False
Dim registerContent() As Object = ActionScript.GetRegisterValue(DelayRegisterName)
If registerContent(0) Is Nothing Or registerContent(1) Is Nothing Then
Logger.Log(Logger.LogTypes.Warning, "ScriptComparer.vb: No valid script has been set to be executed.")
ActionScript.UnregisterID(DelayRegisterName, "str")
ActionScript.UnregisterID(DelayRegisterName)
End If
Dim DelayType As String = CStr(registerContent(0)).GetSplit(0, ";")
If DelayType.ToLower = "itemcount" Then
Dim DelayValue As String = CStr(registerContent(0)).GetSplit(1, ";")
Dim s As Screen = CurrentScreen
While s.Identification <> Screen.Identifications.OverworldScreen And Not s.PreScreen Is Nothing
s = s.PreScreen
End While
If s.Identification = Screen.Identifications.OverworldScreen Then
CType(CurrentScreen, OverworldScreen).ActionScript.StartScript(DelayValue, 0, False)
ActionScript.UnregisterID(DelayRegisterName, "str")
ActionScript.UnregisterID(DelayRegisterName)
ItemDelayList.Remove(entry)
Exit For
End If
End If
End If
End If
Next
Core.Player.ScriptDelayItems = String.Join(";", ItemDelayList)
End Sub
Public Sub AddVisitedMap(ByVal mapFile As String)
Dim maps As List(Of String) = VisitedMaps.Split(CChar(",")).ToList()
@ -2129,6 +2236,7 @@
DaycareData = ""
HallOfFameData = ""
RoamingPokemonData = ""
UsedItemsToCheckScriptDelayFor.Clear()
filePrefix = "nilllzz"
newFilePrefix = ""

View File

@ -999,6 +999,12 @@ Public Class NewInventoryScreen
Case INFO_ITEM_OPTION_USE
cItem.Use()
LoadItems()
If Me.PreScreen.Identification = Screen.Identifications.BattleScreen Then
Core.Player.UsedItemsToCheckScriptDelayFor.Add(_items(ItemIndex + PageIndex * 10).ItemID)
Else
Core.Player.CheckItemCountScriptDelay(_items(ItemIndex + PageIndex * 10).ItemID)
End If
Case INFO_ITEM_OPTION_GIVE
Dim selScreen = New PartyScreen(Core.CurrentScreen) With {.Mode = ISelectionScreen.ScreenMode.Selection, .CanExit = True}
AddHandler selScreen.SelectedObject, AddressOf GiveItemHandler

View File

@ -108,6 +108,14 @@
Private Sub ChangeScreen()
Core.SetScreen(NewScreen)
If OldScreen.Identification = Identifications.BattleScreen And CurrentScreen.Identification = Identifications.OverworldScreen Then
If Core.Player.UsedItemsToCheckScriptDelayFor.Count > 0 Then
For Each itemEntry As String In Core.Player.UsedItemsToCheckScriptDelayFor
Core.Player.CheckItemCountScriptDelay(itemEntry)
Next
Core.Player.UsedItemsToCheckScriptDelayFor.Clear()
End If
End If
End Sub
Public Delegate Sub DoStuff()

View File

@ -36,6 +36,7 @@
amount = int(item.MaxStack - Core.Player.Inventory.GetItemAmount(_itemID)).Clamp(0, 999)
End If
Core.Player.Inventory.AddItem(_itemID, amount)
Core.Player.CheckItemCountScriptDelay(_itemID)
End If
Case "remove"
Dim amount As Integer = 1
@ -75,6 +76,7 @@
CanContinue = False
End If
Core.Player.CheckItemCountScriptDelay(_itemID)
Case "clearitem"
If argument <> "" Then
Dim ItemID As String = argument
@ -83,6 +85,7 @@
If amount > 0 Then
Core.Player.Inventory.RemoveItem(ItemID, amount)
End If
Core.Player.CheckItemCountScriptDelay(ItemID)
Else
Core.Player.Inventory.Clear()
End If
@ -149,6 +152,7 @@
Dim itemID As String = argument
If Core.Player.Inventory.GetItemAmount(itemID) > 0 Then
Item.GetItemByID(itemID).Use()
Core.Player.CheckItemCountScriptDelay(itemID)
End If
Case "select"
Dim allowedPages As Integer()

View File

@ -20,23 +20,104 @@
CType(Core.CurrentScreen, OverworldScreen).ActionScript.StartScript(argument, 2, True, False, "ScriptCommand")
Case "delay"
If argument.Contains(",") = True Then
ActionScript.UnregisterID("SCRIPTDELAY", "str")
ActionScript.UnregisterID("SCRIPTDELAY")
Core.Player.ScriptDelaySteps = 0
'arg 0 = Identifier
'arg 1 = Script Path
'arg 2 = Delay Type
' //Steps
'arg 3 = Amount of steps
'arg 4 = Whether to display the remaining steps in the start menu
' //ItemCount
'arg 3 = Item ID
'arg 4 = Compare Type
'arg 5 = Item Amount
Dim args() As String = argument.Split(CChar(","))
Select Case args(1).ToLower
If ActionScript.IsRegistered("SCRIPTDELAY_" & args(0).ToLower) = True Then
ActionScript.UnregisterID("SCRIPTDELAY_" & args(0), "str")
ActionScript.UnregisterID("SCRIPTDELAY_" & args(0))
End If
If Core.Player.ScriptDelaySteps > 0 AndAlso args(2).ToLower = "steps" Then
Dim Data() As String = Core.Player.RegisterData.Split(CChar(","))
For Each line As String In Data
If line.StartsWith("[") = True And line.Contains("]") = True And line.EndsWith("]") = False Then
Dim lineName As String = line.Remove(0, line.IndexOf("]") + 1)
Dim delayID As String = ""
If lineName.StartsWith("SCRIPTDELAY_") Then
Dim registerContent() As Object = ActionScript.GetRegisterValue(lineName)
Dim delayType As String = CStr(registerContent(0)).GetSplit(0, ";")
If delayType.ToLower = "steps" Then
ActionScript.UnregisterID(lineName, "str")
ActionScript.UnregisterID(lineName)
Core.Player.ScriptDelaySteps = 0
Exit For
End If
End If
End If
Next
End If
Select Case args(2).ToLower
Case "steps"
Core.Player.ScriptDelaySteps = CInt(args(2))
Core.Player.ScriptDelaySteps = CInt(args(3))
Dim DisplaySteps As Boolean = False
If args.Count > 4 Then
DisplaySteps = CBool(args(4))
End If
Core.Player.ScriptDelayDisplaySteps = DisplaySteps
Case "itemcount"
Dim CompareType As String = ""
Select Case args(4).ToLower
Case "equal"
CompareType = "equal"
Case "below"
CompareType = "below"
Case "equalorbelow"
CompareType = "equalorbelow"
Case "above"
CompareType = "above"
Case "equalorabove"
CompareType = "equalorabove"
End Select
If args(3) <> "" And CompareType <> "" And StringHelper.IsNumeric(args(5)) Then
If Core.Player.ScriptDelayItems.Contains(args(0) & "," & args(3) & "," & CompareType & "," & CInt(args(5))) = False Then
If Core.Player.ScriptDelayItems <> "" Then
Core.Player.ScriptDelayItems &= ";"
End If
'0=delayIdentifier,1=itemID,2=compareType,3=itemAmount
Core.Player.ScriptDelayItems &= args(0) & "," & args(3) & "," & CompareType & "," & CInt(args(5))
End If
End If
End Select
ActionScript.RegisterID("SCRIPTDELAY", "str", CStr(args(1) & ";" & args(0)))
ActionScript.RegisterID("SCRIPTDELAY_" & args(0), "str", CStr(args(2).ToLower & ";" & args(1)))
End If
IsReady = True
Case "cleardelay"
ActionScript.UnregisterID("SCRIPTDELAY", "str")
ActionScript.UnregisterID("SCRIPTDELAY")
If argument <> "" Then
Dim registerContent() As Object = ActionScript.GetRegisterValue("SCRIPTDELAY_" & argument)
Dim delayType As String = CStr(registerContent(0)).GetSplit(0, ";")
Select Case delayType.ToLower
Case "steps"
Core.Player.ScriptDelaySteps = 0
Core.Player.ScriptDelayDisplaySteps = False
Case "itemcount"
Dim ItemDelayList As List(Of String) = Core.Player.ScriptDelayItems.Split(",").ToList
For Each entry As String In ItemDelayList
If entry.GetSplit(0, ",") = argument Then
ItemDelayList.Remove(entry)
Exit For
End If
Next
Core.Player.ScriptDelayItems = String.Join(";", ItemDelayList)
End Select
ActionScript.UnregisterID("SCRIPTDELAY_" & argument, "str")
ActionScript.UnregisterID("SCRIPTDELAY_" & argument)
End If
IsReady = True
End Select
End If

View File

@ -12,18 +12,20 @@
Select Case command.ToLower()
Case "delay"
If ActionScript.IsRegistered("SCRIPTDELAY") = True Then
Dim args() As String = argument.Split(CChar(","))
Dim registerContent() As Object = ActionScript.GetRegisterValue("SCRIPTDELAY")
If ActionScript.IsRegistered("SCRIPTDELAY_" & args(0)) = True Then
Dim registerContent() As Object = ActionScript.GetRegisterValue("SCRIPTDELAY_" & args(0))
If registerContent(0) Is Nothing Or registerContent(1) Is Nothing Then
Logger.Log(Logger.LogTypes.Warning, "ScriptComparer.vb: No valid script has been set to be executed.")
ActionScript.UnregisterID("SCRIPTDELAY", "str")
ActionScript.UnregisterID("SCRIPTDELAY")
ActionScript.UnregisterID("SCRIPTDELAY_" & args(0), "str")
ActionScript.UnregisterID("SCRIPTDELAY_" & args(0))
Return DefaultNull
End If
Select Case argument.ToLower
Select Case args(1).ToLower
Case "type"
Return CStr(registerContent(0)).GetSplit(0, ";")
Case "script"
@ -33,6 +35,14 @@
Select Case DelayType
Case "steps"
Return Core.Player.ScriptDelaySteps
Case "itemcount"
Dim ItemDelayList As List(Of String) = Core.Player.ScriptDelayItems.Split(";").ToList
For Each entry As String In ItemDelayList
If entry.GetSplit(0, ",") = args(0) Then
Return entry.GetSplit(3)
Exit For
End If
Next
End Select
End Select

View File

@ -368,11 +368,11 @@ Namespace ScriptVersion2
r(New ScriptCommand("script", "start", {New ScriptArgument("scriptFile", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Starts a script with the given filename (without file extension)."))
r(New ScriptCommand("script", "text", {New ScriptArgument("text", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Starts a script with a simple text to display."))
r(New ScriptCommand("script", "run", {New ScriptArgument("scriptContent", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Runs script content. New lines are represented with ""^""."))
r(New ScriptCommand("script", "delay", {New ScriptArgument("scriptPath", ScriptArgument.ArgumentTypes.Str), New ScriptArgument("delayType", ScriptArgument.ArgumentTypes.Str, {"steps"}), New ScriptArgument("delayValue", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Executes a script file after something happened (like having moved a certain amount of steps)."))
r(New ScriptCommand("script", "delay", "Clears the register created with @script.delay, preventing the script from being executed."))
r(New ScriptCommand("script", "delay", {New ScriptArgument("delayID", ScriptArgument.ArgumentTypes.Str), New ScriptArgument("scriptPath", ScriptArgument.ArgumentTypes.Str), New ScriptArgument("delayType", ScriptArgument.ArgumentTypes.Str, {"steps", "itemcount"}), New ScriptArgument("valueArguments", ScriptArgument.ArgumentTypes.StrArr)}.ToList(), "Executes a script file after something happened (like having moved a certain amount of steps)."))
r(New ScriptCommand("script", "cleardelay", {New ScriptArgument("delayID", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Removes the register with the specified identifier (delayID) created with @script.delay, preventing the script from being executed."))
' Constructs:
r(New ScriptCommand("script", "delay", "str,int", {New ScriptArgument("type", ScriptArgument.ArgumentTypes.Str, {"type", "script", "value"})}.ToList(), "Returns the ""type"", ""scriptpath"" or ""value"" of what will trigger the script, like the number of steps.", ",", True))
r(New ScriptCommand("script", "delay", "str,int", {New ScriptArgument("delayID", ScriptArgument.ArgumentTypes.Str), New ScriptArgument("returnType", ScriptArgument.ArgumentTypes.Str, {"type", "script", "value"})}.ToList(), "Returns the ""type"", ""scriptpath"" or ""value"" of what will trigger the script, like the number of steps.", ",", True))
End Sub
Private Shared Sub DoRegister()