Sign in to follow this  

Attack Scripting?

This topic is 2012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am working on a Turn based Strategy rpg, and one of the issues that I'm having is that In the projects that I've worked on in the past, I have primarily hardcoded almost everything. Now I'm working on making an engine for this game that contains no game specific data, and I'm currently discussing with the other developer about how to implement special attacks and spells, so that we can be more flexible and allow players to modify the game if they wish.

Our first idea was to just read from one of our data files basic information, such as the energy cost of the attack, the AOE, the range,what animation the user should do, what attack animation should hit the target, the damage done (negative for healing), accuracy, and what buffs/debuffs to affect the target on hit.

However, we plan on having a good deal of our skills be a bit more complex than that would be able to handle. But we're at a loss at how to implement a scripting system that would be able to handle more interesting attacks (something like Chain Lightning, or summoning reinforcements for example)

I've heard that LUA might work for this, but we'd prefer to roll our own scripting system out. If someone has experience in this, or can link a relevant article/tutorial about this, I would be grateful. Thanks!

Share this post


Link to post
Share on other sites
I dont think you should make your own scripting language unless its purely for learning purposes, or if its a very simple one (where you call a few predefined functions in different orders or with different values). But if you need to do any logic or have more complex structures in the scripting language just use Lua or something.

Share this post


Link to post
Share on other sites
Yeah, don't roll your own. If you're in this to make a game, why would you waste time writing a language instead? They're complex, and perfecting them is a lengthy process. Lua is lightweight, robust, well-tested and under very active support and development. Not to mention easy as balls to use.

Share this post


Link to post
Share on other sites
LUA does the job fine.

If you absolutely must define your own language, I suggest reading up on parsing: [url="http://en.wikipedia.org/wiki/Parsing"]http://en.wikipedia.org/wiki/Parsing[/url]
Then, you can make your own pseudo-language that is simply used for your game and therefore easily usable:

[CODE]
Filename: ChainLightning.spell

"Chain Lightning"
required $caster $power $cost
decrease MANA of $caster by $cost
select $a in range(4,$caster)
select $b in range(1,$a)
select $c in range(1,$b)
damage $a by $power
damage $b by [$power/2]
damage $c by [$power/4]
[/CODE]

This type of language is easily parsable and readable by the average non-programmer. The disadvantage is the strictness of the syntax and lack of power, obviously.

Share this post


Link to post
Share on other sites
[quote name='Explodinator' timestamp='1339699457' post='4949240']
I suggest reading up on parsing: [url="http://en.wikipedia.org/wiki/Parsing"]http://en.wikipedia.org/wiki/Parsing[/url]
Then, you can make your own pseudo-language that is simply used for your game and therefore easily usable:
[/quote]

This is exactly what we had originally planned, and still might do if we don't decide to work with Lua;

The only problem we're having is deciding how we'd handle more complex abilities, for example:

(Note that Targetting is already handled seperately, assume a legitimate target)
[code]
// Chain Lightning Pseudocode

ChainLightning.effect(Attacker,Target){

Attacker.state = ("Casting")
Draw lightning from the Attacker's sprite to the Target's sprite
Target.state = ("Hurt")
Target takes (Attacker.Intellect / Target.Lightning_Resist) damage
Target.Hit = True
show the damage done on the screen, over the target's head

while(Target is not null)
{
OldTarget = Target
Target = NULL
check tiles within 2 spaces of target
if(tile contains a unit that is hostile to the attacker and has not previously been hit){
Target = found unit
Target takes (Attacker.Intellect / Target.Lightning_Resist) damage
Target.Hit = True
Target.state = ("Hurt")
show the damage done on the screen, over the target's head
}
}

}
[/code]

The problem is that doing very linear and simple spells will be incredibly easy, but anything that requires looping or other special effects will be hard.

Share this post


Link to post
Share on other sites
Well, first off you wouldn't want your chain lightning effect script to actually handle drawing the lightning bolt. That responsibility belongs elsewhere (in the rendering system, however that is structured). The script would merely have access to functionality that would allow the spawning of effects.

Second, the chain lightning effect script shouldn't have the responsibility of displaying combat floating text. That also should be handled elsewhere.

Third, the chain lightning effect shouldn't be setting Target state, such as hurt. What if the Target is lightning immune? Why should the effect even care?

Here are the things the chain lightning effect should be responsible for: spawning a visual effect, generating the damage value, and handing some sort of ApplyDamage(DmgValue) message off to the target object. How the Target reacts to that message (is it immune? Does it take double damage? does it cause the target to put on a party hat and dance a little jig?) is all entirely up to the Target.

complex effects can simply be split up into various smaller and simpler effects.

Share this post


Link to post
Share on other sites
[quote name='Silverain Development' timestamp='1339700876' post='4949249']
[code]
// Chain Lightning Pseudocode

ChainLightning.effect(Attacker,Target){

Attacker.state = ("Casting")
Draw lightning from the Attacker's sprite to the Target's sprite
Target.state = ("Hurt")
Target takes (Attacker.Intellect / Target.Lightning_Resist) damage
Target.Hit = True
show the damage done on the screen, over the target's head

while(Target is not null)
{
OldTarget = Target
Target = NULL
check tiles within 2 spaces of target
if(tile contains a unit that is hostile to the attacker and has not previously been hit){
Target = found unit
Target takes (Attacker.Intellect / Target.Lightning_Resist) damage
Target.Hit = True
Target.state = ("Hurt")
show the damage done on the screen, over the target's head
}
}

}
[/code]
[/quote]

Ok, you seem to not understand what I was getting at. You need to generalize what you're doing as much as possible in the context if your game, not write a new language.

That means things like variables, loops, properties, etc. should be kept to a minimum. You define a set of rules in the context of your game and have your parser execute the programming logic.

Share this post


Link to post
Share on other sites
[quote name='FLeBlanc' timestamp='1339702008' post='4949252']
Well, first off you wouldn't want your chain lightning effect script to actually handle drawing the lightning bolt. That responsibility belongs elsewhere (in the rendering system, however that is structured). The script would merely have access to functionality that would allow the spawning of effects.

Second, the chain lightning effect script shouldn't have the responsibility of displaying combat floating text. That also should be handled elsewhere.
[/quote]

Of course, the thing is though, that I will still need to know what information to send to the drawing/sound systems, and that's what I was trying to show in my example. I'm kind of regretting posting this Pseudocode as it was a pretty bad example of what I'm trying to do.

[quote name='Explodinator' timestamp='1339702373' post='4949255']
Ok, you seem to not understand what I was getting at. You need to generalize what you're doing as much as possible in the context if your game, not write a new language.

That means things like variables, loops, properties, etc. should be kept to a minimum. You define a set of rules in the context of your game and have your parser execute the programming logic.
[/quote]

The Pseudocode isn't anywhere near what I envisioned the actual parsing system should look like, it is more of what I need to do for this particular example. I know that my scripting system will need to be generalized regardless, but I will probably need loop functionality anyway for certain abilities.

Regardless, I think I've figured out how I'm going to approach this, and I'd like to thank everyone who helped me here.

Share this post


Link to post
Share on other sites
You could create an XML based system. There are plenty of XML tools available (meaning you won't have to write your own parser) and it's pretty trivial to write something to extract your information from the XML.

Share this post


Link to post
Share on other sites

This topic is 2012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this