Fucking HUD elements

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Fucking HUD elements

Post by Rezil » November 7th, 2010, 1:49 am

It's 2 in the morning, I haven't slept well in days, I have a homework assignment due tomorrow night. So excuse the sloppy scripting.

My problem is this, I have the following code(supposed to be a working Blackjack - so far it only displays 4 cards on screen and does some basic math):

Code: Select all

//made by rezil, do not modify!

/* position can be: 1, 2, 3, 4, 5

pos 1: first card the player is dealt
pos 2: the second card the player is dealt
pos 3: if user hit, draw card here
pos 4: if user hit after pos 3, draw card here
pos 5; if user hit after pos 4, draw card here
*/
main()
{

thread trig_start();
}

trig_start()
{
    t = getent("trigger_2","targetname");
    while(1)
    {
        t waittill("trigger", user);
        user thread initgame();
        wait 5;
    }
}


initGame()
{
    self notify("another_game");
    self endon("another_game"); 
    self.score = 0;
    self.dealer_score = 0;
    
    
    self dealFirstTwoCards();
    
}

dealFirstTwoCards()
{
    card1 = randomInt(13)+1;
    card1_dealer = randomInt(13)+1;
    suite1 = randomint(4)+1;
    suite1_dealer = randomint(4)+1;
    card2 = randomInt(13)+1;
    card2_dealer = randomInt(13)+1;
    suite2 = randomint(4)+1;
    suite2_dealer = randomint(4)+1;
    
    self dealCard("self", card1, suite1, 1, 0);
    self.hudent_card1 = self.card[0];
    self.value_card1 = self.card[0].game_value;
    
    wait 0.3;
    
    self dealCard("dealer", card1_dealer, suite1_dealer, 1, 1);
    self.hudent_card1_dealer = self.card[1];
    self.value_card1_dealer = self.card[1].game_value;
    
    wait 0.3;
    
    self dealCard("self", card2, suite2, 2, 2);
    self.hudent_card2 = self.card[2];
    self.value_card2 = self.card[2].game_value;
    
    wait 0.3;
    
    self dealCard("dealer", card2_dealer, suite2_dealer, 2, 3);
    self.hudent_card2_dealer = self.card[3];
    self.value_card2_dealer = self.card[3].game_value;
    
    wait 0.3;
    
    wait 0.5;
    
    iprintlnbold("My cards: "+self.value_card1+ " and " +self.value_card2+ ". Dealer cards: " +self.value_card1_dealer+ " and " +self.value_card2_dealer+ ".");
    
    if(checkBlackjack(self.value_card1, self.value_card2)) iprintlnbold("game over, you win");
    else if(checkBlackjack(self.value_card1_dealer, self.value_card2_dealer)) iprintlnbold("game over, dealer wins");
    
    
    
}
//Draws a HUD image of a playing card with the value <value> to the specified person 'person' in the specified suite 'suite'. cardnum is the card index
dealCard(person, value, suite, position, cardnum)
{
    if(!isdefined(self.card)) self.card = [];
    
    if(!isdefined(self.card[cardnum])) 
    {
        self.card[cardnum] = newclientHudElem(self);
        self.card[cardnum].alignX = "left";
        self.card[cardnum].alignY = "top";    
        self.card[cardnum].alpha = 1;
        switch(position)
        {
            case 1:
              if(person=="self") self.card[cardnum] setCardXY(190, 240);
              else if(person=="dealer") self.card[cardnum] setCardXY(190, 80);
              break;
            case 2:
              if(person=="self") self.card[cardnum] setCardXY(240, 240);
              else if(person=="dealer") self.card[cardnum] setCardXY(240, 80);
              break;
            case 3:
              if(person=="self") self.card[cardnum] setCardXY(290, 240);
              else if(person=="dealer") self.card[cardnum] setCardXY(290, 80);
              break;
            case 4:
              if(person=="self") self.card[cardnum] setCardXY(340, 240);
              else if(person=="dealer") self.card[cardnum] setCardXY(340, 80);
              break;
            case 5:
              if(person=="self") self.card[cardnum] setCardXY(390, 240);
              else if(person=="dealer") self.card[cardnum] setCardXY(390, 80);
              break;
            default:
              iprintln("^1 0 position set(or is greater than 5), ERROR!^3*");
              break;
        }
        
        if((position==1) && (person=="dealer")) 
        {
            if(randomint(2)==0) self.card[cardnum] setshader("bicycle_red", 72, 96);
            else self.card[cardnum] setshader("bicycle_blue", 72, 96);
        }
        else self.card[cardnum] setshader(getShaderFromCard(value, suite), 72, 96);
        
        if(value>10) self.card[cardnum].game_value=10; 
        else self.card[cardnum].game_value=value;

        return self.card[cardnum].game_value;
    }
}

