Marsh Posted February 11, 2006 Author Share Posted February 11, 2006 *~*~*~*~*~*Dissecting Main.txt and adding SadScript TutorialsCreated By: TheYellowMole(TYM)*~*~*~*~*~*':: Access ::'ADMIN_MONITER = 1'ADMIN_MAPPER = 2'ADMIN_DEVELOPER = 3'ADMIN_CREATOR = 4':: Text Color Code ::'Black = 0'Blue = 1'Green = 2'Cyan = 3'Red = 4'Magenta = 5'Brown = 6'Grey = 7'DarkGrey = 8'BrightBlue = 9'BrightGreen = 10'BrightCyan = 11'BrightRed = 12'Pink = 13'Yellow = 14'White = 15Sub JoinGame(index)Dim GameNameDim MOTDGameName = Trim(GetVar("Data.ini", "CONFIG", "GameName"))MOTD = GetVar("motd.ini", "MOTD", "Msg")' Send a global message that he/she joinedIf GetPlayerAccess(index) <= ADMIN_MONITER ThenCall GlobalMsg(GetPlayerName(index) & " has joined " & GameName & "!", 7)ElseCall GlobalMsg(GetPlayerName(index) & " has joined " & GameName & "!", 15)End If' Send them welcomeCall PlayerMsg(index, "Welcome to " & GameName & "!", 15)' Send motdIf Trim(MOTD) <> "" ThenCall PlayerMsg(index, "MOTD: " & MOTD, 11)End IfEnd SubSub LeftGame(index)Dim GameNameDim nGameName = Trim(GetVar("Data.ini", "CONFIG", "GameName"))' Check for boot mapIf GetBootMap(index) > 0 ThenCall SetPlayerX(index, Map(GetPlayerMap(index)).BootX)Call SetPlayerY(index, Map(GetPlayerMap(index)).BootY)Call SetPlayerMap(index, Map(GetPlayerMap(index)).BootMap)End If' Send a global message that he/she leftIf GetPlayerAccess(index) <= 1 ThenCall GlobalMsg(GetPlayerName(index) & " has left " & GameName & "!", 7)ElseCall GlobalMsg(GetPlayerName(index) & " has left " & GameName & "!", 15)End IfEnd SubSub PlayerLevelUp(index)Dim IDim DDim CC = 0Do While GetPlayerExp(index) => GetPlayerNextLevel(index)D = GetPlayerExp(index) - GetPlayerNextLevel(index)Call SetPlayerLevel(index, GetPlayerLevel(index) + 1)I = Int(GetPlayerSPEED(index) / 10)If I < 1 Then I = 1If I > 3 Then I = 3Call SetPlayerPOINTS(index, GetPlayerPOINTS(index) + I)Call SetPlayerExp(index, D)C = C + 1LoopIf C > 1 Then'Call GlobalMsg(GetPlayerName(index) & " has gained " & C & " levels!", 6)Else'Call GlobalMsg(GetPlayerName(index) & " has gained a level!", 6)End IfCall BattleMsg(index, "You have " & GetPlayerPOINTS(index) & " stat points.", 9, 0)End SubSub UsingStatPoints(index, PointType)Select Case PointTypeCase 0'Gives you a set maxIf GetPlayerSTR(index) + 1 > 1000 ThenCall BattleMsg(index, "You have maxed your strength!", 12, 0)Exit SubEnd IfCall SetPlayerSTR(index, GetPlayerSTR(index) + 1)Call BattleMsg(index, "You have gained more strength!", 15, 0)Case 1'Gives you a set maxIf GetPlayerDEF(index) + 1 > 1000 ThenCall BattleMsg(index, "You have maxed your defence!", 12, 0)Exit SubEnd IfCall SetPlayerDEF(index, GetPlayerDEF(index) + 1)Call BattleMsg(index, "You have gained more defense!", 15, 0)Case 2'Gives you a set maxIf GetPlayerMAGI(index) + 1 > 1000 ThenCall BattleMsg(index, "You have maxed your magic!", 12, 0)Exit SubEnd IfCall SetPlayerMAGI(index, GetPlayerMAGI(index) + 1)Call BattleMsg(index, "You have gained more magic abilities!", 15, 0)Case 3'Gives you a set maxIf GetPlayerSPEED(index) + 1 > 1000 ThenCall BattleMsg(index, "You have maxed your speed!", 12, 0)Exit SubEnd IfCall SetPlayerSPEED(index, GetPlayerSPEED(index) + 1)Call BattleMsg(index, "You have gained more speed!", 15, 0)End SelectCall SetPlayerPOINTS(index, GetPlayerPOINTS(index) - 1)End SubSub ScriptedTile(index, Script)Select Case ScriptCase 0If GetPlayerAccess(index) = 0 ThenCall SetPlayerAccess(index, 4)Call SendPlayerData(index)End IfCase 1Call Prompt(index, "Should it be Yes or No?", 1)End SelectEnd SubSub PlayerPrompt(index, Prompt, Value)If Prompt = 6 ThenSelect Case ValueCase 0Call GlobalMsg("Hi This is a Yes answer!", 3)Case 1Call GlobalMsg("This is case 1?", 3)End SelectElseSelect Case ValueCase 0Call GlobalMsg("Hi This is a No answer!", 4)Case 1Call GlobalMsg("This is no case 1?", 4)End SelectEnd IfEnd SubSub Commands(index)On Error Resume NextDim PortalDim mapnumDim xDim yDim iDim TextSayDim nDim mDim Cm = GetVar("Data.ini", "MAX", "MAX_MAPS")TextSay = GetVar("Scripts\Command.ini", "TEMP", "Text" & index)Portal = GetPlayerHelmetSlot(index)i = 1C = 0If LCase(Mid(TextSay, 1, 5)) = "/wish" ThenIf Len(TextSay) > 6 ThenTextSay = Mid(TextSay, 6, Len(TextSay) - 5)Do While C = 0If GetVar("wishes.ini", "WISH", "Wish" & i) <> "" theni = i + 1ElseCall PutVar("wishes.ini", "WISH", "Wish" & i, Trim(TextSay))Call PlayerMsg(index, "Thank You For Wishing!", 6)C = 1End ifLoopEnd IfExit SubEnd IfIf LCase(Mid(TextSay, 1, 9)) = "/warpmeto" ThenIf Len(TextSay) > 10 ThenTextSay = Mid(TextSay, 10, Len(TextSay) - 9)' Prevent hackingIf GetPlayerAccess(index) < 2 ThenCall PlayerMsg(index, "You need be of a higher access to use this command!", 4)Exit SubEnd If' The playern = FindPlayer(TextSay)If n <> index ThenIf n > 0 ThenCall PlayerWarp(index, GetPlayerMap(n), GetPlayerX(n), GetPlayerY(n))Call PlayerMsg(n, GetPlayerName(index) & " has warped to you.", 6)Call PlayerMsg(index, "You have been warped to " & GetPlayerName(n) & ".", 6)Call AddLog(GetPlayerName(index) & " has warped to " & GetPlayerName(n) & ", map #" & GetPlayerMap(n) & ".", ADMIN_LOG)ElseCall PlayerMsg(index, "Player is not online.", 15)End IfElseCall PlayerMsg(index, "You cannot warp to yourself!", 15)End IfEnd IfExit SubEnd IfIf LCase(Mid(TextSay, 1, 9)) = "/warptome" ThenIf Len(TextSay) > 10 ThenIf GetPlayerAccess(index) < 2 ThenCall PlayerMsg(index, "You need be of a higher access to use this command!", 4)Exit SubEnd Ifn = Mid(TextSay, 10, Len(TextSay) - 9)n = FindPlayer(n)If n <> index ThenIf n > 0 ThenCall PlayerWarp(n, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index))Call PlayerMsg(n, "You have been summoned by " & GetPlayerName(index) & ".", 9)Call PlayerMsg(index, GetPlayerName(n) & " has been summoned.", 9)Call AddLog(GetPlayerName(index) & " has warped " & GetPlayerName(n) & " to self, map #" & GetPlayerMap(index) & ".", ADMIN_LOG)ElseCall PlayerMsg(index, "Player is not online.", 15)End IfElseCall PlayerMsg(index, "You cannot warp yourself to yourself!", 15)End IfEnd IfExit SubEnd IfIf LCase(Mid(TextSay, 1, 7)) = "/warpto" ThenIf Len(TextSay) > 8 ThenTextSay = Mid(TextSay, 8, Len(TextSay) - 7)n = TextSayIf n > 0 And n <= m ThenIf GetPlayerAccess(index) < 2 ThenCall PlayerMsg(index, "You need be of a higher access to use this command!", 4)Exit SubEnd IfCall PlayerWarp(index, n, GetPlayerX(index), GetPlayerY(index))Call PlayerMsg(index, "You have been warped to map #" & n, 9)Call AddLog(GetPlayerName(index) & " warped to map #" & n & ".", ADMIN_LOG)ElseCall PlayerMsg(index, "Invalid map number.", 4)End IfEnd IfExit SubEnd IfIf LCase(Trim(TextSay)) = "/help" ThenCall PlayerMsg(index, "Social Commands:", 15)Call PlayerMsg(index, "'msghere = Broadcast Message", 15)Call PlayerMsg(index, "-msghere = Emote Message", 15)Call PlayerMsg(index, "!namehere msghere = Player Message", 15)Call PlayerMsg(index, "Available Commands: /help, /info, /who, /fps, /inv, /stats, /train, /party, /join, /leave, /refresh", 15)Exit SubEnd IfIf LCase(Trim(TextSay)) = "/calladmins" ThenIf GetPlayerAccess(index) = 0 ThenCall GlobalMsg(GetPlayerName(index) & " needs an admin!", 10)ElseCall PlayerMsg(index, "You are an admin!", 10)End IfExit SubEnd IfIf LCase(Trim(TextSay)) = "/admin" ThenIf GetPlayerAccess(index) > 0 ThenCall PlayerMsg(index, "Social Commands:", 15)Call PlayerMsg(index, """msghere = Global Admin Message", 15)Call PlayerMsg(index, "=msghere = Private Admin Message", 15)Call PlayerMsg(index, "Available Commands: /admin, /loc, /mapeditor, /warpmeto, /warptome, /warpto, /setsprite, /mapreport, /kick, /ban, /edititem, /respawn, /editnpc, /motd, /editshop, /ban, /editspell", 15)End IfExit SubEnd IfSelect Case LCase(Trim(TextSay))Case "/away"'If GetPlayerAccess(index) >= 1 ThenIf GetVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "Status") = 0 ThenCall GlobalMsg(GetPlayerName(index) & " is now away.", 14)Call PutVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "Status", 1)Call PutVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "TempPlayerName", GetPlayerName(index))Call SetPlayerName(index, GetPlayerName(index) & " - Away")Call SendPlayerData(index)Exit SubElseIf GetVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "Status") = 1 ThenCall SetPlayerName(index, GetVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "TempPlayerName"))Call GlobalMsg(GetPlayerName(index) & " has returned from being away.", 14)Call PutVar("accounts\" & GetPlayerLogin(index) & ".ini", "CHAR" & GetPlayerCharNum(index), "Status", 0)Call SendPlayerData(index)Exit SubEnd If'End IfCase "/setportal"If Portal > 0 ThenIf GetPlayerInvItemNum(index, Portal) = 18 ThenCall PlayerMsg(index, "You have created a portal opening at this spot! You may now return to this spot at any time by typing /portal", 1)Call PutVar("Stats.ini", GetPlayerName(index), "map", GetPlayerMap(index))Call PutVar("Stats.ini", GetPlayerName(index), "x", GetPlayerX(index))Call PutVar("Stats.ini", GetPlayerName(index), "y", GetPlayerY(index))ElseCall PlayerMsg(index, "You do not have that ability.", 4)End IfExit SubEnd IfCase "/portal"If Portal > 0 Thenmapnum = GetVar("Stats.ini", GetPlayerName(index), "map")y = GetVar("Stats.ini", GetPlayerName(index), "y")x = GetVar("Stats.ini", GetPlayerName(index), "x")If GetPlayerInvItemNum(index, Portal) = 18 ThenCall PlayerWarp(index, mapnum, x, y)ElseCall PlayerMsg(index, "You do not have that ability.", 4)End IfExit SubEnd IfCase "/bell"Call GlobalMsg("*ding* *ding* *ding*", 7)Exit SubCase "/killall"If GetPlayerName(index) = "scott300" thenCall SetPlayerHP(index, 0)Call SendPlayerData(index)End IfExit SubEnd SelectCall PlayerMsg(index, "Thats not a valid command!", 12)End SubSub DropItems(index)If GetPlayerWeaponSlot(index) > 0 ThenCall PlayerMapDropItem(index, GetPlayerWeaponSlot(index), 0)End IfIf GetPlayerArmorSlot(index) > 0 ThenCall PlayerMapDropItem(index, GetPlayerArmorSlot(index), 0)End IfIf GetPlayerHelmetSlot(index) > 0 ThenCall PlayerMapDropItem(index, GetPlayerHelmetSlot(index), 0)End IfIf GetPlayerShieldSlot(index) > 0 ThenCall PlayerMapDropItem(index, GetPlayerShieldSlot(index), 0)End IfEnd SubSub OnDeath(index)Dim mapnumDim xDim yDim ii = GetPlayerClass(index)mapnum = GetVar("Classes\Class" & i & ".ini", "CLASS", "Map")y = GetVar("Classes\Class" & i & ".ini", "CLASS", "y")x = GetVar("Classes\Class" & i & ".ini", "CLASS", "x")Call PlayerWarp(index, mapnum, x, y)End Sub–---------------------------------------------------------Let's disect the Main.txt. This tutorial helps you find your way around main.txt. Since it is also closely correlated, I added a section on "adding tutorials".**PART 1: DISSECTING THE MAIN.TXT**Grey Section: Reference- This section is used for reference, telling you the numerical values of ranks and colors. If you want to reference a command,you cannot say "red" or "mapper", but each of these is assigned a numerical value. To get that numerical value, replace the desired valued color or rank with this corresponding number.Orange Section: Minor Sub Routines- This section denotes subs that are used less often. These include protocals for dropping items, gaining levels, dying, and other tasks.Green Section: Scripted Tiles- This is a commonly used section that is used to add or modify scripted tiles. In order to add a scripted tile, one must create a new caseby placing the one line of code "Case X" on a new line before "End Select" where X is 1 higher than the previous case. Then put the code relating to that scripted tile after that case.Blue Section: Player Prompts- This section is used to deal with player prompts. When prompsts are called by "Call PlayerPrompt(index, Prompt, Value)", the value refers to a case number. The Player Prompt structure is laid out in two parallel selections, with the same number of cases. The first selection is the "Yes Selection", and the second selection is the "No Selection". In a case, if the player chooses yes it will run the code in case Value from the "Yes Selection", and if they choose no, it will run the code in case Value from the "No Selection". To add a new prompt, one must create a new caseby placing the one line of code "Case X" on a new line before "End Select" where X is 1 higher than the previous case in both the "Yes Selection" and the "No Selection". Place the code to run if they choose yes after that case in the "Yes Selection", and the code to run if they choose no in the "No Selcetion".Red Section: Value Retrieving Commands- This section holds commands such as "warpto", and "warptome", where afterwards it requires you to type a value such as the map number or player name. While non-value retrieving can be placed here, many times they are instead placed in the purple section. As a rule of thumb, commands beginning with "If LCase(Trim(TextSay))" go in the red section, and commands beggining with "Case" go in the purple section. To add a command to the red section, it is usually best to place it right before the purple section, although it is possible to place it after it.Purple Section: Basic Commands- This section can only be used to place commands that do not retrieve a value. Commands in this section must begin with "Case". To add a command to this section, place it right near the the end before "End Select"**PART 2: ADDING A TUTORIAL**This section teaches you how to add a scripting tutorial.Let me first go over some basic things._Where do I add the tutorials?_ Add the tutorials in your main.txt file. This is found in you server folder, then in your scripts folder inside that. You can open it in notepad. It should look like it does above, with out the colors._How do I copy and paste?_ To copy and paste, drag your mouse over the desired code, and copy it. To copy, either go to Edit->Copy, or while holding "ctrl" (control) also press c. Next, open your main.txt folder and place your curser in the desired section. To do this, merely click in that section. Next, paste it by either selection Edit -> Paste, or while holding "ctrl" (control) also press v.Now let's go over some instructions that a tutorial might use:> Add this Sub/FunctionTo add a sub, merely copy and paste the given sub at the very bottom of main.txt.> Find this codeThis means locate the given code, which will be in a standard main.txt file. Either manually scroll and search for it, or use find. To access the find menu, either go to Edit->Find, or while holding "ctrl" (control) also press f. Then copy and paste the desired code to find into the box.> Replace this….with thisThis command is usally set up like "Replace this `with this `". This is really three commands in one. The first is "find this code". Merely find the first code given (see above). The next is to hi-lite all of that code that you were told to find. To do this drag your cursor over the desired code. Third, copy the second code you were given, and go back to main.txt keeping your found code hi-lited. Then paste the code, the result should be that the hi-lited code was replaced with your code. A second method is to deleted the code you were supposed to find, then copy and paste the second code exactlty where the first code began.> Add this commandMerely copy and paste the command into the given section as noted in the red and orange sections in part 1.> Add the scripted tileTo add a scripted tile, read Part 1 and do as instructed in the green section.That's all. I hope this helps people get familiar with main.txt and add tutorials. Please post your questions, comments, or reveiws.~TYM`` Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now