Creating a Magic Wand?

I plan on making a wand for a game I’m working on with various people. While I’m sure I could do it by myself, I was hoping for some advice on how to go about it the best way possible.

Essentially it will be a Harry Potter based wand. The player types out the name of a spell with their wand equipped, and then they click to cast it. Each spell will have a variety of different effects and display differently.

I’m thinking of a regular tool with just a simple local script that will pass the inputs to a controlling script in ServerScriptService. That way wands themselves are very simple, and completely useless without that server script.

But the server script is what I’m not entirely certain about. Each spell has a variety of different effects, and considering I plan on making at least 50-100 (with more that are easy to update), I am a bit overwhelmed on deciding the most efficient solution. Some spells with have very similar effects, while others could be vastly different from others, if not unique. Using Harry Potter spells as an example, compare “Stupefy” with “Expecto Patronum”. One is similar to a beam of lightning that affects one target, while the other is multiple ‘shields’ coming from the wand and growing to a certain radius, affecting only certain targets within range. Finding a way to create multiple spells with a large variety of effects, with an easy way to add new spells…idk.

Here is what I’m currently thinking about doing:

Summary

I’m thinking I could just make a ModuleScript containing a function for each spell. It will be passed all the possible arguments it could need and go from there. This would give me the most customization over each spell, however I imagine much of the code for these spells would look the same. This also means it’d be extremely difficult to update how a spell works, as I would have to change each and every ModuleScript.

Alternatively, I could have a ModuleScript with a table of various spells whose data represents how it will act. This would require something like a Yu-Gi-Oh card, in which I think of every possible situation (is the spell travel in a straight line or is it a ‘bubble’ effect, is the spell instant or does it take time to travel/grow, what type of effect does it have, etc). This could make it really easy to add new spells to the game and update how certain spells work. As a side benefit, it could make it easy to add a “custom spell” feature. However, thinking of all the various variables would take a long time to create…

Not sure if I explained this very well. But any tips/suggestions/resources would be super helpful.

8 Likes

Not exactly related, but a warning that Harry Potter is a banned thing on Roblox (explicitly naming it is beaned)

spells are ok though :ok_hand:

11 Likes

You could have all of the spell functions in a single module, couldn’t you?

4 Likes

You could make a single server script and set up a framework I guess, nothing comes easy so it will take some time.

for example:

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        -- do stuff with msg and player
    end)
end)

Tip: You can use --(hint) to organise scripting for each wand and use ctrl + f to search for your wand in your script if you are editing the script. Good luck!

1 Like

If I were going to do this, I would use a modulescript with a dictionary of the spells.
If you had the keys as the name of the spell and a function for each one that takes whatever arguments you need, it would make the whole system very neat imo. You can just check for an index to check if something is a valid spell, and you could pass some preset arguments to each function (player look direction, player power level etc).
That’s how I usually set up systems like that, and it means you can add and edit spells very easily, by just adding a new index and function.

For similar spells you could declare a function independant of the list, and call it for different spells, just with different arguments.

For example:

module = {}

function explodeSpell(direction,size)
    — create orb moving in direction, and explode on impact
end)

module.BigExplosion = function(lookDir)
    explodeSpell(lookDir,20)
end

module.SmallExplosion = function(lookDir)
    explodeSpell(lookDir,10)
end

module.otherSpell = function(lookDir)
    — some other spell
end

return module
5 Likes

My group has an older place which we stopped working on with some spells. I could talk the the others about donating it to this. :3

1 Like

Make a module for each similar effect that takes certain variable inputs:

  • Beams (startpos, endpos, color)
  • Bolts (startpos, velocity, type) --type = fire, ice, earth etc.
  • Shields (startpos, Image pattern, color, radius)

Then for each spell create one module that does the damage, healing logic etc. but still uses these effect modules for FX.

Structure it with folders placed in a structured hierarchy of folders (Spells inside Spells, Effects inside Spells/Effects). I’m sure it’ll look and feel great to work with!

PS. For absolute unique spells you can just smash it all into one module but it’d still be nice if it had a separate fx module (incase u do alot of editing/improvements on that part)

4 Likes