Timer problem
#1

ok so i am trying to make a a text draw that shows up when you get shot and it tells you how much dmg you took, so far i have this, it compiles and when you get shot it shows you what you lost but the text draws do not go away.
this is my first attempt at using a timer so if someone could point me in the right direction I would appreciate it!

Код:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    new msg[128],name1[24],name2[24], msg2[128];
	dtxtdraw = TextDrawCreate(400.0,280.0, "~r~ -, health");
	dtxtdraz = TextDrawCreate(450.0,280.0, "~b~ -, armour");
	format(msg, sizeof(msg), "~r~ -%f, health", HealthLost);
	format(msg2, sizeof(msg2), "~b~ -%f, armour", ArmourLost);
	TextDrawSetString(dtxtdraw, msg);
	TextDrawSetString(dtxtdraz, msg2);
	TextDrawShowForPlayer(Target, dtxtdraw);
	TextDrawShowForPlayer(Target, dtxtdraz);
	timer1 = SetTimer("mytimer", 1000, false);
	GetPlayerName(Shooter,name1,24);
    GetPlayerName(Target,name2,24);
	CreateObject(1240, 0, 0, 0, 0.0, 0.0, 0.0, 0.0);
	AttachObjectToPlayer(1, Target, 0.0, 0.0, 1.0, 0, 0, 0);
 	return 1;

}
public mytimer(playerid)
{
	TextDrawHideForPlayer(playerid, dtxtdraw);
	TextDrawHideForPlayer(playerid, dtxtdraw);
	KillTimer(timer1);
	return 1;
}
Reply
#2

Код:
new
timer1[MAX_PLAYERS];
forward mytimer(playerid); public OnGameModeInit() {
dtxtdraw[MAX_PLAYERS] = TextDrawCreate(400.0,280.0, "~r~ -, health"); dtxtdraz[MAX_PLAYERS] = TextDrawCreate(450.0,280.0, "~b~ -, armour"); return 1;
} public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost) {
new
msg[128], msg2[128];
format(msg, sizeof(msg), "~r~ -%f, health", HealthLost); format(msg2, sizeof(msg2), "~b~ -%f, armour", ArmourLost); TextDrawSetString(dtxtdraw[playerid], msg); TextDrawSetString(dtxtdraz[playerid], msg2); TextDrawShowForPlayer(Target, dtxtdraw[playerid]); TextDrawShowForPlayer(Target, dtxtdraz[playerid]); timer1[playerid] = SetTimerEx("mytimer", 1000, false, "d", Target); return 1;
} public mytimer(playerid) {
TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); KillTimer(timer1[playerid]); return 1;
}
The above code was posted by you, modified by me.
The above code was not tested!
The above code requires San Andreas Multiplayer 0.3d RC2 and up.

Do not forget to +rep me if this worked or explain further if the problem persists.
Reply
#3

try
pawn Код:
timer1 = SetTimerEx("mytimer", 1000, false, "d", playerid /*or try Target than playerid*/);
Reply
#4

@System64 that wont fully work because his variables arn't linked to the playerid.

@random123 My code should work, if it doesn't post compile errors here so I can fix.
Reply
#5

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
Код:
new
timer1[MAX_PLAYERS];
forward mytimer(playerid); public OnGameModeInit() {
dtxtdraw[MAX_PLAYERS] = TextDrawCreate(400.0,280.0, "~r~ -, health"); dtxtdraz[MAX_PLAYERS] = TextDrawCreate(450.0,280.0, "~b~ -, armour"); return 1;
} public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost) {
new
msg[128], msg2[128];
format(msg, sizeof(msg), "~r~ -%f, health", HealthLost); format(msg2, sizeof(msg2), "~b~ -%f, armour", ArmourLost); TextDrawSetString(dtxtdraw[playerid], msg); TextDrawSetString(dtxtdraz[playerid], msg2); TextDrawShowForPlayer(Target, dtxtdraw[playerid]); TextDrawShowForPlayer(Target, dtxtdraz[playerid]); timer1[playerid] = SetTimer("mytimer", 1000, false, "d", playerid); return 1;
} public mytimer(playerid) {
TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); KillTimer(timer1[playerid]); return 1;
}
The above code was created by you, modified by me.
The above code was not tested!
The above code requires San Andreas Multiplayer 0.3d RC2 and up.

