Death system, need answers.
#1

Hello there dear community, I've run into a problem regarding my death system on my server and can't figure out how to get it to work. I've tried most ways but it still returns problems.




This is my timer callback. Earlier it looped through all players and decided which of those had the variable pDeath as 1. Everything worked until I tried putting two players on the same time in death mode. It resulted in that when the second player died it first saw the other players timer textdraw and then it's own,

Код:
public DeathTimer(playerid)
{
    
	if(PlayerInfo[playerid][pDead] == 1){
	if(PlayerInfo[playerid][pDeadTimer] == 0){
	PlayerInfo[playerid][pDead] = 0;
	SpawnPlayer(playerid);
	GivePlayerMoney(playerid, 100);
     SendClientMessage(playerid, COLOR_LIGHTBLUE, "You died, remember that you can't remember getting killed.!");
    TextDrawHideForPlayer(playerid, Textdraw0);
	}
	else if(PlayerInfo[playerid][pDeadTimer] < 61){
	if(PlayerInfo[playerid][pDeadAnim] == 1)
	{
	PlayerInfo[playerid][pDeadAnim] = 0;
	TogglePlayerControllable(playerid,false);
	ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,0,1);
	}
	
	PlayerInfo[playerid][pDeadTimer]--;
	new string[128];
	format(string,sizeof(string),"Time until \nrespawn:\n%d seconds",PlayerInfo[playerid][pDeadTimer]);
	TextDrawShowForPlayer(playerid, Textdraw0);
	TextDrawSetString(Textdraw0, string);
	}
	}
	

	
}
After that I tried making it like this.. instead of looping through all players I just added playerid on every single one and then put the SetTimerEx in OnPlayerDeath. That resulted in that both timers were mixed up and everything went wrong.


In OnPlayerDeath

[code] PlayerInfo[playerid][pDeadTimer] = 60;
TextDrawShowForPlayer(playerid,Textdraw0);[code]


So do you have any suggestions on how to fix this problem?
Reply
#2

Textdraw0 - you are using single TextDraw variable. You need to create array of textdraws (Text:Textdraw0[MAX_PLAYERS]) and use Textdraw0[playerid] instead
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Textdraw0 - you are using single TextDraw variable. You need to create array of textdraws (Text:Textdraw0[MAX_PLAYERS]) and use Textdraw0[playerid] instead
So if I change back to the loop in my time callback and add a variable, should it work then? I guess this playerid thing doesn't work.
Reply
#4

pawn Код:
new Timers[MAX_PLAYERS];
new Text:Textdraw0[MAX_PLAYERS] = { Text:INVALID_TEXT_DRAW, ... };
//OPD:
PlayerInfo[playerid][pDeadTimer] = 60;
TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
Timers[playerid] = SetTimerEx(...);

public DeathTimer(playerid)
{
    if(PlayerInfo[playerid][pDead] == 1){
        if(PlayerInfo[playerid][pDeadTimer] == 0){
            KillTimer(Timers[playerid]);
            PlayerInfo[playerid][pDead] = 0;
            SpawnPlayer(playerid);
            GivePlayerMoney(playerid, 100);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "You died, remember that you can't remember getting killed.!");
            TextDrawHideForPlayer(playerid, Textdraw0[playerid]);
        }
        else if(PlayerInfo[playerid][pDeadTimer] < 61){
            if(PlayerInfo[playerid][pDeadAnim] == 1)
            {
                PlayerInfo[playerid][pDeadAnim] = 0;
                TogglePlayerControllable(playerid,false);
                ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,0,1);
            }
           
            PlayerInfo[playerid][pDeadTimer]--;
            new string[128];
            format(string,sizeof(string),"Time until \nrespawn:\n%d seconds",PlayerInfo[playerid][pDeadTimer]);
            TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
            TextDrawSetString(Textdraw0[playerid], string);
        }
    }  
}
#e: Also you have to find and replace all Textdraw0 assignments for all players accordingly

#e2: In fact - rebuild the system. Create array with users which are dead (I strongly recommend y_iterate to handle looping), and have only global timer - then loop only through dead players, not all
Reply
#5

Quote:
Originally Posted by Misiur
Посмотреть сообщение
pawn Код:
new Timers[MAX_PLAYERS];
new Text:Textdraw0[MAX_PLAYERS] = { Text:INVALID_TEXT_DRAW, ... };
//OPD:
PlayerInfo[playerid][pDeadTimer] = 60;
TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
Timers[playerid] = SetTimerEx(...);