//gets the correct shader name to use, also gives the card value
getShaderFromCard(value, suite)
{
    shader_name = "";

    switch(value)
    {
        case 1:
          shader_name = "ace_";
          break;
        case 2:
          shader_name = "two_";
          break;
        case 3:
          shader_name = "three_";
          break;
        case 4:
          shader_name = "four_";
          break;
        case 5:
          shader_name = "five_";
          break;
        case 6:
          shader_name = "six_";
          break;
        case 7:
          shader_name = "seven_";
          break;
        case 8:
          shader_name = "eight_";
          break;
        case 9:
          shader_name = "nine_";
          break;
        case 10:
          shader_name = "ten_";
          break;
        case 11:
          shader_name = "jack_";
          break;
        case 12:
          shader_name = "queen_";
          break;
        case 13:
          shader_name = "king_";
          break;
        default:
          iprintln("^1card value is 0, ERROR!^3*");
          break;
    }
    
    shader_name = shader_name+"of";
    
    switch(suite)
    {
        case 1:
          shader_name = shader_name+"_clubs";
          break;
        case 2:
          shader_name = shader_name+"_spades";
          break;
        case 3:
          shader_name = shader_name+"_hearts";
          break;
        case 4:
          shader_name = shader_name+"_diamonds";
          break;
        default:
          iprintln("^1suite is 0, ERROR!^3*");
          break;
    }
    return shader_name;
}

setCardXY(x_val, y_val)
{
    self.x = x_val;
    self.y = y_val;
}

checkBlackjack(value1, value2)
{
    if((value1 == 1) || (value2==1))
    {
        value1+=10; //doesn't matter which card gets 10 added, if either of them is an ace
        if(value1+value2==21)
        {
            iprintlnbold("^2$$$^7BLACKJACK!^2$$$");
            return true;
        }
        else return false;
    }
    else return false; //need an ace for a blackjack
}

Now, I get the 'too many unique materials (1024)' engine error when trying to run this(triggering). I have 54 precached shaders but that shouldn't be a problem because cod2 can handle more than that(the shaders are precached in a seperate file, will post that if you need it as well).
If I display the cards and delete them after spawning(and undefing the values) it works fine. The problem is when I don't do that I get the error. Perhaps I did something wrong in the script or there are simply too many 2d images precached(unlikely).

Hope you guys provide some answers to this, me and IzNoGoD have been at it for hours to no avail. :/
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Fucking HUD elements

Post by Drofder2004 » November 7th, 2010, 2:54 am

I suspect your precaches are hitting a major limit.
The 1024 is (to my knowledge) a matter of not only size but "text size". So the amount of characters must be less than 1024 (across all content).

Why not make 4 shaders (symbols) and then use the ingame text to simulate the card numbers?

It should not be hard to do using 5 text Placeholders and 5 symbol placeholders.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Fucking HUD elements

Post by Rezil » November 7th, 2010, 11:42 am

Hm, I guess it would work that way as well. Although it wouldn't be nearly as nice to look at. I'll try to reduce the ammount of precached shaders and report back.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Fucking HUD elements

Post by Drofder2004 » November 7th, 2010, 1:04 pm

Option2:
31 total precached

13 Red, 13 black numbers
4 suits (with full card)
1 card reverse side

Make sure everything is one/two letter longs (either use letters or "_1" etc)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Fucking HUD elements

Post by IzNoGoD » November 7th, 2010, 1:34 pm

Updated the script for you rez, but it still crashes.

Code: Select all

//made by rezil, do not modify!