Do not forget to +rep me if this worked or explain further if the problem persists.
Thanks for the help but I am using .3c rc5
Quote:
Originally Posted by System64
Посмотреть сообщение
try
pawn Код:
timer1 = SetTimerEx("mytimer", 1000, false, "d", playerid /*or try Target than playerid*/);
testing this now
Reply
#6

Quote:
Originally Posted by random123
Посмотреть сообщение
Thanks for the help but I am using .3c rc5
Note how I said "and up" meaning 0.3d rc2 - rc5
Reply
#7

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
@System64 that wont fully work because his variables arn't linked to the playerid.

@random123 My code should work, if it doesn't post compile errors here so I can fix.
How I said, if playerid doesn't work than try Target or Shooter, you code won't work, It must be SetTimerEx not SetTimer and you also use playerid?
Reply
#8

Oh I used playerid because I am used to playerid not Target xD ... My bad.

The reason I say yours isn't going to work is because, say if three people get shot at the same exact time, all three players will get the third player's health loss and not their own.

Thats why this...

Код:
new
timer1[MAX_PLAYERS];
forward mytimer(playerid); public OnGameModeInit() {
dtxtdraw[MAX_PLAYERS] = TextDrawCreate(400.0,280.0, "~r~ -, health"); dtxtdraz[MAX_PLAYERS] = TextDrawCreate(450.0,280.0, "~b~ -, armour"); return 1;
} public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost) {
new
msg[128], msg2[128];
format(msg, sizeof(msg), "~r~ -%f, health", HealthLost); format(msg2, sizeof(msg2), "~b~ -%f, armour", ArmourLost); TextDrawSetString(dtxtdraw[Target], msg); TextDrawSetString(dtxtdraz[Target], msg2); TextDrawShowForPlayer(Target, dtxtdraw[Target]); TextDrawShowForPlayer(Target, dtxtdraz[Target]); timer1[Target] = SetTimerEx("mytimer", 1000, false, "d", Target); return 1;
} public mytimer(playerid) {
TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); KillTimer(timer1[playerid]); return 1;
}
... is better.

You had the right idea, but it would've cause bugs.
Reply
#9

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
Oh I used playerid because I am used to playerid not Target xD ... My bad.

The reason I say yours isn't going to work is because, say if three people get shot at the same exact time, all three players will get the third player's health loss and not their own.

Thats why this...

Код:
new
timer1[MAX_PLAYERS];
forward mytimer(playerid); public OnGameModeInit() {
dtxtdraw[MAX_PLAYERS] = TextDrawCreate(400.0,280.0, "~r~ -, health"); dtxtdraz[MAX_PLAYERS] = TextDrawCreate(450.0,280.0, "~b~ -, armour"); return 1;
} public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost) {
new
msg[128], msg2[128];
format(msg, sizeof(msg), "~r~ -%f, health", HealthLost); format(msg2, sizeof(msg2), "~b~ -%f, armour", ArmourLost); TextDrawSetString(dtxtdraw[Target], msg); TextDrawSetString(dtxtdraz[Target], msg2); TextDrawShowForPlayer(Target, dtxtdraw[Target]); TextDrawShowForPlayer(Target, dtxtdraz[Target]); timer1[Target] = SetTimerEx("mytimer", 1000, false, "d", Target); return 1;
} public mytimer(playerid) {
TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); TextDrawHideForPlayer(playerid, dtxtdraw[playerid]); KillTimer(timer1[playerid]); return 1;
}
... is better.

You had the right idea, but it would've cause bugs.
Ok i put it in and it compiled, will test in a bit
Reply
#10

Ok it works thanks for the help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)