UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: Ege115 on May 17, 2014, 08:18:22 pm

Title: Button script problem
Post by: Ege115 on May 17, 2014, 08:18:22 pm
I have trouble with this script. I am trying to make so you will have to press 4 buttons and then thread a function.
But ingame it threads the function if I only press 2 of the buttons. Why is this happening? In my script it says 4 buttons but ingame it threads after 2 hits.
Code Snippet
Plaintext
main()
{
level.switchs_hit = 0;
button1 = GetEnt("button1","targetname");
button2 = GetEnt("button2","targetname");
button3 = GetEnt("button3","targetname");
button4 = GetEnt("button4","targetname");

button1 thread make_switch();
button2 thread make_switch();
button3 thread make_switch();
button4 thread make_switch();
}
make_switch()
{
level waittill("gen1_done");
level waittill("gen2_done");
level waittill("gen3_done");
level waittill("gen4_done");

self setCursorHint( "HINT_NOICON" );
self sethintstring ("Press &&1 to Link Generator to Mainframe");
self waittill("trigger", player);

PlaySoundAtPosition( "heart_monitor", self.origin );
self delete();

level.switchs_hit = level.switchs_hit + 1;

if(level.switchs_hit == 4)
{
thread open_portal();
players = Get_players();
for( i = 0; i < players.size; i++ )
{
players[i] playsound("radio12");
}
}
}
Thanks in advance.
Title: Re: Button script problem
Post by: ConvictioNDR on May 17, 2014, 08:27:53 pm
I'm new to scripting so maybe not the best answer but worth a shot until someone better at scripting can help if it doesn't work.
Try something more like this?
Code Snippet
Plaintext
main()
{
level.switchs_hit = 0;
level make_switch( "button1" );
level make_switch( "button2" );
level make_switch( "button3" );
level make_switch( "button4" );
}
make_switch( trigger_name )
{
level waittill("gen1_done");
level waittill("gen2_done");
level waittill("gen3_done");
level waittill("gen4_done");
button_trig = getent( trigger_name, "targetname" );
button_trig setCursorHint( "HINT_NOICON" );
button_trig sethintstring ("Press &&1 to Link Generator to Mainframe");
button_trig waittill("trigger", player);

PlaySoundAtPosition( "heart_monitor", button_trig.origin );
button_trig delete();

level.switchs_hit = level.switchs_hit + 1;

if(level.switchs_hit == 4)
{
thread open_portal();
players = Get_players();
for( i = 0; i < players.size; i++ )
{
players[i] playsound("radio12");
}
}
}
Title: Re: Button script problem
Post by: MakeCents on May 17, 2014, 08:29:17 pm
I have trouble with this script. I am trying to make so you will have to press 4 buttons and then thread a function.
But ingame it threads the function if I only press 2 of the buttons. Why is this happening? In my script it says 4 buttons but ingame it threads after 2 hits.
Code Snippet
Plaintext
main()
{
level.switchs_hit = 0;
button1 = GetEnt("button1","targetname");
button2 = GetEnt("button2","targetname");
button3 = GetEnt("button3","targetname");
button4 = GetEnt("button4","targetname");

button1 thread make_switch();
button2 thread make_switch();
button3 thread make_switch();
button4 thread make_switch();
}
make_switch()
{
level waittill("gen1_done");
level waittill("gen2_done");
level waittill("gen3_done");
level waittill("gen4_done");

self setCursorHint( "HINT_NOICON" );
self sethintstring ("Press &&1 to Link Generator to Mainframe");
self waittill("trigger", player);

PlaySoundAtPosition( "heart_monitor", self.origin );
self delete();

level.switchs_hit = level.switchs_hit + 1;

if(level.switchs_hit == 4)
{
thread open_portal();
players = Get_players();
for( i = 0; i < players.size; i++ )
{
players[i] playsound("radio12");
}
}
}
Thanks in advance.
Looks fine to me...
Shot in the dark... You don't call main more than once do you?
Title: Re: Button script problem
Post by: Ege115 on May 17, 2014, 08:45:39 pm
I'm new to scripting so maybe not the best answer but worth a shot until someone better at scripting can help if it doesn't work.
Try something more like this?
Code Snippet
Plaintext
main()
{
level.switchs_hit = 0;
level make_switch( "button1" );
level make_switch( "button2" );
level make_switch( "button3" );
level make_switch( "button4" );
}
make_switch( trigger_name )
{
level waittill("gen1_done");
level waittill("gen2_done");
level waittill("gen3_done");
level waittill("gen4_done");
button_trig = getent( trigger_name, "targetname" );
button_trig setCursorHint( "HINT_NOICON" );
button_trig sethintstring ("Press &&1 to Link Generator to Mainframe");
button_trig waittill("trigger", player);

PlaySoundAtPosition( "heart_monitor", button_trig.origin );
button_trig delete();

level.switchs_hit = level.switchs_hit + 1;

if(level.switchs_hit == 4)
{
thread open_portal();
players = Get_players();
for( i = 0; i < players.size; i++ )
{
players[i] playsound("radio12");
}
}
}
That wouldn't matter, I call the function as "self". And in that case self is always the entity I called it from in "main". But thanks anyway :D.
Looks fine to me...
Shot in the dark... You don't call main more than once do you?
I call main only once. :/
Title: Re: Button script problem
Post by: PROxFTW on May 17, 2014, 08:57:19 pm
Quick made script. See how this works then maybe I can modify based on the results.
Code Snippet
Plaintext
main()
{
level.SwitchHit = 0;
for( i = 1; i < 5; i++ )
{
Button[i] = GetEnt( "button" + i, "targetname" );
Button[i] thread SwitchX();
}
level thread WatchHits();//Maybe just thread
}

