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

Counting in Script Help

broken avatar :(
Created 11 years ago
by jbird
0 Members and 1 Guest are viewing this topic.
3,526 views
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
×
jbird's Groups
Code Snippet
Plaintext
rounds_won = 0;
        if( players_alive == 1 )
        {
                if( !is_player_valid(players[i]) )
                {
                        iprintlnbold("You have won this round!");
                        rounds_won++;
                        iprintln("Rounds Won: " + rounds_won);
                        if( rounds_won == 3 )
                        {
                                self freezeControls(true);
                                level notify( "end_game" );
                        }
                }

I'm trying to make a script that counts up 1 everytime the amount of players alive is 1. The iprintln says 1 everytime though, any help getting it working?
Marked as best answer by jbird 11 years ago
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
rounds_won = 0;

is setting it back to 0 everytime this function is called, but also this variable does not exist outside of this functions name space, make it global by applying it to level

declare it outside of the function instead like

level.rounds_won = 0;

and add to that variable

or :

Code Snippet
Plaintext
if ( !isDefined( level.rounds_won) )
{
    level.rounds_won = 0;
}
        if( players_alive == 1 )
        {
                if( !is_player_valid(players[i]) )
                {
                        iprintlnbold("You have won this round!");
                        level.rounds_won++;
                        iprintln("Rounds Won: " + level.rounds_won);
                        if( players[i].rounds_won == 3 )
                        {
                                self freezeControls(true);
                                level notify( "end_game" );
                        }
                }
Last Edit: June 09, 2015, 07:01:10 am by Harry Bo21
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
rounds_won = 0;

is setting it back to 0 everytime this function is called, but also this variable does not exist outside of this functions name space, make it global by applying it to level

declare it outside of the function instead like

level.rounds_won = 0;

and add to that variable

or :

Code Snippet
Plaintext
if ( !isDefined( level.rounds_won) )
{
    level.rounds_won = 0;
}
        if( players_alive == 1 )
        {
                if( !is_player_valid(players[i]) )
                {
                        iprintlnbold("You have won this round!");
                        level.rounds_won++;
                        iprintln("Rounds Won: " + level.rounds_won);
                        if( rounds_won == 3 )
                        {
                                self freezeControls(true);
                                level notify( "end_game" );
                        }
                }
Thanks it worked! Is there a way I could make the variable different for each player? Would changing it from "level." to "player." do that?
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Thanks it worked! Is there a way I could make the variable different for each player? Would changing it from "level." to "player." do that?

Code Snippet
Plaintext
Players[i].
not players but yes that would be the fastest way to store something for each specific player.

Edit: forum tag screwed with the index part.
Last Edit: June 09, 2015, 05:41:44 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
Code Snippet
Plaintext
Players[i].
not players but yes that would be the fastest way to store something for each specific player.

Edit: forum tag screwed with the index part.
It's not working right when I change it to
Code Snippet
Plaintext
players.
or
Code Snippet
Plaintext
players[i].
Last Edit: June 09, 2015, 06:02:56 am by jbird
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
It's not working right when I change it to
Code Snippet
Plaintext
players.
or
Code Snippet
Plaintext
players[i].

Post the entire function then. Can't help you with what little information your providing.

Edit: Just to clarify/point out, players is an array and you can never attach anything directly to an array, only each individual entities that make up the array which you can get by using an index, key, or both(more advanced stuff).
Last Edit: June 09, 2015, 06:52:51 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
Actually can be called whatever you choose

Code Snippet
Plaintext
players = get_players();

players[ i ].won_rounds =

imanynameatall = get_players();

imanynameatall [ i ].won_rounds =

you just need to make sure you declare it before referencing it, similar to the original problem ;)

but yes "players" seems to already be referenced in your script so

Code Snippet
Plaintext
if ( !isDefined( players[i].rounds_won) )
{
    players[i].rounds_won = 0;
}
        if( players_alive == 1 )
        {
                if( !is_player_valid(players[i]) )
                {
                        iprintlnbold("You have won this round!");
                        players[i].rounds_won++;
                        iprintln("Rounds Won: " + players[i].rounds_won);
                        if( players[i].rounds_won == 3 )
                        {
                                self freezeControls(true);
                                level notify( "end_game" );
                        }
                }
Last Edit: June 09, 2015, 07:00:54 am by Harry Bo21
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Actually can be called whatever you choose

Code Snippet
Plaintext
players = get_players();

players[ i ].won_rounds =

imanynameatall = get_players();

imanynameatall [ i ].won_rounds =

you just need to make sure you declare it before referencing it, similar to the original problem ;)

I meant you can store the variable for each players using different methods than using get_players(), just takes longer and uses more code than is necessary.
Last Edit: June 09, 2015, 07:16:01 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
Code Snippet
Plaintext
if ( !isDefined( players[i].rounds_won) )
{
    players[i].rounds_won = 0;
}

    if( players_alive == 1 )
    {
        if( !is_player_valid(players[i]) )
        {
            iprintlnbold("You have won this round!");
            players[i].rounds_won++;
            iprintln("Rounds Won: " + players[i].rounds_won);
}
else
{
iprintlnbold("You have been given another chance");
}

if( players[i].rounds_won == 3 )
{
self FreezeControls( true );
level notify( "end_game" );
}
}
Here is what I have now, but it still doesn't work right, the game ends after the first time instead of the 3rd time when its suppose to happen
Last Edit: June 09, 2015, 07:34:10 am by jbird
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
I meant post the entire function i meant post everything, even the head and where your variables are coming from because from your original code i don't know where players_alive is coming from.

But regardless i rewrote the function which should work:

Code Snippet
Plaintext
round_won_watch()
{
level endon("end_game");
while(1)
{
players = get_players();
for(i=0;i<players.size;i++)
{
if(!isdefined(players[i].rounds_won))
players[i].rounds_won = 0;

level waittill( "between_round_over" );

if(!is_player_valid(players[i]))
{
iprintlnbold("You have won this round!");
            players[i].rounds_won++;
iprintln("Rounds Won: " + players[i].rounds_won);
}
else
iprintlnbold("You have been given another chance");

if(players[i].rounds_won == 3)
{
self FreezeControls( true );
level notify( "end_game" );
}
}
}
}

Thread call this once after _zombiemode.

I used between_round_over to stop the function until the next round had begun which is what i assume your trying to do.

You shouldn't need to check the amount of players alive because if all players are dead the script will just end because of:

Code Snippet
Plaintext
	level endon("end_game");

Unless this is a SP only thing. In which case just add it back in i guess.

Hopefully it works.
Last Edit: June 09, 2015, 07:55:03 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
Code Snippet
Plaintext
players = get_players();
players_alive = 0;
for( i = 0; i < players.size; i++ )
{
if( is_player_valid(players[i]) )
{
players_alive++;
}
}

if( players_alive > 1 )
{
self maps\_callbackglobal::finishPlayerDamageWrapper( eInflictor, eAttacker, finalDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, modelIndex, psOffsetTime );
return;
}

self.intermission = true;

self thread maps\_laststand::PlayerLastStand( eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime );
self player_fake_death();

players = get_players();
for(i=0;i<players.size;i++)
{
if(!isDefined(players[i].rounds_won))
{
    players[i].rounds_won = 0;
}

    if( players_alive == 1 )
    {
    for (i = 0; i < players.size; i++)
{
        if( is_player_valid(players[i]) )
        {
            iprintlnbold("You have won this round!");
            players[i].rounds_won++;
            iprintln("Rounds Won: " + players[i].rounds_won);
}
else
{
iprintlnbold("You have been given another chance");
}
}

self maps\_laststand::laststand_take_player_weapons();

zombs = getaiarray("axis");
for(i=0;i<zombs.size;i++)
{
zombs[i] delete(); //removes all currently spawned in zombies
}

maps\_zombiemode_powerups::powerup_round_start(); //restarts the amount of powerups you can earn this round
array_thread( players, maps\_zombiemode_blockers_new::rebuild_barrier_reward_reset ); //restarts your barrier points this round
level thread [[level.round_spawn_func]](); //makes the amount of zombies restart to its original amount for the round

players = get_players();
for( i = 0; i < players.size; i++ ) //respawns you back in and gives you your weapons back
{
players[i] spectator_respawn();
players[i] [[level.spawnPlayer]]();
while(1)
{
if(players[i] hasWeapon("zombie_colt"))
{
players[i] takeAllWeapons();
players[i] maps\_laststand::laststand_giveback_player_weapons();
if( isDefined( players[i].has_altmelee ) && players[i].has_altmelee )
{
players[i] SetPerk( "specialty_altmelee" );
}
if (isDefined(level.script) && players[i].score < 5000)
{
players[i].old_score = players[i].score;
players[i].score = 5000;
players[i] maps\_zombiemode_score::set_player_score_hud();
}
level thread award_grenades_for_survivors(); //get 2 extra grenades when you spawn back in, optional
break;
}
wait(0.05);
}
}

if( players[i].rounds_won == 3 )
{
self FreezeControls( true );
level notify( "end_game" );
}
}

Here is all the code that you need. The print in counts up currectly, the only thing that doesnt work is the last part. The code is not waiting for rounds_won to equal 3 even though thats what is coded, it is ending the game no matter what.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet

Here is all the code that you need. The print in counts up currectly, the only thing that doesnt work is the last part. The code is not waiting for rounds_won to equal 3 even though thats what is coded, it is ending the game no matter what.

... because there isn't anything to prevent it from looping again - assuming that this whole function is looped somewhere or is called more than once - it'll just keep adding to each players round_won var without really stopping.

Try adding:

Code Snippet
Plaintext
level waittill( "between_round_over" );

right before this:

Code Snippet
Plaintext
	    if( players_alive == 1 )

broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
... because there isn't anything to prevent it from looping again - assuming that this whole function is looped somewhere or is called more than once - it'll just keep adding to each players round_won var without really stopping.

Try adding:

Code Snippet
Plaintext
level waittill( "between_round_over" );

right before this:

Code Snippet
Plaintext
	    if( players_alive == 1 )

But it's in a mod where the round never ends, it's round 15 with a very high amount of zombies, and when theres only one player left the round restarts and all the other players spawn back in.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
But it's in a mod where the round never ends, it's round 15 with a very high amount of zombies, and when theres only one player left the round restarts and all the other players spawn back in.

and your testing this in SP, correct? That would be why it isn't working - the condition would always be true because there is always one player in SP and they are always valid players.

Just add a size comparison to determine if the game is coop or not:

Code Snippet
Plaintext
if(players.size > 1 && players_alive == 1 )

This would make sure that it only runs if there are more than one player in the game. Your going to have to test the script in COOP though - no real way around it.
Last Edit: June 10, 2015, 02:46:05 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: usUnited States
Date Registered: 13 May 2014
Last active: 5 days ago
Posts
167
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
jbird's Groups
I tested it in coop and it does the same thing. I guess I will have to stick with the level variable for now

 
Loading ...