if failure?

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

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

if failure?

Post by Moustache » September 18th, 2010, 3:41 pm

How is it possible that a script just executes a code in the if statement while the if statement isn't correct?

This is what I am talking about:

Code: Select all

if (self.clientid == warn[0])
{
	self IPrintLnBold(self.clientid);
	self IPrintLnBold(warn[0]);
}
On my screen I see:
1
0
WTF? :shock:
How can it be printed while 1 is not equal to 0?

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: if failure?

Post by waywaaaard » September 18th, 2010, 4:22 pm

!=
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

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

Re: if failure?

Post by Moustache » September 18th, 2010, 4:27 pm

waywaaaard wrote:!=
I know that that means is not. But I think you don't understand me.

Why does the script print the values? Even when the values are not equal to each other?

And when I tried != I still get the same thing.

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: if failure?

Post by waywaaaard » September 18th, 2010, 4:50 pm

is any other thread using those vars? Would print them out before the if and inside it. So maybe it changes. And or try to cast both to int with int(warn[0]) == int(self.clientid)
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

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

Re: if failure?

Post by Drofder2004 » September 18th, 2010, 10:26 pm

What are the assigned values of these variable, because my guess is that we have mis-matched types (one being a string), but the code is not throwing an error.
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

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

Re: if failure?

Post by Moustache » September 19th, 2010, 8:59 am

Actually my whole system fails.
I want a system where you can send a command to the server with the player slot in it and a warning message.
My script doesn't work good. It only works when I place the command in the .cfg file. Because when I send it to the server when the server is running it doesn't work. I don't know what I am doing wrong :|
I hope someone can and is willing to help me.
Last edited by Moustache on September 20th, 2010, 2:22 pm, edited 1 time in total.

User avatar
Opel
CJ Fan
CJ Fan
Posts: 188
Joined: September 15th, 2008, 12:28 pm
Location: Scotland

Re: if failure?

Post by Opel » September 19th, 2010, 10:22 am

Code: Select all

SayPlayer()
{
	tokens = strTok( getDvar("jmp_say"), ":");
	if(tokens.size == 2)
	{
		players = getEntArray("player", "classname");
		for(i=0; i<players.size; i++)
		{
			playernum = players[i] getEntityNumber();
			if(playernum == int(tokens[0] ))
			{
				players[i] iprintlnbold(tokens[1]);
				break;
			}
		}
	}
	setDvar("jmp_say", "");
}

Mabye try something like that. I havent tested it though

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

Re: if failure?

Post by Drofder2004 » September 19th, 2010, 10:58 am

The above should work fine.

Although to add the loop:

Code: Select all

SayPlayer()
{
   for(;;)
   {
      setDvar("jmp_say", "");

      while(getDvar("jmp_say") == "")
         wait 0.05;

      tokens = strTok( getDvar("jmp_say"), ":");
      if(tokens.size == 2)
      {
         players = getEntArray("player", "classname");
         for(i=0; i<players.size; i++)
         {
            playernum = players[i] getEntityNumber();
            if(playernum == int(tokens[0] ))
            {
               // This is where you would insert your "if true" code
               players[i] iprintlnbold(tokens[1]);
               break;
            }
         }
      }
   }
}
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

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

Re: if failure?

Post by Moustache » September 20th, 2010, 2:45 pm

Thank you very much, that script works perfect :mrgreen:

Only combined with my code, there is something strange.
Because I always see the IPrintLineBold, but not the text that should be on the hud element.

I just start the server, join it. Put in console: /rcon login [rcon_pass]
Then I type in console: /rcon set warn_player "0:Do ^1not ^3spam ^7please"
I get the IPrintLineBold warning and after 2 seconds the HUD elements. The black screen with the warning. But I don't get the: "You can continue in [number]" text.

And when I type /reconnect in console.
And then type this in console: /rcon set warn_player "0:Do ^1not ^3spam ^7please"
I get the IPrintLineBold message, but after 2 seconds I only get a black screen. Without any text in it.

How is that possible?
Last edited by Moustache on September 21st, 2010, 4:35 pm, edited 1 time in total.

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

Re: if failure?

Post by Drofder2004 » September 20th, 2010, 7:43 pm

you may need to add a small wait before assigning the label/text to a hud.
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

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

Re: if failure?

Post by Moustache » September 21st, 2010, 6:07 am

I don't see any text now, only a black screen :|
Last edited by Moustache on September 21st, 2010, 4:40 pm, edited 1 time in total.

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

Re: if failure?

Post by Drofder2004 » September 21st, 2010, 10:56 am

Use ".sort" on all your hud elements, start at 100 for the black and 101 for the text.
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

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

Re: if failure?

Post by Moustache » September 21st, 2010, 4:40 pm

Thanks again, that worked :)

But when I reconnect and type in the command again I first see the IPrintLnBold message but then I get a black screen without any text in it.
Last edited by Moustache on September 21st, 2010, 7:18 pm, edited 1 time in total.

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

Re: if failure?

Post by Drofder2004 » September 21st, 2010, 4:57 pm

For testing purposes, change the "setText(message)" to "setText("TESTING")"

Post results.
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

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

Re: if failure?

Post by Moustache » September 21st, 2010, 5:25 pm

Still the same.

Only a black screen after reconnect.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests