Card game - mini game - for NWN2 - how to do it?

I just thought I’d put this question out there to the community. I would have really liked, if it was possible, to have a card game, like a mini game, inside the module I’m working on at the moment. I searched the vault and found this:

However, this is made for persistent worlds and my module is a single player module.
I’m not smart enough to adapt this whole thing by scripting for a player vs computer(the game) thing.
Therefore I just wanted to ask if there is some mini game like this out there that would be free to use in a module?

I also found this:

but it’s also again for multi player, and you have to come up with your own rules for the card game.

My guess is that this whole thing is way too complicated for me to achieve, so I might have to scratch this idea altogether…but…maybe there are some clever people out there that knows how this could be achieved…or have something to share that’s already out there, I don’t know.

Yes it’s possible but you need to know your stuff with NWN2 GUI.

Well, that doesn’t help me much. I know that you need xml coding for this, if that’s what you are referring to, but I would rather have wanted to somehow convert the card game for persistent worlds (in the link above) to a singleplayer module…but since I hope that you read my whole post and not just the headline of the thread, you should already know that’s what I’m trying to do.

Maybe black jack via a conversation that just uses random numbers between 1 and 10 and adds them together, if you go past 21 you bust then the computer does it but has a random number between 17 and 21 that it will stick at, if it’s higher than yours it wins and takes your money… " Do you want another go ? " " yes " back to the start again. If you get an ace ( 1 ) you get the choice of it being worth 11 or 1 just add 10 to the total.

So create a random int and name it, add to it with the next card, add it up and give the total, do you want another, add the next random int, is that > 21 no, do you want another no, save the number, yes, add another is it > 21 etc. Then do the computer.

Or just have a dice game roll x amount of dice add it up and see who gets the highest you or the computer ( shady looking guy in the tavern ) you could even bet on who gets the lowest instead of highest.

The cards version is a big looking conversation with not much writing but lots of links back to things, all you need is a random number generator per roll, an add function and a few conditions > or < etc.

Or create your own game with a dice that has an orc, goblin, ogre, elf, dwarf and pixie on it ( only examples ) you bet and each one has a different outcome to your money. Get an orc or a goblin you lose your money, an ogre lose double and vice versa with the other three.

Or the all time classic Russian roulette, that’s just random numbers too but a bit more lethal, could be that for every shot missed you get a lot of money but get the wrong one and it’s death ( big cash penalty for a respawn ).


@Tsongo - That was a bunch of really good ideas, actually.

I already have a dice game that I used in my third module and that I’m also using in this one.

My ideas for this module was that one of the companions is good at card games and the PC might want to have a crack at it. A way of bonding with the companion.

It’s been so long since I played cards myself that I don’t remember any game. Black Jack, now that you describe it, seems very familiar and simple though. I wonder if one could somehow take what’s in the:

and somehow change it to Black Jack then that would be the ultimate idea, I think. Something simple but yet with a bit of graphics.

I would think that maybe @Lance_Botelle already has something like this in his modules, but if he has, I don’t know if he would like to share such a thing. I know it must be a tremendous amount of work on a thing like this, and maybe the creator wants it to be unique to his/her module.

Looking at the persistent world card game, it’s a bit overwhelming. I think I would need to rework the whole thing and that requires a lot of xml coding, which I suck at. I wish I could just have a background and spaces where to put the cards and then the game would dra random cards, and then somehow one could maybe code so that the game counts if you win or lose against the oponent (in this case the companion). So something simple like that, just like Tsongo described, but even that seems to be quite hard to do.

I think this may be a bit too much over my head…I might try some things, but I think I won’t be able to do this on my own.

Ah, well. It was nice to dream, I guess.


Depending on the type of card game you have in mind will determine the overall complexity. That may sound like stating the obvious, but let me try to explain that some more …

XML … The amount of XML coding is only really governed by what you need to display (not the actual contents as such). Therefore, having a game that simply shows a few cards at a time will require less XML coding than something that requires many cards on show at once. e.g. A game of Blackjack (also called “21” in some places) requires only two “hands of cards” to be shown at any given time. Bridge on the other hand requires many more cards to be on show. However, even Blackjack may require a hand to show more than 5 cards at a time, unless you limit the game to a given number of cards.

SCRIPT … This is where much of the grunt work actually takes place. For once we have the XML setup to be ready to display certain cards or not, we then need the code behind it to say which cards are going to be set in the XML locations. If you use a standard deck of cards, you will need to handle 52 potential objects that can be randomly given.

You are correct, in that I have a number of “games” in my modules, but I have avoided “cards” for a few reasons, not excluding the number of objects required. However, instead, I have gone for games/puzzles that can be accomplished with 26 or fewer objects. That’s just my personal limit. but allows me to use an alphabet string to help handle randomisation.

