Pixel

Identifying a certain player's death which has a variable

9 posts in this topic

I'm trying to work out how to detect when a player which has an assigned variable dies.

 

So if they have self.raid = 1; the script will continuously check to see if the player which has that variable is dead. In the meantime, other players will have self.raid = 2; etc. When the person with self.raid = 1; dies, the person with the self.raid = 2; gets self.raid = 1;

 

etc

 

if that explanation mind fucked you in anyway, i will try explain further, cheers ;)

0

Share this post


Link to post
Share on other sites

THIS IS NOT TESTED, PROBABLY BUGS.

theThreadName()
{
	while(true)
	{
		if(!isAlive(self))
			updateOtherPlayers(self.raid); //run this function when the player dies
	}
}

//num is the var of the dead player's self.raid value
updateOtherPlayers(num)
{
	players = getALlPlayers(); //get all of the players in game
	for(index=0; index<players.size; index++)
	{
		//if the player's self.raid value is less than the dead one's then it doesn't change
		if(players[index].raid < num)
			continue;

		//if the player's self.raid value is greater than the dead one's it is reduced by one
		elif(players[index].raid > num)
			players[index].raid -= 1;
	}
}


/*

for example, player with self.raid = 3 dies; num = 3
goes through each player's self.raid value
when the player's value is 1 it doesn't need to be updated
when the player's value is 2 it doesn't need to be updated
the player with value 3 is now dead so nothing happens here
when the player's value is 4 it is updated to become 3 and take the dead person's place
when the player's value is 5 it is updated to become 4 and takes #4s place
so on and so forth

*/

I don't have much time, this is something I typed up in about 5 mins so expect there to be flaws.

1

Share this post


Link to post
Share on other sites

// thread on all players

// Slaya is a cunt

hasDied()

{

while( true )

{

self waittill("death");

if( !isDefined(self.raid) )

continue;

// put code you want to execute under here.

}

}

Edited by AoKMiKeY
Slaya is a nub
1

Share this post


Link to post
Share on other sites

Thanks for the help both of you, and Mikey how does that make the person with self.variable =2; to go to self.variable = 1; when self.variable = 1; dies?

 

I will look through your code sentrex and see if i can implement it thank you, and yours too mikey! :)

0

Share this post


Link to post
Share on other sites

Thanks for the help both of you, and Mikey how does that make the person with self.variable =2; to go to self.variable = 1; when self.variable = 1; dies?

 

I will look through your code sentrex and see if i can implement it thank you, and yours too mikey! :)

// thread on all players 
// Slaya is a cunt

hasDied()
{
    while( true )
    {
        self waittill("death");
        if( !isDefined(self.raid) )
            continue;
        
        // put code you want to execute under here. 
        if( self.raid == 1 )
            self.raid == 0;
        if( self.raid == 0 )
            self.raid == 1;
    }
}

You have to be kidding me right :P Sentrexs is pointless. 

1

Share this post


Link to post
Share on other sites
// thread on all players 
// Slaya is a cunt

hasDied()
{
    while( true )
    {
        self waittill("death");
        if( !isDefined(self.raid) )
            continue;
        
        // put code you want to execute under here. 
        if( self.raid == 1 )
            self.raid == 0;
        if( self.raid == 0 )
            self.raid == 1;
    }
}

You have to be kidding me right :P Sentrexs is pointless. 

 

Not sure, you guys are way more experienced than me, hence why I am posting ;) thanks

0

Share this post


Link to post
Share on other sites

The question is what you are trying to achieve here... An explanation would mean we could be more accurate as well. :sir:

 

// =============================================================================
// Initialize the raid script.
// =============================================================================
init()
{
    // Array containing players.
    level.raid = [];

    thread onPlayerConnect();
}

// =============================================================================
// Watch for new player connections.
// =============================================================================
onPlayerConnect()
{
    level endon("game_ended");
    
    for (;;)
    {
        level waittill("connected", player);
        player thread handlePlayer();
    }
}

// =============================================================================
// Do some player specific shit I guess.
// =============================================================================
handlePlayer()
{
    level endon("disconnect");
}

// =============================================================================
// Add a player to the array.
//   <player> The player that has to be added.
//   [self] The player that has to be added.
// =============================================================================
addPlayer(player)
{
    if (!isDefined(player))
        player = self;

    if (isDefined(player.pers["team"]) && (player.pers["team"] == "allies" || player.pers["team"] == "axis"))
        level.raid[level.raid.size] = player;
}

// =============================================================================
// Determines if the player is present in the array.
//   <player> The player that we want to know from if he is in the array.
//   [self] The player that we want to know from if he is in the array.
//   [return] The index in the array [0, level.raid.size[ or -1 if not present.
// =============================================================================
isRaid(player)
{
    if (!isDefined(player))
        player = self;

    for (i = 0; i < level.raid.size; i++)
    {
        if (level.raid[i] == player)
            return i;
    }
    
    return -1;
}

// =============================================================================
// Repopulates the array with all the players.
// =============================================================================
repopulate()
{
    level.raid = [];

    players = getEntArray("player", "classname");
    for (i = 0; i < players.size; i++)
    {
        addPlayer(players[i]);
    }
}

// =============================================================================
// Shift the players after the given player in the array.
//   <player> The player that has to be removed from the array.
//   [self] The player that has to be removed from the array.
// =============================================================================
shift(player)
{
    if (!isDefined(player))
        player = self;

    for (i = 0; i < level.raid.size; i++)
    {
        current = level.raid[i];
        
        if (current == player)
        {
            for (i++; i < level.raid.size; i++)
            {
                if (i == (level.raid.size - 1))
                {
                    level.raid[i] = undefined;
                }
                else
                {
                    level.raid[i-1] = level.raid[i];
                }
            }
        }
    }
}
 
0

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now