0

I'm working on a game bot. I'd like to place there something like a scripter, my program is reading all the needed stuff from the game's memory and I've got all of game-objects. I'd like to add something to my program that allows user to make his own scripts.

eg.

foreach (character ch in characters_on_screen)
{
if (ch.burning()) {game_say("burning!");}
}

I don't really know if it's hard to make, thats why I'm writing here :P, I'm working in c# and the scripter language doesnt really matter I think, coz all the game scripts arent going to be hard i think So whats the easiest way to do that? (if theres any) Thanks :)

p.s. I'd also like to know if there's a way to disable several functions, like creating files or so.

Patryk
  • 3,042
  • 11
  • 41
  • 83

4 Answers4

2

Check out csscript.

Krumelur
  • 31,081
  • 7
  • 77
  • 119
2

There are several options you could go with.

  1. If you want to create a really specialized scripting language, you'd basically have to implement one. That would require either creating semantical, lexical, syntactical analyzer that would translate your string input into a delegate chains.
  2. Is you want to create a really specialized language without a fuss, you could search for existing frameworks.
  3. You could use existing programming language to describe actions, like C# (and use Roslyn compiler), FreePascal, JS, Python/Ruby (and use DLR scripting engines to execute ruby/python code).

I'd personally go with python/ruby implementation. They're dynamic languages that have enough power and capability to be customized into a specific language.

You would probably also want to look at the following SO posts: this and this.

Community
  • 1
  • 1
Dmitry Reznik
  • 6,812
  • 2
  • 32
  • 27
1

You can also get the C# compiler to compile C# code at runtime. Check out the runtime compliation classes in the Microsoft.CSharp namespace.

There's also a tutorial here.

This way you could attempt to santise the input if you so wish; it simply takes in strings. As well as imposing restrictions like implementing an interface.

Alexander R
  • 2,468
  • 24
  • 28
  • thanks, Your answer seem to be the simplest one and that's what I've been looking for, im a newbie :P :) – Patryk Apr 03 '12 at 06:51
1

I'd go with JavaScript. It's safer (eg. No filesystem access) and easy to write for. JavaScript .NET is a nice wrapper around the V8 engine.

There's also the IActiveScript COM interface that can be used to host any COM-based scripting language that implements IActiveScript (eg VBScript, JScript [both the older 5.x and the newer 9.x {Chakra}])

Sam Axe
  • 33,313
  • 9
  • 55
  • 89