SwitchX()
{
for( i = 1; i < 5; i++ )
level waittill( "gen" + i + "_done" );
self SetCursorHint( "HINT_NOICON" );
self SetHintString( "Press &&1 to link Generator to Mainframe" );
self waittill( "trigger", Player );
PlaySoundAtPosition( "heart_monitor", self.origin );
self delete();
level.SwitchHit += 1;
}

WatchHits()
{
while( 1 )
{
if( level.SwitchHit == 4 )
{
thread open_portal();
Player = GetPlayers();
for( i = 0; i < Player.size; i++ )
Player[i] playsound( "radio12" );
break;
}
wait .05;
}
}
Title: Re: Button script problem
Post by: ConvictioNDR on May 17, 2014, 08:59:56 pm
Couldn't hurt to try though yeah?
I use a similar script in my map. I noticed it was adding a number already cuz I accidentally had two trigs with the same targetname. So I'd say check the target names make sure none are accidentally the same or with typo.
Title: Re: Button script problem
Post by: MakeCents on May 17, 2014, 09:01:13 pm
main only once. :/

Sorry, just thought it might be 4 cause it ups the level variable twice, maybe. Did you check the level.switchs_hit with an iprintln after the waittill trigger? If counting by twos, then something is doubling. You could just make it 8 if you can't figure it out. If it counts by 1s and is working on 2, then sorry for wasting your time, cause I'm out of ideas.
Title: Re: Button script problem
Post by: Ege115 on May 17, 2014, 09:30:59 pm
Couldn't hurt to try though yeah?
I use a similar script in my map. I noticed it was adding a number already cuz I accidentally had two trigs with the same targetname. So I'd say check the target names make sure none are accidentally the same or with typo.
You solution would work as well, this script is just how I thought. :)
Sorry, just thought it might be 4 cause it ups the level variable twice, maybe. Did you check the level.switchs_hit with an iprintln after the waittill trigger? If counting by twos, then something is doubling. You could just make it 8 if you can't figure it out. If it counts by 1s and is working on 2, then sorry for wasting your time, cause I'm out of ideas.
You didn't waste my time at all. xD no need to say sorry.

Also, I solved it, it was something I did wrong in the script simply. Thanks for he help anyways, but sorry for wasting YOUR time. xD

Edit: but I give the best answer to prox, because your way is to use arrays which is smarter than the script I had. :D
Title: Re: Button script problem
Post by: ConvictioNDR on May 17, 2014, 09:35:38 pm
Mind saying what the error was? Just in case someone else gets the same issue? They might have made the same mistake.
Title: Re: Button script problem
Post by: Ege115 on May 17, 2014, 09:47:10 pm
Oh, yea sure thing.

The script was called twice in mapname.gsc which dublicated the amount of times you pressed the buttons.
Title: Re: Button script problem
Post by: MakeCents on May 18, 2014, 02:07:50 am
Why is this happening? In my script it says 4 buttons but ingame it threads after 2 hits.
You don't call main more than once do you?
I call main only once. :/
Did you check the level.switchs_hit with an iprintln after the waittill trigger? If counting by twos, then something is doubling.
Also, I solved it, it was something I did wrong in the script simply. Thanks for he help anyways, but sorry for wasting YOUR time. xD
Mind saying what the error was?
The script was called twice in mapname.gsc which dublicated the amount of times you pressed the buttons.
but I give the best answer to prox
LOL
 :derp:
(https://www.ugx-mods.com/forum/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FLTiY9YF.gif&hash=6b91fcffef12ef1274b1d09bb35f0f5e0d8a6c46)