So, if I was to add a card type game, I would probably redesign a fantasy deck that worked with no more than 26 object types. In my own puzzles/games, I have tended towards matching types, or memory routines or logic solutions. This then generally allows a player to understand what is required of them without having to explain too many new rules in the first place.

I think adding an actual “game” beyond this stage of addition goes beyond anything I would want to add to my own modules at this point, simply because it takes too much focus from the story, in my opinion. That said, maybe another situation on another day … ?

1 Like

AKA Pontoon.



Thanks for the replies.

@Lance_Botelle - The good thing is that we already have the graphics from the card-game-persistent-worlds. Maybe one could limit the amount of cards to 5 on each hand? I don’t know the exact rules of Black Jack, but if one were to limit it to that, that would mean a maximum of 10 cards on the table. So it would require 5 “slots” on each side and then to code it so it is random what cards would appear, then the computer would need to calculate the sum of each hand and see which one is closest to 21, right? And if it’s over 21 you would lose automatically, right?

For this game I would like to limit it to just two players (the PC and the companion) as to make it less complex.

Would it be hard to (I have no idea how to do this) make an XML script of this? Just asking…
Maybe someone here knows? If I had some sort of template to work from I could maybe do it myself, but at the moment I have no idea where to start even.

I downloaded the stuff from:

I then extracted the file and made a hak file out of it with nwn2packer:

As you can see if you look inside this hak there are pictures for a lot of cards…
There are even a 2da file. Not sure why this is needed here, and there are a bunch of xml files already done. I’ve tried to make a test module just to see how it looks ingame, but it wouldn’t work since it’s made for multiplayer.

Maybe I should just give up on this whole thing…


Setting a limitation on the number of cards to display would certainly help, both from an XML and scripting point of view. And keeping the game to just a single PC versus a computer AI would also help.

As I say above, the hardest part is (in my opinion) would be to write the script code to handle the cards themselves and the randomisation/tracking of the “deck” involved. For example, in a regular 52 deck, you have four suits, or more importantly, four types of each card. E.g Four lots of 3’s etc.

i.e. You are not limited to only ten cards (from an XML point of view), but are dictated by the size of the deck you are playing with.

So, when the player draws (or is dealt) a three, you need to track that that particular card (3) is used from those that may be randomly delivered from again. However, If you further restrict your deck in some way, then the coding gets a little simpler.

It can be done with any number of cards/displays, but, as you can imagine, the coding become more complex.

As a (virtual) template, try to imagine a deck of cards, and how you would manage all the cards in that deck between the two players (PC v AI). If you can construct your game in such a way that uses a smaller deck, then it may be easier to manage. The thing about games like Blackjack, however, is that they have more than one possibility of the same “numbered” card turning up, and so removing that (to make things simpler) may also end up compromising the experience you are trying to achieve.

Personally, I would probably look at designing a completely different game to allow easier coding and a different experience to what is already available. Sometimes the simpler stuff can be just as fun without the potential headache.

That all said, if I ever get to the point where I have time to spare, I imagine it to be one of those challenges that may be fun to write as an add-on for builders like yourself to include. I remember writing a very simple dice game for a friend in NWN1 once, which he enjoyed using.

These would certainly save some time for the images, but do not help with the actual scripting time. :wink:


Yeah, now that you point it out with 52 cards in a deck the script would be very complex indeed. I don’t know if using one with only 13 cards and pictures, but have like 4 different variations of 2:s etc. …ok, that might essentially be the same thing as 52 cards…

Yeah, this might be too much of a hazzle to get through.

I already have a dice game. I wish there was some other simple game one could use. Sure, I could maybe make something similar to the dice game, that is entirely done through conversation, but it would have been SO nice if there were some graphical element to it, so that it really felt like a minigame. Uugh, I don’t know…


Another potential issue you have is that any puzzle or game tends to become quite “integral” with any other coding. i.e. It’s hard for me to recommend you look at the games/puzzles I have included, as even with all the images, XML and scripts available to you from my module, incorporating them into your own would be a “challenge” in and of itself.

I have a number of interesting puzzles already, and a number coming in module two, but all of them would require extra work from you to be able to transfer to your own environment - and I have made them as “easy” to do such as possible.

As an example … remember the lock pick GUI we were both looking at a while back? I had to write code around the way locks work in my campaign to the way they might in another. I also use home-brew functions (in libraries I have made) to help support them. Even trying to explain that relatively straightforward third party XML was quite involved. Trying to transfer a more complex puzzle would require even more time and patience.

A puzzle concept sounds fine on paper, but when it has to be personalised for each campaign style, changes made can start to add to the overall complexity … which is why some of the examples you link to say they are “not complete”, or require more work … because each campaign would want to design aspects their own way, very little works “as is” when it comes to this kind of coding.

1 Like

Tarot_Redhand… And it always will be pontoon to me, I was trying to be more continental :smiley:

1 Like

had a bit of fun …

