Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[ED2.1.0b+] Scripted Chests


Stein
 Share

Recommended Posts

Hello there, since scripting has just been added to Eclipse Dawn 2.1.0, I figured I'd make a quick tutorial that shows you how easy it can be to add new functionality to your server by just changing a few files! Now, then.. Let's get started shall we?

Note: The GetOpenInvSlots function does NOT take into account what you want to place in there, and may result in inaccurate results when you try and hand out currencies to the player, and assume this currency requires an additional slot. Please take this into account when using the script, I may resolve this issue later this week. This issue will not break the script, but may cause it to say your inventory is full when you have enough space when items stack with existing slots.

**Step 1: Your server.**
Make sure your server is up to date, and running AT LEAST Eclipse Dawn 2.1.0b, it will not work in lower versions or any other custom Eclipse Version. Please note that it does not matter whether your server is running or not, there's a method of reloading the scripts while the server runs.

**Step 2: Making directories.**
Since my script uses specific directories to store Data, let's make them!

Head into your **Server Directory** and click on **Data**, once in there make a new folder called **ScriptData** and go inside it, in there make another folder called **Frankenstein** and enter it as well, then finaly in there make a new folder called **Chests**. If all went well, you should now have the following folder structure to get where you are: **\data\scriptdata\frankenstein\chests\.**

Head back to your **Server Directory** and click the **Scripts** folder, once in there make a new folder called **User** and go inside it, in there make another called **Frankenstein**. If all went well, your folder structure should be as follows: **data\scripts\user**

The reason I chose these names are simply to keep things organized in the future should I want to add more scripts of my own, or another user. But do bear in mind that it does not matter what folder structure you use, as long as you rewrite the script(s) to reflect the changes.

**Step 3: Creating the file script file.**
First, copy the following script:

```
' Eclipse Dawn Chest System V1.1
' Written by Frankenstein (Sil van Harberden)
' 29 / 09 / 2013 (DD / MM / YYYY)

Function GetPlayerChestState(Index, Chest)
GetPlayerChestState = GetVar("data\scriptdata\frankenstein\chests\cheststate.ini", GetPlayerName(Index), "Chest" & CSTR(Chest))
' Error checking below, if the record is empty it returns a blank string.
' And a blank string can't be converted to a Long, so that's why we need to check this manually.
If GetPlayerChestState = "" Then
GetPlayerChestState = ChestStateFull
Else
GetPlayerChestState = CLNG(GetPlayerChestState)
End If

End Function

Sub SetPlayerChestState(Index, Chest, State)
PutVar "data\scriptdata\frankenstein\chests\cheststate.ini", GetPlayerName(Index), "Chest" & CSTR(Chest), CSTR(State)
End Sub

Function GetChestMaxItems(Chest)
GetChestMaxItems = CLNG(GetVar("data\scriptdata\frankenstein\chests\chestcontent.ini", "Chest" & CSTR(Chest), "MaxItems"))
End Function

Function GetChestItemNum(Chest, Item)
GetChestItemNum = CLNG(GetVar("data\scriptdata\frankenstein\chests\chestcontent.ini", "Chest" & CSTR(Chest), "Item" & CSTR(Item) & "Num"))
End Function

Function GetChestItemVal(Chest, Item)
GetChestItemVal = CLNG(GetVar("data\scriptdata\frankenstein\chests\chestcontent.ini", "Chest" & CSTR(Chest), "Item" & CSTR(Item) & "Val"))
End Function

Sub OpenChest(Index, Chest, OpenMsg, EmptyMsg)
Dim i, MaxItems, Item, Val, Name, OpenSlots

' Check if the chest is empty for this player before we begin.
If GetPlayerChestState(Index, Chest) <> ChestStateEmpty Then

' The chest seems to be alright for this guy, let's move on!
' Retrieve the max amount of items in this chest.
MaxItems = GetChestMaxItems(Chest)

' Check if the player has enough room for all these items.
OpenSlots = GetOpenInvSlots(Index)
If OpenSlots => MaxItems then
' Player has enough space to hold the items.

' And time to loop through this mess, we want to hand out the items to the player, after all.
For i = 1 to MaxItems

' Retrieve the item number and amounts.
Item = GetChestItemNum(Chest, i)
Val = GetChestItemVal(Chest, i)

' Hand it out
GivePlayerItem Index, Item, Val

Next

' Set the chest state to empty.
SetPlayerChestState Index, Chest, ChestStateEmpty

' Done! Let's notify our player of his opened chest!
PlayerMsg Index, OpenMsg, BrightRed
Else
' Player doesn't have enough space in his inventory.
PlayerMsg Index, "Your inventory does not have enough space to hold all the items in this chest!", BrightRed
End If
Else

' Seems like this player's opened the chest before.
' Let's notify them.
PlayerMsg Index, EmptyMsg, BrightRed
End If

End SubĀ 
```

Now return to the **data\scripts\user** directory and make a file called **Chests.eds**, open it up and paste the above code into it.

**Step 4: Editing Main.eds**
Open up your Main.eds file inside the **Scripts** directory, and search for the following line: **Public Const Shield = 4**, below it paste the following:

```
' ***
' Chest States
' ***
Public Const ChestStateFull = 0
Public Const ChestStateEmpty = 1

' ***
' Chest Strings
' ***
Public Const ChestOpened = "You have opened a chest and found bountiful riches!"
Public Const ChestEmpty = "You have already looted this chest before."
```

Now search for **#include** and paste the following below it:

```
' ***
' User Created Scripts
' ***
#include
```

Save the file and we should be done there.

**Step 5: Creating the required *.ini files**
Go to the **data\scriptdata\frankenstein\chests** folder and make a file called **ChestState.ini**, this file will hold all the data of which player has opened which chest so it is fairly important that it is always present!
Now, in the same folder create a file called **ChestContent.ini**, this file will determine which chest contains which items. Copy and paste the following test data into it:

```
[Chest1]
MaxItems= 1
Item1Num= 1
Item1Val= 25
```

Here's a basic explanation as to what all these values do:
**[Chest1]** This is the header that seperates one chest from another, in this case the data below this would belong to Chest #1, whereas everything below **[Chest2]** Would belong to Chest #2.
**MaxItems = 1** This determines the maximum amount of item slots this chest has in it, if you look at the values under it you will see numbers between the two words in each line, this number determines the item slot it takes up, make sure you fill ALL the slots with data up to the maximum you've set or it may cause issues.
**Item1Num = 1** This determines which item number slot 1 contains, if you want to add items to slot 2, simply add a new line under the header called **Item2Num**, or whichever number happens to the next one up. (make sure you adjust MaxItems accordingly!)
**Item1Val = 25** This determines what amount of items slot 1 contains, if you want to add items to slot 2, simply add a new line under the header called **Item2Num**, or whichever number happens to the next one up. (make sure you adjust MaxItems accordingly!)
Save the file, and let's get on to the last step!

**Step 6: Opening a chest**
Opening a chest is very simple, you only need to add the following command somewhere in your code, possibly on a scripted item, tile or an NPC:

```
OpenChest Index, 1, ChestOpened, ChestEmpty
```

Note that Index is not always called Index in every sub, pay attention to that. The 1 in the line can be replaced with any chest ID that you've created, and ChestOpened/ChestEmpty are default strings we added, if you want a custom message for your chest you can ofcourse simply replace the two variabled with your own text.
Happy treasure hunting!

**Should you have edited your script files while the server is running, go to your server console and hit the Controls tab, then hit the Scripts button. This will reload the scripts!**
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...