public DeathTimer(playerid)
{
    if(PlayerInfo[playerid][pDead] == 1){
        if(PlayerInfo[playerid][pDeadTimer] == 0){
            KillTimer(Timers[playerid]);
            PlayerInfo[playerid][pDead] = 0;
            SpawnPlayer(playerid);
            GivePlayerMoney(playerid, 100);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "You died, remember that you can't remember getting killed.!");
            TextDrawHideForPlayer(playerid, Textdraw0[playerid]);
        }
        else if(PlayerInfo[playerid][pDeadTimer] < 61){
            if(PlayerInfo[playerid][pDeadAnim] == 1)
            {
                PlayerInfo[playerid][pDeadAnim] = 0;
                TogglePlayerControllable(playerid,false);
                ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,0,1);
            }
           
            PlayerInfo[playerid][pDeadTimer]--;
            new string[128];
            format(string,sizeof(string),"Time until \nrespawn:\n%d seconds",PlayerInfo[playerid][pDeadTimer]);
            TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
            TextDrawSetString(Textdraw0[playerid], string);
        }
    }  
}
#e: Also you have to find and replace all Textdraw0 assignments for all players accordingly

#e2: In fact - rebuild the system. Create array with users which are dead (I strongly recommend y_iterate to handle looping), and have only global timer - then loop only through dead players, not all



How should the OnGameModeInit variables look? Because if I put Textdraw0[MAX_PLAYERS] there it says that the array is out of bounds.. Should it be Textdraw[MAX_PLAYERS-1]?
Reply
#6

Show me your current OnGameModeInit (at least with textdraws part)
Reply
#7

This is still without the [MAX_PLAYERS] since it gave lots of errors.
Код:
Textdraw0 = TextDrawCreate(557.000000, 120.000000, "");
    TextDrawAlignment(Textdraw0, 2);
    TextDrawBackgroundColor(Textdraw0, 255);
    TextDrawFont(Textdraw0, 1);
    TextDrawLetterSize(Textdraw0, 0.440000, 1.600000);
    TextDrawColor(Textdraw0, -16776961);
    TextDrawSetOutline(Textdraw0, 1);
    TextDrawSetProportional(Textdraw0, 1);
    TextDrawUseBox(Textdraw0, 1);
    TextDrawBoxColor(Textdraw0, 255);
    TextDrawTextSize(Textdraw0, 50.000000, 150.000000);
Reply
#8

Ok, so
1. Remove everthing from OnGameModeInit, and remove Textdraw0 variable

pawn Код:
//Global variables
static Timers[MAX_PLAYERS];
static Text:Textdraw0[MAX_PLAYERS] = { Text:INVALID_TEXT_DRAW, ... };

//OnPlayerDeath
PlayerInfo[playerid][pDeadTimer] = 60;
if(Text:Textdraw0[playerid] == Text:INVALID_TEXT_DRAW) DrawStuff(Textdraw0[playerid]);
TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
Timers[playerid] = SetTimerEx("DeathTimer", XXX, "i", playerid);

//Later
public DeathTimer(playerid)
{
    if(PlayerInfo[playerid][pDead] == 1){
        if(PlayerInfo[playerid][pDeadTimer] == 0){
            KillTimer(Timers[playerid]);
            PlayerInfo[playerid][pDead] = 0;
            SpawnPlayer(playerid);
            GivePlayerMoney(playerid, 100);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "You died, remember that you can't remember getting killed.!");
            TextDrawHideForPlayer(playerid, Textdraw0[playerid]);
        }
        else if(PlayerInfo[playerid][pDeadTimer] < 61){
            if(PlayerInfo[playerid][pDeadAnim] == 1)
            {
                PlayerInfo[playerid][pDeadAnim] = 0;
                TogglePlayerControllable(playerid,false);
                ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,0,1,1,1,0,1);
            }
           
            PlayerInfo[playerid][pDeadTimer]--;
            new string[128];
            format(string,sizeof(string),"Time until \nrespawn:\n%d seconds",PlayerInfo[playerid][pDeadTimer]);
            TextDrawShowForPlayer(playerid, Textdraw0[playerid]);
            TextDrawSetString(Textdraw0[playerid], string);
        }
    }  
}

stock DrawStuff(&Text:td) {
    td = TextDrawCreate(557.000000, 120.000000, "_");
    TextDrawAlignment(td, 2);
    TextDrawBackgroundColor(td, 255);
    TextDrawFont(td, 1);
    TextDrawLetterSize(td, 0.440000, 1.600000);
    TextDrawColor(td, -16776961);
    TextDrawSetOutline(td, 1);
    TextDrawSetProportional(td, 1);
    TextDrawUseBox(td, 1);
    TextDrawBoxColor(td, 255);
    TextDrawTextSize(td, 50.000000, 150.000000);
}
Reply
#9

Thanks, works like a charm when I try it myself, I guess I won't have the same problem when I test it with more players at the same time. Do you still have an answer on why the animation is not triggered? If I do my /crack command at first and then die it works but else the guy just stands there without any animation.
Reply
#10

Hm, could you show me your /crack command? I don't know much about animations, but maybe there might be some problem with fact that player is dead, so you can't apply animation.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)