String Setup Like PNameJ With Script

maxman

Well-known member
I can hide player name and score with script after player is killed out. But to continue or join, I need something that helps calling drawstring (with script) similar to pnamej. I plan to use font2 for player 1 and font for player 2 in drawstring for any player to join in. I have keys for Left, Right, and Start prepared, along player entity and its name. Even with a for loop which I plan to use to loop with or for drawstring. Would I need to use a for loop like pnamej?
 
I was trying this out with player 2 by going with join2.c. But I got dis error. Any how to do for aligning player 2 texts for "Credits", "Press Start", etc.?

join2.c:

Code:
void main(){
	// Player 2 joins
	
	int i;
	void CountEnt = openborvariant("count_entities");
	int Time = openborvariant("elapsed_time");
	int iEnt;
	void vEnt;
	
	for(i = 0; i < CountEnt; i++){
		vEnt = getentity(i);
		if(getentityproperty(vEnt, "exists")){
			void type = getentityproperty(vEnt, "type");
			
			if(type == openborconstant("TYPE_PLAYER")){
				int P2 = getplayerproperty(1, "entity");
				
				if(P2 == NULL()){
					int P2Start = playerkeys(P2, 1, "start");
					
					if(P2Start){
						char P2Name = getentityproperty(P2, "name");
						int hres = openborvariant("hresolution");
						
						if(P2Name){
							drawstring(hres-27-strwidth(p2Name, 0), 55, 0, p2Name);
							drawstring(hres-27-strwidth("Select_Hero", 0), 43, 0, "Select_Hero");
							break;
						} // drawstring
					} // Press start
				} // Player 2 is empty
			} // Calling type player
		} // entity, "exists"
	} // Using a for loop
	
}

log:

Code:
Total Ram: 4168376320 Bytes
 Free Ram: 1281961984 Bytes
 Used Ram: 3710976 Bytes

debug:nativeWidth, nativeHeight, bpp, Hz  1366, 768, 24, 60
OpenBoR v3.0 Build , Compile Date: Dec 12 2016

Game Selected: ./Paks/My Mod.pak

FileCaching System Init......	Disabled
Initializing video............
Reading video settings from 'data/video.txt'.
Initialized video.............	320x240 (Mode: 0, Depth: 32 Bit)

Loading menu.txt.............	Done!
Loading fonts................	1 2 3 4 5 7 8 9 10 Done!
Timer init...................	Done!
Initialize Sound..............	
Loading sprites..............	Done!
Loading level order..........	Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Command 'versusdamage' not understood in level order!Done!
Loading model constants......	Done!
Loading script settings......	Done!
Loading scripts..............	
Script compile error in 'join': p2Name line 26, column 75

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'join' 
Total Ram: 4168376320 Bytes
 Free Ram: 1254531072 Bytes
 Used Ram: 19292160 Bytes

Release level data...........
Done!

Release graphics data........	Done!
Release game data............


Release game data............	Done!
Release timer................	Done!
Release input hardware.......	Done!
Release sound system.........	Done!
Release FileCaching System...	Done!

**************** Done *****************

Can't compile script 'join'
 
Extra brace/bracket? (How?) Hmm... I put brackets together beginning with void main and the for loop... Is it the wrong input of player?
 
here:
if(getentityproperty(vEnt, "exists")){

There is a missing parenthesis
When you see this type of error "Invalid function call or expression '{' (in production 'postfix_expr2')"  is ALWAYS a missing bracket or parenthesis at the code.
 
I got it working but somehow, the text alignment for the player name and "Select_Hero" is not displaying at all.

Code:
void main(){
	// Player 2 joins
	
	int i;
	void CountEnt = openborvariant("count_entities");
	int Time = openborvariant("elapsed_time");
	int iEnt;
	void vEnt;
	
	for(i = 0; i < CountEnt; i++){
		vEnt = getentity(i);
		if(getentityproperty(vEnt, "exists")){
			void type = getentityproperty(vEnt, "type");
			
			if(type == openborconstant("TYPE_PLAYER")){
				int P2 = getplayerproperty(1, "entity");
				
				if(P2 == NULL()){
					int P2Start = playerkeys(P2, 1, "start");
					
					if(P2Start){
						char P2Name = getentityproperty(P2, "name");
						int hres = openborvariant("hresolution");
						
						if(P2Name){
							drawstring(hres-27-strwidth(P2Name, 0), 55, 0, P2Name);
							drawstring(hres-27-strwidth("Select_Hero", 0), 43, 0, "Select_Hero");
							break;
						} // drawstring
					} // Press start
				} // Player 2 is empty
			} // Calling type player
		} // entity, "exists"
	} // Using a for loop
	
}

EDIT: Should I put that for ondeathscript?
 
Something I couldn't figure out: why are you counting the entities, if you are using this just for players?

It would be better to just use
Code:
void P1 = getplayerproperty(0, "entity"); // Gets the Player 1
void P2 = getplayerproperty(1, "entity"); // Gets the Player 2

So you would get P1 and P2 right out of the bat, with no need to make the engine to count entities, check if they exists and check their types.

Then you follow the logic
Code:
if(P1){
*insert your logic here*
} 

if(P2){
*insert your logic here*
}

Should I put that for ondeathscript?
Ondeathscript fires only once*, when the entity dies. On the next update cycle, its gone AFAIK.
And by the way there is a difference between ONDEATHSCRIPT and ONKILLSCRIPT. If an entity falls and dies on a hole, ONDEATH script won't trigger - but ONKILL will do.

*this is how is should work, but seams that variables set with ondeath are active even before the scrip trigger. I need to report this, btw.
 
Back
Top Bottom