UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Creating a hud problem

broken avatar :(
Created 12 years ago
by Ege115
0 Members and 1 Guest are viewing this topic.
2,965 views
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 2 years ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
Hello everyone.

I have trouble with creating creating a hud. I'm trying to make a hud to show if the player is ads and have a specific weapon. And if the player doesn't do that, the hud will be removed from the screen. However, no hud creates at all.
And "self" is the player.

Why not?
Code Snippet
Plaintext
create_ads_hud()
{
        text = undefined;
while(1)
{
WeapName = self getcurrentweapon();
if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "top";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
text.alpha = 1;
}
else
{
if(isdefined(text))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
}
wait .01;
}
}
Thanks in advance.
Last Edit: June 18, 2014, 07:16:10 pm by Ege115
This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: de
Date Registered: 18 October 2013
Last active: 2 days ago
Posts
651
Respect
Forum Rank
Zombie Enslaver
Primary Group
Donator ♥
My Groups
More
×
InFInIX's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
InFInIX's Contact & Social Links
do you use "text" already in an other script?
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 2 years ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
No I am not, I know it could be because of that as "text" is the most obvious thing to name it but no. :/
Last Edit: June 18, 2014, 07:11:05 pm by Ege115
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 6 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Mapper Has released one or more maps to the UGX-Mods community.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Hello everyone.

I have trouble with creating creating a hud. I'm trying to make a hud to show if the player is ads and have a specific weapon. And if the player doesn't do that, the hud will be removed from the screen. However, no hud creates at all.
And "self" is the player.

Why not?
Code Snippet
Plaintext
create_ads_hud()
{
        text = undefined;
while(1)
{
WeapName = self getcurrentweapon();
if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "top";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
text.alpha = 1;
}
else
{
if(isdefined(text))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
}
wait .01;
}
}
Thanks in advance.

One of your conditions is
Code Snippet
Plaintext
    !isdefined(text)
It runs through and before it gets a chance to show it, it loops back around because of the while(1) and sees that text is now defined so it destroys the hud before you see it. Add a wait after it creates the hud or modify your code some other way to not destroy hud if the other two conditions exist, or something, and then it should work.

You could change this:
Code Snippet
Plaintext
                if(isdefined(text))
{
text destroy();
text = undefined;
}

to this:
Code Snippet
Plaintext
                if(isdefined(text) && !(self AdsButtonPressed()))
{
text destroy();
text = undefined;
}

Last Edit: June 18, 2014, 09:24:33 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 2 years ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
Hmm. It is still not working, it is so wierd imo. "else" is for if the others statements are false right? Well I tried to print and see what happens if I print in the else statement, and it printed even if the statements were true. Why is that happening even if the statement is true?

Here is how my code looks now.
Code Snippet
Plaintext
create_ads_hud()
{
        text = undefined;
while(1)
{
WeapName = self getcurrentweapon();
if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "top";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
                wait 1;
text.alpha = 1;
}
else
{
if(isdefined(text) && !(self AdsButtonPressed()))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
                iprintln("none of the checks shouldn't be true");
}
wait .01;
}
}
Marked as best answer by Ege115 12 years ago
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 6 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Mapper Has released one or more maps to the UGX-Mods community.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Hmm. It is still not working, it is so wierd imo. "else" is for if the others statements are false right? Well I tried to print and see what happens if I print in the else statement, and it printed even if the statements were true. Why is that happening even if the statement is true?

Here is how my code looks now.
Code Snippet
Plaintext
create_ads_hud()
{
        text = undefined;
while(1)
{
WeapName = self getcurrentweapon();
if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "top";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
                wait 1;
text.alpha = 1;
}
else
{
if(isdefined(text) && !(self AdsButtonPressed()))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
                iprintln("none of the checks shouldn't be true");
}
wait .01;
}
}

This is the code that I used and tested:
Code Snippet
Plaintext
create_ads_hud()
{
    text = undefined;
while(1)
{
WeapName = self getcurrentweapon();

if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "middle";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
text.alpha = 1;
}
else
{
if(isdefined(text) && !(self AdsButtonPressed()))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
}
wait .01;
}
}

You have:
Code Snippet
Plaintext
text.vertAlign = "top";
and
Code Snippet
Plaintext
text.y = -4;
If you change this to :
Code Snippet
Plaintext
text.vertAlign = "middle";
or change this to
Code Snippet
Plaintext
text.y = 40;
You will see your hud.

The reason it prints is because you put the print in the else statement. The first statement is only true when you ads. As soon as you do, it waits the total of the waits you have in and then continues to print, and neither statement is true until you release ads. Then again when you hit it again, and so on... If the print statement was in either if statement it would have behaved differently.
broken avatar :(
×
broken avatar :(
Location: se
Date Registered: 30 July 2013
Last active: 2 years ago
Posts
517
Respect
Forum Rank
Zombie Enslaver
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Ege115's Groups
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Ege115's Contact & Social LinksEge115
This is the code that I used and tested:
Code Snippet
Plaintext
create_ads_hud()
{
    text = undefined;
while(1)
{
WeapName = self getcurrentweapon();

if( self AdsButtonPressed() && WeapName == "zombie_colt" && !isdefined(text))
{
self AllowMelee(false);
wait .4;
text = create_simple_hud( self );
text.alignX = "center";
text.alignY = "middle";
text.horzAlign = "center";
text.vertAlign = "middle";
text.fontscale = 14;
text.x = 0;
text.y = -4; // -265;
text.alpha = 0;
text SetText( "Do something random, I don't know" );
text.alpha = 1;
}
else
{
if(isdefined(text) && !(self AdsButtonPressed()))
{
text destroy();
text = undefined;
}
self AllowMelee(true);
self SetClientDvar("cg_fovMin","60");
}
wait .01;
}
}

You have:
Code Snippet
Plaintext
text.vertAlign = "top";
and
Code Snippet
Plaintext
text.y = -4;
If you change this to :
Code Snippet
Plaintext
text.vertAlign = "middle";
or change this to
Code Snippet
Plaintext
text.y = 40;
You will see your hud.

The reason it prints is because you put the print in the else statement. The first statement is only true when you ads. As soon as you do, it waits the total of the waits you have in and then continues to print, and neither statement is true until you release ads. Then again when you hit it again, and so on... If the print statement was in either if statement it would have behaved differently.
Works like a charm when I changed the,
Code Snippet
Plaintext
text.y = -4;
to,
Code Snippet
Plaintext
text.y = 40;
Thanks you makecents. :D

 
Loading ...