News:

SMF - Just Installed!

Main Menu

LUA-question

Started by doublejack, September 03, 2012, 03:22:17 PM

Previous topic - Next topic

doublejack

Hello! I have read a post about LUA-modules and want to help with development, if I can.
I have lua-coding experience and a lot of ideas for knights game so I'll be really happy to help.

Can anyone show me where I can script and maybe some examples so I could understand how the whole knights thing works.

thanks.
sorry if there are some mistakes, English isn't my native language.

K9

You're English seems great! 

Thank you for the interest in coding Lua game enhancements for Knights.

I have played this game for many years and seen Stephen do amazing things with this game, reborn from Amiga version.

All hardcore fans are excited to see new possibilites opened with Lua.

I am responding now, to tell you from a player perspective, about our excitement for your post.

The last thing I read is that Stephen Is still perfecting the system for Lua integration and hasn't released the version ready for development yet.

He will probably post a reply to you with answers to your questions.

Thanks again, I hope we can see you on our weekend games.

Check the server list and join the fun to see what it's like with a great group of Knights battling in unique, often hilarious dungeon quests.

Stephen

Welcome!

Unfortunately the Lua support is not released yet. It is coming in the next release of Knights, which will happen fairly soon (probably 1-2 weeks from now).

I would suggest you wait until then.

In the meantime, there is some documentation here: http://www.knightsgame.org.uk/trac/wiki/lua but I don't know if it will be much use at this point.

Maybe the best way is if you told us what kind of things you want to add? I could then give you some hints about how to do it. But, like I said, we have to wait for the new release first :)

doublejack

Yes, as I said I have ideas but first of all I'll be happy to create something for users, I mean something that they want or suggested here, maybe some new game modes, monsters and other.
But I understand that the game is yours and I would not try to change the whole game system or try to turn it in something totally new. I think people like knights game and want to see some upgrades/improvements but not global changes.
I'll try to discuss with you all ideas so if you like them too you would be able to add them to next game versions.

But if you interested in my personal ideas, I think that it would be great to make some really teamplay-oriented game modes like defense(survival) where all players are trying to defend their spawn/fortress from being destroyed by hordes of zombies and swarms of bats or maybe capture the flag mode with two teams... but I have to repeat - there are my personal ideas and I would work on them only if you like it as developer and if the community like it.

so I'll TRY to help you in development. I think that it's no sense in creating stuff that would not be added in game, so hope I would be able to help and maybe one day become a part of the knights game development team

thanks

ImpassIve

#4
doublejack
"But I understand that the game is yours and I would not try to change the whole game system or try to turn it in something totally new."

Sorry, but I can't agree with you at that point.

Modding is an unofficial part of the game. So, if you want to make something cool, but conflicting with main idea - you should try to do that...
It is most likely that such mod wouldn't be imported to official game in later releases, but this game supports unofficial servers (see "Download" page), so I don't see any problem.

I can cite as a good example the game "Cortex Command". It is almost 90% moddable (all "standart" units/scripts were written in the same way as mods which you can create just by using notepad and photoshop). Now, there are 700+ available mods and some of them are really cool!

I hope that new modding system in "Knights" will have the same success. But we need people who would make all those mods, because without them this feature would be purposeless.
I am glad that you are willing to participate in the present case)




doublejack

...but I still think that it is better to help with official development now.
maybe sometimes when knights would have at least 10-15 players online always it would be good idea to create mods and separate servers for them.
anyway, Stephen looks like developer ready for innovations and game enlargement so I hope there would not be problems with official modding:)

Stephen

Personally, I am happy for all types of mods to be made. New quests, new game modes, new monsters or items... whatever you want really.

There is not really any difference between "official" and "unofficial" development. Anyone can make a mod. If you make a mod, and people like the idea, then I will put it up on the official server. (We could then test it during our weekly game perhaps.) This is easy enough to do, and it doesn't need a new release of Knights -- I can just install the files on the server and it will be available straight away.

Eventually, some mods might become an "official" part of Knights, but let's wait until some mods are actually made before thinking about that :)

K9

Development and enhancements to Knights are exciting, either way you call it (i second Stephen's and ImpassIve_rus's comments)

As a DB Coder (programmer at heart) i also really respect your point of view about ownership, and your direction toward honoring the existing crowd.

That is very cool approach, I am sure everyone will enjoy playing your ideas and seeing previous suggestions come to pass as well.


Thank you.

ImpassIve

#8
Well, now I have one question about lua scripting.

In this game, when you become invulnerable - you get a special addition to sprite of your knight (something like new armor).

Is there any way to make something like that by mod?

(In my mod, some players should have a crown or helmet sprites on their knights).
If that is not possible, well... that is not so necessary.


P.S. Also, is there any way to increase default knight's health?

P.P.S. I found how to make player win (kts.WinGame), but how can I eliminate him?

P.P.P.S. I have tried to use some hooks but my function was never called... Also, I checked tutorial files and have found only "on_pickup" etc. functions but no hooks... Are they working now?




Stephen

Quote from: ImpassIve_rus on September 06, 2012, 08:41:58 AM
In this game, when you become invulnerable - you get a special addition to sprite of your knight (something like new armor).

Is there any way to make something like that by mod?

(In my mod, some players should have a crown or helmet sprites on their knights).
If that is not possible, well... that is not so necessary.

Currently this is not possible. I could add it, but if it's not important then I'll wait until some other time.

Quote
P.S. Also, is there any way to increase default knight's health?

kts.MISC_CONFIG.knight_hitpoints = 10    -- or however many hit points you want

Not tested but it should work :)

Quote
P.P.S. I found how to make player win (kts.WinGame), but how can I eliminate him?

Not possible currently. I can add "kts.EliminatePlayer", that would be easy to do.

Quote
P.P.P.S. I have tried to use some hooks but my function was never called... Also, I checked tutorial files and have found only "on_pickup" etc. functions but no hooks... Are they working now?

It should be working. Have you tried a simple hook that only does a "print"? Maybe post your code and I can try to figure out what's wrong?

ImpassIve

#10
1) No, this feature is not necessary. Mod can work even without this.
2) Ok, I will try this, but this is not so important for me too...
3) Yeah, EliminatePlayer would be nice...
4) Lol. Looks like I have found, where was the problem.
Before that, I had tried to put "kts.HOOK_KNIGHT_DAMAGE = knight_damage_f" in "features" part of menu (because this hook should be installed only if my mod was selected in menu) - everything worked, except hooks.
5 minutes ago I tried to move it into initial part of my lua... now it works. But, sure, that hook is called even if my mod wasn't selected in menu. But that problem seems solvable.




ImpassIve

#11
Hm... but I have got some more questions now))

1) How differs "cxt.actor" and "cxt.originator", for example while executing function <item>.on_pick_up or <item>.on_drop ?
because kts.GetNumHeld(cxt.originator, i_revive_gem) -- causes an error "bad userdata"
kts.GetNumHeld(cxt.actor, i_revive_gem)  --working fine.

But in the same time

kts.SetRespawnFunction(respawn_func)
...
function respawn_func (player)
...
for i=1,#heroes do
    if (heroes[i]==player)
           print("hello")
...

prints "hello" only after "table.insert(heroes, cxt.originator)" but not after "table.insert(heroes, cxt.actor)" (both were called in "on_pickup" function)

2) I haven't found in wiki any definition of types returned by "cxt.actor" and some other, so I don't know what to do with it, does it contain some information (e.g. player's nickname, health etc.), or that is just something like number of this knight?




Stephen

Quote from: ImpassIve_rus on September 07, 2012, 01:51:48 PM
1) How differs "cxt.actor" and "cxt.originator", for example while executing function <item>.on_pick_up or <item>.on_drop ?

cxt.actor is a "Creature" while cxt.originator is a "Player".

A "Creature" represents the knight itself. A "Player" represents the person controlling that knight.

If your knight dies, then the old "Creature" object is marked as "dead" and can no longer be used. (You can use kts.IsAlive to find out whether a Creature object is "alive" or "dead".) When you respawn, a completely new Creature object is created for your new knight.

By contrast, "Player" objects are never destroyed -- each player keeps the same Player object all through the game.

If you have a Creature you can get the corresponding Player using kts.GetPlayer. (There is no function to go the other way currently.)

For monsters, it works slightly differently. The Creature object represents the zombie, or bat, or whatever. There is no Player object for monsters. (kts.GetPlayer returns nil if called on a monster.) For monsters, cxt.originator will be set to the string "monster".

Quote
because kts.GetNumHeld(cxt.originator, i_revive_gem) -- causes an error "bad userdata"
kts.GetNumHeld(cxt.actor, i_revive_gem)  --working fine.


kts.GetNumHeld requires a Creature (not Player) as first parameter. That's why it only works with cxt.actor.

Quote
But in the same time

kts.SetRespawnFunction(respawn_func)
...
function respawn_func (player)
...
for i=1,#heroes do
    if (heroes[i]==player)
           print("hello")
...

prints "hello" only after "table.insert(heroes, cxt.originator)" but not after "table.insert(heroes, cxt.actor)" (both were called in "on_pickup" function)

The respawn function has one parameter which is a Player object. Note that when the respawn function is called, there is a Player object, but no corresponding Creature object (their old knight has been destroyed, but the new knight hasn't been created yet).

Quote
2) I haven't found in wiki any definition of types returned by "cxt.actor" and some other, so I don't know what to do with it, does it contain some information (e.g. player's nickname, health etc.), or that is just something like number of this knight?

They are just userdata objects. (Technically, they are pointers to C++ objects.) You can't do anything with them apart from compare them for equality and pass them to "kts" functions.

ImpassIve

Ok, thanks for the answer =)




ImpassIve

#14
Just one more question (or, maybe, a request?) to Stephen.

Since 21th build of Knight isn't released yet, it is possible to add some features to it, right?

Well, I am making (or, at least, trying to make) a new quest type - something similar to deathmatch, but with some new contents, and with different scoring type. That's why I asked about a way to eliminate player. But I have a little trouble right now. Score in standart deathmatch depends on how much players killed each other, but that is not quite correct for this quest.

Atm, I am counting score of each player in a special array, and when player gets one more violet gem (from killed barbarian) - total amount of his gems are displayed by using a flashing message (in the same way as effect of potion).
But he can not compare his score with the opponent's scores, because I don't know their nicknames. I can display only something like
1st player - 0
2nd player - 3
3rd player - 1

So, is that hard to implement a function to retrieve a name from "Player" object?
I think, that may be useful in mods, focused on multiplayer and new quest types.

Also, an ability to operate with Deathmatch scores table (displayed on the upper right side of the screen) would be nice for me, but with feature is a bit more specific, so that is not so important.

If that is not possible for some reason, I would like to ask for advice.
Which way to inform players about their scores is better? (using current functionality)

1) Do not use names at all. For example, display the top score.
2) Use numeric interpretation of players (first, second, third, etc.) - as they are placed in players list.
3) Some graphical interpretation (I don't know)
4) Other