Solved Get score points for all players

Question that is answered or resolved.

dantedevil

Well-known member
I want to modify the script of this animation, so that I can give score to all the players that are in game. This is for the bonus stage, so if they succeed, give the bonus to both.
My mod has 3 players in game.

Code:
anim follow1
    delay    1
    offset    1 1
@script
  if(frame==1){
    void target = getlocalvar("opponent");

    int PIndex = getentityproperty(target,"playerindex"); // Get player's index
    int PScore = getplayerproperty(PIndex, "score");
  
    changeplayerproperty(PIndex, "score", PScore+15000);
  }
@end_script
    frame    data/chars/misc/empty.png
 
Last edited:
Solution
It seems P1Score isn't declared at all because it doesn't have a function for it to call. You have just ScoreP1 as player 1's own score.

It goes something like this:

Code:
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    void P3 = getplayerproperty(2, "entity");

    void ScoreP1 = getplayerproperty(P1, "score"); // Player 1's own score
    void ScoreP2 = getplayerproperty(P2, "score"); // Player 2's own score
    void ScoreP3 = getplayerproperty(P3, "score"); // Player 3's own score
   
    changeplayerproperty(P1, "score", ScoreP1+3000); // Changing player 1's score with given points
    changeplayerproperty(P2, "score", ScoreP2+3000);
    changeplayerproperty(P3, "score"...
There is no need to check the target.
You can get the players like I did here (you will need to add one more line to add the p3, just follow the logic) http://www.chronocrash.com/forum/index.php?topic=3610.msg50090#msg50090

Them you check it each player are available and proceed with the score code.
 
Well my friend, I try but not work.

Here my try :
Code:
anim follow1
	delay	1
	offset	1 1
@script
  if(frame==1){
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    void P3 = getplayerproperty(2, "entity");

    void ScoreP1 = getplayerproperty(P1, "score");
    void ScoreP2 = getplayerproperty(P2, "score");
    void ScoreP3 = getplayerproperty(P3, "score");
   
    changeplayerproperty(P1, "score", P1Score+3000);
    changeplayerproperty(P2, "score", P2Score+3000);
    changeplayerproperty(P3, "score", P3Score+3000);
  }
@end_script
	frame	data/chars/misc/empty.png
	frame	data/chars/misc/empty.png
	frame	data/chars/misc/empty.png
 
O Ilusionista said:
Please, be more descriptive.
What exactly happens?

Sorry!

Here the log error:
Code:
Script compile error in 'text': P1Score line 231, column 38

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

Can't compile script 'text' data/chars/misc/dialogue/text.txt
 
It seems P1Score isn't declared at all because it doesn't have a function for it to call. You have just ScoreP1 as player 1's own score.

It goes something like this:

Code:
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    void P3 = getplayerproperty(2, "entity");

    void ScoreP1 = getplayerproperty(P1, "score"); // Player 1's own score
    void ScoreP2 = getplayerproperty(P2, "score"); // Player 2's own score
    void ScoreP3 = getplayerproperty(P3, "score"); // Player 3's own score
   
    changeplayerproperty(P1, "score", ScoreP1+3000); // Changing player 1's score with given points
    changeplayerproperty(P2, "score", ScoreP2+3000);
    changeplayerproperty(P3, "score", ScoreP3+3000);

Be careful with names you declare.
 
Solution
I think you can add a check if the players are available before proceed into anything, like this:

Code:
void P1 = getplayerproperty(0, "entity"); // Get P1
void P2 = getplayerproperty(1, "entity"); // Get P2
void P3 = getplayerproperty(2, "entity"); // Get P3

if (P1){// Check if P1 is present
    void ScoreP1 = getplayerproperty(P1, "score"); // Player 1's own score
    changeplayerproperty(P1, "score", ScoreP1+3000); // Changing player 1's score with given points
}
if (P2){ // Check if P2 is present
    void ScoreP2 = getplayerproperty(P2, "score"); // Player 2's own score
    changeplayerproperty(P2, "score", ScoreP2+3000);
}
if (P3){ // Check if P3 is present
    void ScoreP3 = getplayerproperty(P3, "score"); // Player 3's own score
    changeplayerproperty(P3, "score", ScoreP3+3000);
}

So if a player isn't present, the engine will just skip that code block and won't try to calculate things it doens't need to.
 
O Ilusionista said:
I think you can add a check if the players are available before proceed into anything, like this:

Code:
void P1 = getplayerproperty(0, "entity"); // Get P1
void P2 = getplayerproperty(1, "entity"); // Get P2
void P3 = getplayerproperty(2, "entity"); // Get P3

if (P1){// Check if P1 is present
    void ScoreP1 = getplayerproperty(P1, "score"); // Player 1's own score
    changeplayerproperty(P1, "score", ScoreP1+3000); // Changing player 1's score with given points
}
if (P2){ // Check if P2 is present
    void ScoreP2 = getplayerproperty(P2, "score"); // Player 2's own score
    changeplayerproperty(P2, "score", ScoreP2+3000);
}
if (P3){ // Check if P3 is present
    void ScoreP3 = getplayerproperty(P3, "score"); // Player 3's own score
    changeplayerproperty(P3, "score", ScoreP3+3000);
}

So if a player isn't present, the engine will just skip that code block and won't try to calculate things it doens't need to.

With your update, give me this error:

Code:
Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'opt_else')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'stmt_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'comp_stmt3')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'opt_else')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'stmt_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'comp_stmt3')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'opt_else')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'stmt_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'decl_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 324: Unknown error '' (in production 'comp_stmt3')


^


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

