Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] Basic Fantasy Role-Playing Game (Alpha)

I've been using Roll20 as an excuse to get a little dirty with Javascript, a language that I've used for years but never bothered to master. I've also been GMing some old-school retroclone lately using Basic Fantasy Role-Playing Game. This has resulted in some extremely over-engineered code for handling a bit of the PC creation and game management. Even though this is far from done, and there are some pretty nasty JS faux-pas going on, I figured I'd share it to get feedback or perhaps inspire ideas in others. BFRpg.js is the bulk of the code I'm presenting. Its defines prototypes and helper functions for PCs, StatBlocks, Races and Classes. I've also defined the base races (dwarf, halfling, elf, and human) and classes (fighter, cleric, magic-user, and thief). Helper functions for Race and Class are able to identify legal choices based on StatBlock and (for class) Race. I've also included the concept of concordance , a naive distance measurement from the ideal - basically it attempts to calculate 'how dwarf-ish / elf-ish / fighter-ish etc, is a character's StatBlock). This provides the ability to build random characters that make sense. I've also implemented random name generators, based on race. Each race can define forenames and surnames as nested arrays of name components that will be concatenated at random. Forenames are further broken down into Male and Female. I've begun adding some of the tables for classes but don't do anything with them yet. You'll notice right at the top I muck about with the Function and String global level prototypes. Don't do that, its bad. I'll fix it at some point. <a href="https://gist.github.com/goblinHordes/7227708" rel="nofollow">https://gist.github.com/goblinHordes/7227708</a> BFRpg.chargen.js is just an on chat:message wrapper around the BFRpg.PlayerCharacter.random helper function. By issuing a !random_pc command in chat a new character will be spun up. JSON can be passed in that call to set specific features of the randomly generated PC. For instance !random_pc {"sex":"male", "class:dwarf"} would generate a random male dwarf. I've commented out the section that creates a new R20 Character from the PC since its still in debugging stages and its annoying to have to delete all the characters I create. I still need some error handling, you can easily cause an infinite loop by requesting an illegal character build such as a Dwarf Magic-User. <a href="https://gist.github.com/goblinHordes/7228010" rel="nofollow">https://gist.github.com/goblinHordes/7228010</a> I plan on adding Items, Weapons and Armor, as well as inventory management and Macro generation for attacks. I've got some work done on parsing NPC and monster statblocks for easily adding creatures for the PCs to fight as well, along with their macros. Hopefully I'll have more to show in the next few weeks. I still want to get back to my ActiveToken project as well, but I've left that alone since its in a working state. Let me know if you find any of this useful or have constructive criticism of my early JS experiments.
1383140869
Pat S.
Forum Champion
Sheet Author
Now that is sweet. I run BFRPG games here and this is looking very nice. Keep up the good work.
1383708807