// 'cards_inc'
	Several basic functions that can be used or adapted for use by a standard
	52-card puzzle.

	Drawn cards are simply stored as TRUE localints in the format
	where x is the suit and y is the rank of each card as it gets drawn from the

	Note that the remaining cards in the deck are effectively shuffled between
	each draw which means that these routines might not be suitable for puzzles
	that could go through the deck more than once.

const int spade   = 0;
const int heart   = 1;
const int club    = 2;
const int diamond = 3;

void DrawCard(object oStore = OBJECT_SELF);
string GetCardStr(string var);
void ClearDeck(object oStore = OBJECT_SELF);
string GetCardVar(int iSuit, int iRank);

// draws a unique card from the deck
// - oStore : a suitable object that holds the cards that have been drawn from
//            the deck
void DrawCard(object oStore = OBJECT_SELF)
	int iSuit, iRank;

	// keep attempting to draw a card until one that has not been drawn is found
	// you might want to limit this because it is a potentially infinite loop
	// ... eg Blackjack is unlikely to use all cards or even cause any
	// significant delay in finding a card; but Solitaire would be problematic
	// ... note that the order of cards in the deck is NOT preserved - ie the
	// remaining deck is effectively shuffled between each draw
	while (TRUE)
		iSuit = Random(4);
		iRank = Random(13);

		if (!GetLocalInt(oStore, GetCardVar(iSuit, iRank)))

	string var = GetCardVar(iSuit, iRank);

	// storing the card-var marks it as having been drawn from the deck
	SetLocalInt(oStore, var, TRUE);

	// do something with the card that was drawn ->
	SendMessageToPC(GetFirstPC(FALSE), "The " + GetCardStr(var) + " is drawn from the deck.");

// gets the readable string representation of a drawn card
// this can be adapted to get an image of the card and place/show it in a GUI
// or perhaps simply matching it to a desired card or a list of desired cards
// right now it's intended merely for printing the card to chat
string GetCardStr(string var)
	string sSuit, sRank;

	switch (StringToInt(GetStringLeft(var, 1)))
		case spade:   sSuit = "Spades";   break;
		case heart:   sSuit = "Hearts";   break;
		case club:    sSuit = "Clubs";    break;
		case diamond: sSuit = "Diamonds"; break;

		default: sSuit = "error Suit"; break;

	switch (StringToInt(GetStringRight(var, GetStringLength(var) - 1)))
		case  0: sRank = "Ace";   break;
		case  1: sRank = "Two";   break;
		case  2: sRank = "Three"; break;
		case  3: sRank = "Four";  break;
		case  4: sRank = "Five";  break;
		case  5: sRank = "Six";   break;
		case  6: sRank = "Seven"; break;
		case  7: sRank = "Eight"; break;
		case  8: sRank = "Nine";  break;
		case  9: sRank = "Ten";   break;
		case 10: sRank = "Jack";  break;
		case 11: sRank = "Queen"; break;
		case 12: sRank = "King";  break;

		default: sRank = "error Rank"; break;

	return sRank + " of " + sSuit;

// deletes all locals of cards that have been drawn
// call this after a game completes to keep the drawn-card-vars clean
void ClearDeck(object oStore = OBJECT_SELF)
	int iSuit = -1, iRank;
	while (++iSuit != 4)
		iRank = -1;
		while (++iRank != 13)
			DeleteLocalInt(oStore, GetCardVar(iSuit, iRank));

// gets the var used to mark a card as drawn
string GetCardVar(int iSuit, int iRank)
	return IntToString(iSuit) + IntToString(iRank);

//void main(){}

and a test script →

// 'cards'
	Console script. Tests 'cards_inc'

#include "cards_inc"

void main()
	object oStore = GetModule();



1 Like

@kevL_s - Ok, that’s a great start! Thank you for the time you put into that!

I just wish I knew the basics to somehow use the xml files already in two games put here on the vault.
I noticed that the second game has its own rules and cards and I don’t know how one would translate that to 13 cards of each “color”. The second has the correct cards with pictures and all, but it seems to me, now that I think about it, that just putting Black Jack with normal cards as a mini-game into my module will probably be a bit boring and feel too much like the real world. I think I need to somehow make it a bit more fantasy. Maybe my extremely limited skills with Gimp would serve me here…


I’ll try to have a look at those standard cards tomorrow. Tbh the appeal to me is to use a standard deck with a known game such as Blackjack … but that’s really just my personal pref

so if i do some more it’ll be geared toward that, but should be adaptable …

u do what u do ofc :)

I would like a standard deck for sure, but it would have been so nice if there was something along the lines like this to make it more otherworldly:

Problem is to find something like this, maybe with less advanced graphics, that is free to download and use.

those look great, are they public-ish domain ?

No, these are from Wicked Kingdom Deck that one can buy online. I just googled to see if there was something…

i googled “vintage playing cards” but don’t know what you want, or what’s free for use … i notice that there are card blanks, ready for custom images

/ah well, see how it goes …