/* position can be: 1, 2, 3, 4, 5

pos 1: first card the player is dealt
pos 2: the second card the player is dealt
pos 3: if user hit, draw card here
pos 4: if user hit after pos 3, draw card here
pos 5; if user hit after pos 4, draw card here
*/
main()
{

thread trig_start();
}

trig_start()
{
	t = getent("trigger_2","targetname");
	while(1)
	{
		t waittill("trigger", user);
		if(!isdefined(user.isplaying))
			user.isplaying=false;
		if(!user.isplaying)
		{
			user.isplaying=true;
			user thread initgame();
			wait 10;
		}
	}
}


initGame()
{
	self dealFirstTwoCards();
	self waittill("end_of_game");
	self destroyallcards();
	self.isplaying=false;
}

dealFirstTwoCards()
{

	for(i=0;i<=10;i++)
	{
		self dealcard(randomint(13)+1,randomint(4)+1,i);
		wait .3;
	}

	wait .5;

	iprintlnbold("My cards: "+self.card[0].game_value+ " and " +self.card[2].game_value+ ". Dealer cards: " +self.card[1].game_value+ " and " +self.card[3].game_value+ ".");	
	
	if(checkBlackjack(self.value_card1, self.value_card2)) iprintlnbold("game over, you win");
	else if(checkBlackjack(self.value_card1_dealer, self.value_card2_dealer)) iprintlnbold("game over, dealer wins");

	self notify("end_of_game");	
}

destroyallcards()
{
for(i=0;i<=4;i++)
	{
	if(isdefined(self.card[i]))
		self.card[i] destroy();
	}
}

//Draws a HUD image of a playing card with the value <value> in the specified suite 'suite'. cardnum is the card index
dealCard(value, suite, cardnum)
{
	if(!isdefined(self.card)) self.card = [];
	if(!isdefined(self.card[cardnum])) 
	{
		self.card[cardnum] = newclientHudElem(self);
		self.card[cardnum].alignX = "left";
		self.card[cardnum].alignY = "top";	
		self.card[cardnum].alpha = 1;

		if(cardnum/2==int(cardnum/2))
			{
			//card is at self
			cardy=240;
			cardshader=value+"_"+suite;
			}
		else
			{
			//card is at dealer
			cardy=80;
			cardshader="color"+randomint(1);
			}
		cardx=190+int((cardnum)/2)*100;

		self.card[cardnum].x=cardx;
		self.card[cardnum].y=cardy;
		self.card[cardnum] setshader(cardshader,72,96);
				
		if(value>10) self.card[cardnum].game_value=10; 
		else self.card[cardnum].game_value=value;
	}
}

checkBlackjack(value1, value2)
{
	if((value1 == 1) || (value2==1))
	{
		value1+=10; //doesn't matter which card gets 10 added, if either of them is an ace
		if(value1+value2==21)
		{
			iprintlnbold("^2$$$^7BLACKJACK!^2$$$");
			return true;
		}
		else return false;
	}
	else return false; //need an ace for a blackjack
}
LMGTFY!

Its not a glitch... Its the future!

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Fucking HUD elements

Post by Rezil » November 22nd, 2010, 1:53 am

Image

Well, it's not as pretty and the black hidden card is not the final back image, but it works and that's what matters.

It seems the problem was in the back image of the card. I have no clue why it would make the game crash(the image is a power of two, compiled and converted without problems) but I'm happy that it at least works.

Even though there are more HUD elements in this version(4 white shaders + 2 shaders(value, suite) for each of the cards - 2 with alpha 0) it seems to work better than the first version. Insane. :/
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Fucking HUD elements

Post by Moustache » November 22nd, 2010, 12:11 pm

You can't use "black" as a shader? That is possible in CoD4.

I also made a Blackjack game :)
But I can't add extra images because this mod is added to promod.

It is on this server: 62.133.194.28:30081. You can check it out if you want :)

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Fucking HUD elements

Post by Rezil » November 22nd, 2010, 12:34 pm

It is the black shader, it's set to 72x96 so it resembles a card shape. The black is just temporary until I can find out what's wrong with the damn card image I used before.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Fucking HUD elements

Post by Moustache » November 22nd, 2010, 2:21 pm

Hmm oke.

And if you only place your created card on the hud?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests