[SCRIPT] Jump to Branch based on Live count

O Ilusionista

Captain 100K
I've made this code by request and I think it could be useful to other people.
It will jumpt to one branch if the live count is bigger than a specific value; If not, jump to another one.
The code care about the player count, so if there are 2, 3 or 4 players, the value is higher.

Paste it on your animationscript

Code:
void changeBranchByLiveCount(char branchHigh, char branchLow, int now) {
	// Change to specific branch based on live count
	// Douglas Baldan / O Ilusionista -  2018.02.11
int players=openborvariant("count_players"); // Count Players	
int P1 = getplayerproperty(0, "entity"); // Set P1
int P2 = getplayerproperty(1, "entity"); // Set P2
int P3 = getplayerproperty(2, "entity"); //Set P3
int P4 = getplayerproperty(3, "entity"); //Set P4
	
int pLive1 = getplayerproperty(P1, "lives"); //Count P1 lives
int pLive2 = getplayerproperty(P2, "lives"); //Count P2 lives
int pLive3 = getplayerproperty(P3, "lives"); //Count P3 lives
int pLive4 = getplayerproperty(P4, "lives"); //Count P4 lives

if (players==4) // 4 Players
{
	int livesTotal = pLive1 + pLive2 + pLive3 + pLive4; // Sum lives
	if (livesTotal>8) 
	{
		jumptobranch(branchHigh, now);
	} else 
	{
		jumptobranch(branchLow, now);
	}
}

else if (players==3) // 3 Players
{
	int livesTotal = pLive1 + pLive2 + pLive3; // Sum lives
	if (livesTotal>6) 
	{
		jumptobranch(branchHigh, now);
	} else 
	{
		jumptobranch(branchLow, now);
	}
}

else if (players==2) // 2 Players
{
	int livesTotal = pLive1 + pLive2; // Sum lives
	if (livesTotal>4) 
	{
		jumptobranch(branchHigh, now);
	} else 
	{
		jumptobranch(branchLow, now);
	}
}

else // 1 player
{
	int livesTotal = pLive1; // Sum lives
	if (livesTotal>2) 
	{
		jumptobranch(branchHigh, now);
	} else 
	{
		jumptobranch(branchLow, now);
	}
}

}

Usage:
@cmd changeBranchByLiveCount "branch2" "branch1" 1

Notes:
- The second branch name should be set before the first one
- The branch name must be in quotes
- the last value controls the jumpbranch. If is 0, the branch happens after the level end. But if its 1, jumps right now.


PS: I pass the branch names using "char". Is there any difference of using "char" over "void"?
 
Use char as it is the correct variable type. I think when you use void openbor guesses what type you wanted and sets it accordingly.
 
msmalik681 said:
Use char as it is the correct variable type. I think when you use void openbor guesses what type you wanted and sets it accordingly.

That's not how it works. OpenBOR Script is weak typed, meaning the engine ALWAYS chooses the type, no matter what you do.

It is still important to use the correct type declaration though, for several reasons. Chiefly debugging.

See here for details.

DC
 
Back
Top Bottom