Fatal Error in load_cached_model, file: data/chars/misc/dialogue/text.txt, line 204, message: Error parsing function main of animation script in file '%s'!
Total Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 98328576 Bytes

-- Setting up game... ----------

Loading title background sprites... Done!

-- LOG: Game proper ---------------------------

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 *****************

Fatal Error in load_cached_model, file: data/chars/misc/dialogue/text.txt, line 204, message: Error parsing function main of animation script in file '%s'!
 
Mmm.... if you're using getplayerproperty, you should input player's index instead of entity handle, like this:

Code:
void P1 = getplayerproperty(0, "entity"); // Get P1
void P2 = getplayerproperty(1, "entity"); // Get P2
void P3 = getplayerproperty(2, "entity"); // Get P3

if (P1){// Check if P1 is present
    void ScoreP1 = getplayerproperty(0, "score"); // Player 1's own score
    changeplayerproperty(0, "score", ScoreP1+3000); // Changing player 1's score with given points
}
if (P2){ // Check if P2 is present
    void ScoreP2 = getplayerproperty(1, "score"); // Player 2's own score
    changeplayerproperty(1, "score", ScoreP2+3000);
}
if (P3){ // Check if P3 is present
    void ScoreP3 = getplayerproperty(2, "score"); // Player 3's own score
    changeplayerproperty(2, "score", ScoreP3+3000);
}
 
Bloodbane said:
Mmm.... if you're using getplayerproperty, you should input player's index instead of entity handle, like this:

Code:
void P1 = getplayerproperty(0, "entity"); // Get P1
void P2 = getplayerproperty(1, "entity"); // Get P2
void P3 = getplayerproperty(2, "entity"); // Get P3

if (P1){// Check if P1 is present
    void ScoreP1 = getplayerproperty(0, "score"); // Player 1's own score
    changeplayerproperty(0, "score", ScoreP1+3000); // Changing player 1's score with given points
}
if (P2){ // Check if P2 is present
    void ScoreP2 = getplayerproperty(1, "score"); // Player 2's own score
    changeplayerproperty(1, "score", ScoreP2+3000);
}
if (P3){ // Check if P3 is present
    void ScoreP3 = getplayerproperty(2, "score"); // Player 3's own score
    changeplayerproperty(2, "score", ScoreP3+3000);
}

Not work my friend!

Code:
Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'opt_else')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'stmt_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'comp_stmt3')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'opt_else')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'stmt_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'decl_list2')


^



Script error: data/chars/misc/dialogue/text.txt, line 320: Unknown error '' (in production 'comp_stmt3')


^


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

Fatal Error in load_cached_model, file: data/chars/misc/dialogue/text.txt, line 204, message: Error parsing function main of animation script in file '%s'!
Total Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 98115584 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 *****************

Fatal Error in load_cached_model, file: data/chars/misc/dialogue/text.txt, line 204, message: Error parsing function main of animation script in file '%s'!

Only the script of maxman works ok with any errors:
Code:
@script
  if(frame==1){
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    void P3 = getplayerproperty(2, "entity");

    void ScoreP1 = getplayerproperty(P1, "score"); // Player 1's own 

score
    void ScoreP2 = getplayerproperty(P2, "score"); // Player 2's own 

score
    void ScoreP3 = getplayerproperty(P3, "score"); // Player 3's own 

score
   
    changeplayerproperty(P1, "score", ScoreP1+3000); // Changing player 

1's score with given points
    changeplayerproperty(P2, "score", ScoreP2+3000);
    changeplayerproperty(P3, "score", ScoreP3+3000);
}
@end_script
 
I think Bloodbane means this:

Code:
void self = getlocalvar("self"); // Get entity.
int index = getentityproperty(self, "playerindex"); // Get player index
int score = getplayerproperty(index, "score"); // Get player index's score

changeplayerproperty(index, "score", score+3000);

Or maybe...
Code:
void self = getlocalvar("self"); // Get entity.
int index = getentityproperty(self, "playerindex"); // Get player index
int score = getplayerproperty(index, "score"); // Get player index's score

if(index != NULL()){
changeplayerproperty(index, "score", score+3000);
}

Hmm... it seems that player index isn't checked whether it's null or not. Not sure if it can solve it.

Code:
void P1 = getplayerproperty(0, "entity"); // Get P1
void P2 = getplayerproperty(1, "entity"); // Get P2
void P3 = getplayerproperty(2, "entity"); // Get P3

if (P1 != NULL()){// Check if P1 is present
    void ScoreP1 = getplayerproperty(0, "score"); // Player 1's own score
    changeplayerproperty(0, "score", ScoreP1+3000); // Changing player 1's score with given points
}
if (P2 != NULL()){ // Check if P2 is present
    void ScoreP2 = getplayerproperty(1, "score"); // Player 2's own score
    changeplayerproperty(1, "score", ScoreP2+3000);
}
if (P3 != NULL()){ // Check if P3 is present
    void ScoreP3 = getplayerproperty(2, "score"); // Player 3's own score
    changeplayerproperty(2, "score", ScoreP3+3000);
}

 
maxman said:
I think Bloodbane means this:

No, that's not what I meant :)

Getting desired player's entity handle is easy and straightforward, contrast to getting NPC, enemy or obstacle. That's why for score giving script like this, it's not needed to acquire self to get player index from it

dantedevil said:
Only the script of maxman works ok with any errors:

Actually it does have error which I've posted above. Try that with all 3 players available. I've tried with 2 players and player 2 doesn't get score updated when script is run

I've tried running the fixed script in level script and it works properly with 2 players (can't test with 3 players but I'm sure it)

OTOH the error message you posted above looks like from other problem. Maybe it's because of how the script is typed? Have to see the full script to know
 
Back
Top Bottom