Made by: Unknown_Raven
Ok once again I have finished another tutorial. I hope you enjoy this script as it took me 2 and a half hours to make.
Description: Ok what this does is it allows you to create scripted tiles that the user steps on and a list of locations are displayed. The player then can type the command /warpkey <location number> and then step on the scripted tile once more and they are instantly warped to the new location. The script was designed to be flexable so you can within a few minutes setup other warps with a completely new list or number of selections. Like all my scripts there is a little bit of scripting knowledge required but I am sure it will not take much to figure it all out.
Installation
First thing you have to do is copy and paste this at the bottom of your main.txt.
' *********************
' * Portal System 1.0 *
' * Made by: Grey *
' *********************
Sub SetWarpKey(index, keynum)
Call PutVar("accounts\" & GetPlayerLogin(index) & ".ini ", "CHAR" & GetPlayerCharNum(Index), "WarpKey", cdbl(keynum))
End Sub
Sub SetupWarpFile(warpkeys)
x = 1
Do While x <= warpkeys
Call PutVar("Warps.ini", "AREA1", "name" & x, "blank")
Call PutVar("Warps.ini", "AREA1", "map" & x, 0)
Call PutVar("Warps.ini", "AREA1", "X" & x, 0)
Call PutVar("Warps.ini", "AREA1", "Y" & x, 0)
x = x+1
Loop
End Sub
Sub WarpList(index, area, keys)
Call PlayerMsg(index, "Please type /warpkey <keynum> then step on this warp again to be transfered to the desired location.", 15)
Call PlayerMsg(index, "WARP LIST", 2)
x = 1
Do While x <= keys
Call PlayerMsg(index, x & ".) " & GetWarpName(area, x), 2)
x = x+1
Loop
End Sub
Sub Warp(index, area, key)
Call setwarpkey(index, 0)
Call PlayerMsg(index, "You were warped to the " & GetWarpName(area, key), 14)
Call PlayerWarp(index, GetWarpMap(area, key), GetWarpX(area, key), GetWarpY(area, key))
End Sub
Function GetWarpName(areanum, keynum)
GetWarpName = Trim(GetVar("Warps.ini", "AREA" & areanum, "name" & keynum))
End Function
Function GetWarpMap(areanum, keynum)
GetWarpMap = Int(GetVar("Warps.ini", "AREA" & areanum, "map" & keynum))
End Function
Function GetWarpX(areanum, keynum)
GetWarpX = GetVar("Warps.ini", "AREA" & areanum, "X" & keynum)
End Function
Function GetWarpY(areanum, keynum)
GetWarpY = GetVar("Warps.ini", "AREA" & areanum, "Y" & keynum)
End Function
Function GetWarpKey(index)
GetWarpKey = GetVar("accounts\" & GetPlayerLogin(index) & ".ini ", "CHAR" & GetPlayerCharNum(Index), "WarpKey")
End Function
Next we need to add this at the top of the main.txt right in the section JoinGame(index)
If GetPlayerExp(index) = 0 Then
If GetPlayerLevel(index) = 1 Then
Call SetWarpKey(index, 0)
End If
End If
Next you have to go into the /commands area of the main.txt and insert this code. Insert it at the bottom of the sub but make sure it is in the right section. It is quite easy to tell this by looking at the format of the script. You should see other scripts above it that use the "x = int(textsay)"
If LCase(Mid(TextSay, 1, 8)) = "/warpkey" Then
If Len(TextSay) > 9 Then
TextSay = Mid(TextSay, 9, Len(TextSay) - 8)
x = Int(TextSay)
If IsNumeric(x) Then
If x > 0 Then
Call PlayerMsg(index, "Location Set.", 14)
Call SetWarpKey(index, x)
End If
End If
End If
Exit Sub
End If
Now that you have installed the /warpkey command it is time to setup the scripted tiles. Find the section for scripted tiles and for case 0 or whatever case you want it as paste this.
Case 0
' this is for resetting players warp key
Call setwarpkey(index, 0)
Preferably paste this next part under case 1. You can however choose another empty case if case 1 is in use.
Case 1
' warp for area 1 maps
key = GetWarpKey(index)
If key = 0 Then
Call WarpList(index, 1, 5)
Else
If key <= 5 Then ' set 5 to the max warpkey
Call Warp(index, 1, key)
End If
End If
Ok, case one is known as the exit and case 1 is the warp. When the player steps on case 0 it sets their warp selection to 0 which makes it impossible for them to warp if they should step on the case 1 scripted tile. The idea is to place the case 0 around the case 1 tiles but leaving atleast one square of space between the two.
Next you must make the warps.ini file. First make a new .ini file and be sure to call it "Warps". Next copy this and paste it inside.
[AREA1]
name1=Darkfields
map1=7
X1=5
Y1=5
name2=Woods
map2=6
X2=5
Y2=5
name3=Castle
map3=1
X3=1
Y3=1
name4=blank
map4=1
X4=1
Y4=1
name5=blank
map5=1
X5=1
Y5=1
What you must do now is fill in the locations with names and coordinates. You can easily add more locations or even an entirely new area. All you have to do is adjust the numbers. For instance look at this example.
[AREA1]
name1=Darkfields
map1=7
X1=5
Y1=5
name2=Woods
map2=6
X2=5
Y2=5
name3=Castle
map3=1
X3=1
Y3=1
[AREA2]
name1=blank
map1=7
X1=5
Y1=5
name2=Fire Palace
map2=6
X2=5
Y2=5
name3=Moon
map3=1
X3=1
Y3=1
How it works:
The player will step onto case 1 and it will show them the list of locations to warp. They then walk off of the scripted tile and type /warpkey <num>. The number they fill in is the location they wish to warp to. After they have selected a place they step back onto the warp tile and wham they are wvooshed away. This is why you need to leave atleast one square of space between case 0 and case 1 tiles.
Adjustments
Ok now as you can see some of the commands have already been filled in with numbers. Note the "Call WarpList" The 1 you see is set for the area the list will look in and the 5 is to signify how many possible warp locations there are.
Now I will breifly go over all the handy commands that have been added.
GetWarpName(area, key)
-Gets the Location name for the specified area and key.
GetWarpMap(area, key)
-Gets the location map number.
GetWarpX(area, key)
-Gets the location X coordinate.
GetWarpY(area, key)
-Gets the location Y coordinate.
GetWarpKey(index)
-Gets the Key Value the player currently has set in their account file.
Call SetWarpKey(index, keynum)
-Used to set a key value within their accounts file.
SetupWarpFile(warpkeys)
-This actually can setup a Warps.ini file within seconds but only for area1. Just fill in warpkeys with the ammount of locations you want within area1.
WarpList(index, area, keys)
-Displays a list of locations for the specified area. Keys must be filled in with the max number of locations. Say Area1 goes all the way up to map5, x5, y5 then your keys value would be 5.
Warp(index, area, key)
-This command warps the player to the specified area location key. Just fill in the area and key number.