Edited 1383708904
Peter R.
KS Backer
Hi! How hard would be to alter this to fit the Swords and Wizardry OSR rules? Peter
For me or for you? As it stands now, it'd be fairly trivial since it doesn't really do much. I barely have time to work on it for myself, though, so I wouldn't get around to it for a while. I've got Swords and Wizardry Complete and could look at porting it once I've made more progress on the BFRPG version. One of my goals was to keep the design loosely coupled so that I could eventually refactor and reuse object prototypes to support multiple games - S&W was actually the other one on my list. I started with BFRPG since it is quite a bit more basic and open source. S&W has an open SRD which would be useful in making such a port. A couple of big things that would need to be implemented: Multi-classing - BFRPG has this, too, with Fighter/Magic-User being listed as an option for Elves and generally accepted for other races. I don't currently have any type of multi-class support. I'm planning on implementing this by making PlayerCharacter.class an array and ensuring the character meets all class requirements before leveling. This is different than how multi-class works in S&W so it'd need to be adapted. More variety in class features - S&W classes have more unique features: Monks earn abilities at different levels, fighters have parry skills, Rangers get a blend of Clerical and Magic-User spells. These things can be fitted into the Class prototypes I've got now, but may require some finesse. Racial variation to class skills - In S&W thieves have different TNs for skills based on their race. This actually effects BFRPG as well - halflings have different modifiers for hiding and moving silently. Just something I haven't implemented yet.
John M. said: For me or for you? As it stands now, it'd be fairly trivial since it doesn't really do much. I barely have time to work on it for myself, though, so I wouldn't get around to it for a while. I've got Swords and Wizardry Complete and could look at porting it once I've made more progress on the BFRPG version. One of my goals was to keep the design loosely coupled so that I could eventually refactor and reuse object prototypes to support multiple games - S&W was actually the other one on my list. I started with BFRPG since it is quite a bit more basic and open source. S&W has an open SRD which would be useful in making such a port. A couple of big things that would need to be implemented: Multi-classing - BFRPG has this, too, with Fighter/Magic-User being listed as an option for Elves and generally accepted for other races. I don't currently have any type of multi-class support. I'm planning on implementing this by making PlayerCharacter.class an array and ensuring the character meets all class requirements before leveling. This is different than how multi-class works in S&W so it'd need to be adapted. More variety in class features - S&W classes have more unique features: Monks earn abilities at different levels, fighters have parry skills, Rangers get a blend of Clerical and Magic-User spells. These things can be fitted into the Class prototypes I've got now, but may require some finesse. Racial variation to class skills - In S&W thieves have different TNs for skills based on their race. This actually effects BFRPG as well - halflings have different modifiers for hiding and moving silently. Just something I haven't implemented yet. Hi! Hehe, for us both I guess. Although as a rookie to scripting, its far easier for you I suspect. ;) I'm a big believer in trying to do this yourself (or myself in this case). Since I have your ear for the moment, what would you consider the most efficacious way to learn javacript? I'm pretty committed in learning, since I see a lot of potential in doing what you are currently trying to do. I'm gearing up to run a greyhawk based game using S&W to run the rappan athuk super dungeon. I think scripting can aid me in making a lot of nice personal touches. Any suggestions or recommendation are infinitely appreciated. :) Peter
Alright Peter, I'm not the best person to ask about how to get into Javascript. Although I've been programming for nearly 20 years, and using Javascript (lightly) since it first appeared, I've only really begun to dig into some of its more advanced uses. Since I'm already familiar with programming techniques, learning a new language is basically just a matter of applying what I already know and figuring out the quirks of the new tool. And Javascript has plenty of quirks. To be honest, I've always found Javascript to be a pretty dreadful language, and while I understand why the Roll20 team uses it for their scripting API (it really is a great choice, though maybe Lua would be better) my recent experience hasn't changed my opinion too greatly. That said, maybe I can help you along your way. To start with, you probably don't want to jump into the BFRPG code, as it is an exercise I'm using to get a handle on the prototypal object oriented design of Javascript. If that last sentence didn't make sense to you - you really don't want to start there. You need to make sure you get a handle on the basics first: What are variables, functions, and objects. What is and array and why are they indexed starting with 0 instead of 1? What is a variable's scope, why do you care, and how do you control it? If you're comfortable with those questions you're ready to start solving problems by programming. It helps to have a clear goal in mind, broken down into simple steps. Remember, programming is just applied logic - you're going to provide inputs, process them according to a set of rules, and output the result. Every task a computer does is broken down into discreet logical units. Start with simple problems and work your way up to the big ones by combining those smaller steps. One of the challenges you'll run into with learning Javascript is that for most of it's existence it's primary use has been in scripting for web browsers. Most tutorials focus on modifying the DOM (Document Object Model), basically the programmatic representation of a webpage that a browser maintains. This is what allows Javascript to make images appear or disappear, move text around, validate forms before you submit, etc. Although you load scripts into the Roll20 API using your browser, they are actually running on a server - there is no DOM, you cannot interact directly with the player's browsers, it really is a different world than 99% of what Javascript is used for. Once you get past the very basics listed above, you're going to want to look for tutorials that focus on server-side or command-line scripting. Something that I've always found helpful, both for new programmers and even those working with a new language, is having a quick way to test simple programs. For Javascript, <a href="http://jsfiddle.net" rel="nofollow">http://jsfiddle.net</a> will allow you to type in basic scripts and get immediate and visible results by running them in your browser. Again, this is browser based, so the DOM does exist and you can interact with the browser, so its not exactly like what your API scripts will be running in. But its a great place to try things out to make sure you have a handle on the basics. Feel free to private message me if you want to bounce ideas off of somebody. I'd be glad to give you pointers on how to break your ideas down to manageable units or explain JS features if you need.
Hi! Much appreciated John! I'll start with the basics then and work my way up. What I would ultimately try to achieve is not that much different than what your doing with BFRPG, only for S&W. Perhaps throw some random encounter tables in there, but not a whole lot more. I'll be using what you have done to start the campaign and try to make small modifications over time. Right now all I really need is a S&W centric character sheet, everything else can wait. :) Peter
I am starting with two options one listed in the API Wiki for roll20, CodeAcademy and then also JavaScript Diaries as the primers. I did download ebooks to support the latter. I do have some familiarity with scripting being a Systems Engineer for the last 25 years, so some VB, and extensive powershell. But this is a bit of a beast of another color. John's work so far has truly inspired me, but realistically there are many pitfalls within the code that experience accounts for, so there is a large difference for John to learn code and me to learn it. So I am starting simple, and the links above seem to be just that...
I'm not actually a programmer by trade. I've 'done' programming, script on a daily basis, and work on the softer side of ware, but I'm not a developer by any means. I do have experience with a lot of programming languages and have been lucky enough to work with folks that have instilled a strong principle of 'doing it right' when it comes to coding. Nothing that I've posted for Roll20, so far, is all that advanced (perspective is a funny thing) and I expect that with a bit of effort most anyone here can be pointing out all the places I've gone wrong in my code.
Well then you are certainly on the right track! I do a lot of scripting in powershell for my trade, and worked with VB Script in the day. Never truly latched on to the "Web" languages in the past, but never had a reason to at the time. But now I want to be able to work on this stuff, or be able to read it all so I know where I want to mod things.