A little problem,need help
#1

Hello,
i got a problem,i tried to make something that checks that if your health gets under 25.0 it will create
a pickup that will heal you.anyway here is the code:
pawn Код:
forward health1(playerid);
new Life;
OnPlayerSpawn
pawn Код:
SetTimer("health1",1,false);
In the bottom of the script
pawn Код:
public health1(playerid)
{
    new Float:health;
  GetPlayerHealth(playerid,health);
  if (health < 25.0)
  {
    SendClientMessage(playerid,COLOR_PURPLE,"Wow looks like you're injured badly!take the heart pickup to heal yourself.");
    new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        Life = AddStaticPickup(1240,2,x+2.00,y+2.34,z,0);
  }
}
OnPlayerPickUpPickup
pawn Код:
if(pickupid == Life) SetPlayerHealth(playerid,100);
Well the problem is that if my health goes under 25 nothing happens,i tried to change the repeating to "true" but than it just spammed pickups and messages.
Thanks in advance.
Reply
#2

according to this code, you should at least see the client message.
Therefore, I do not think it's the function is wrong.
The problem you are experiencing is that you use SetTimer instead of SetTimerEx

The difference is that SetTimer can't pass arguments, which SetTimerEx can.
As you can see, onplayerspawn you use SetTimer, therefore you aren't giving arguments, making your playerid not to be called.

replace
Код:
SetTimer("health1",1,false);
with
Код:
SetTimerEx("health1",10,false,"i",playerid);
//note, playerid is the number argument passed down to the public
Reply
#3

Stop the timer when your health is under 25.
Reply
#4

Quote:
Originally Posted by maij
according to this code, you should at least see the client message.
Therefore, I do not think it's the function is wrong.
The problem you are experiencing is that you use SetTimer instead of SetTimerEx

The difference is that SetTimer can't pass arguments, which SetTimerEx can.
As you can see, onplayerspawn you use SetTimer, therefore you aren't giving arguments, making your playerid not to be called.

replace
Код:
SetTimer("health1",1,false);
with
Код:
SetTimerEx("health1",10,false,"i",playerid);
//note, playerid is the number argument passed down to the public
Weird,now it shows only after i die and respawn
Edit:
@GTAguillaume,now it's just spams again lol
Reply
#5

You probably call the creation of the timer at the wrong time. Also, what you want is a timer that exists anytime.

Therefore, the interval should be at least 1 second. You will kill your server if you put it any lower in my opinion that is.
You should create this timer when the player connects and destroy it when they disconnect.

HOWEVER:
using this method will cause bugs. The pickup will not be picked up the ms after it got spawned, which causes the creation of another health icon. If your health is lower than 25, it will keep creating a new pickup. This means when you die, where a minimal 2 second interval is in between, it will already spawn 2 pickups.

I recommend you to do it otherwise, or better yet not doing it this way at all.
If so, use setplayerhealth or whatsoever instead of a pickup.
Reply
#6

Quote:
Originally Posted by maij
You probably call the creation of the timer at the wrong time. Also, what you want is a timer that exists anytime.

Therefore, the interval should be at least 1 second. You will kill your server if you put it any lower in my opinion that is.
You should create this timer when the player connects and destroy it when they disconnect.

HOWEVER:
using this method will cause bugs. The pickup will not be picked up the ms after it got spawned, which causes the creation of another health icon. If your health is lower than 25, it will keep creating a new pickup. This means when you die, where a minimal 2 second interval is in between, it will already spawn 2 pickups.

I recommend you to do it otherwise, or better yet not doing it this way at all.
If so, use setplayerhealth or whatsoever instead of a pickup.
Oh ok than,just thought it would be a pretty cool idea,
well thanks i guess i need to remove it :/
thanks for the help dude.
Reply
#7

Quote:
Originally Posted by O_x
Quote:
Originally Posted by maij
You probably call the creation of the timer at the wrong time. Also, what you want is a timer that exists anytime.

Therefore, the interval should be at least 1 second. You will kill your server if you put it any lower in my opinion that is.
You should create this timer when the player connects and destroy it when they disconnect.

HOWEVER:
using this method will cause bugs. The pickup will not be picked up the ms after it got spawned, which causes the creation of another health icon. If your health is lower than 25, it will keep creating a new pickup. This means when you die, where a minimal 2 second interval is in between, it will already spawn 2 pickups.

I recommend you to do it otherwise, or better yet not doing it this way at all.
If so, use setplayerhealth or whatsoever instead of a pickup.
Oh ok than,just thought it would be a pretty cool idea,
well thanks i guess i need to remove it :/
thanks for the help dude.
Try sumin like this

pawn Код:
new Life[MAX_PLAYERS] = -1;

public OnPlayerUpdate(playerid)
{
  new Float:Health; GetPlayerHealth(playerid,Health);
  if(Health <= 25.0 && Life[playerid] == -1)
  {
    SendClientMessage(playerid,COLOR_PURPLE,"Wow looks like you're injured badly!take the heart pickup to heal yourself.");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Life[playerid] = AddStaticPickup(1240,2,X+2.00,Y+2.34,Z,0);
  }
  return 1;
}

public OnPlayerPickUpPickup(playerid,pickupid)
{
  if(pickupid == Life[playerid])
  {
     SetPlayerHealth(playerid,100);
     Life[playerid] = -1;
  }
  return 1;
}
Reply
#8

Quote:
Originally Posted by Killa_
Quote:
Originally Posted by O_x
Quote:
Originally Posted by maij
You probably call the creation of the timer at the wrong time. Also, what you want is a timer that exists anytime.

Therefore, the interval should be at least 1 second. You will kill your server if you put it any lower in my opinion that is.
You should create this timer when the player connects and destroy it when they disconnect.

HOWEVER:
using this method will cause bugs. The pickup will not be picked up the ms after it got spawned, which causes the creation of another health icon. If your health is lower than 25, it will keep creating a new pickup. This means when you die, where a minimal 2 second interval is in between, it will already spawn 2 pickups.

I recommend you to do it otherwise, or better yet not doing it this way at all.
If so, use setplayerhealth or whatsoever instead of a pickup.
Oh ok than,just thought it would be a pretty cool idea,
well thanks i guess i need to remove it :/
thanks for the help dude.
Try sumin like this

pawn Код:
new Life[MAX_PLAYERS] = -1;

public OnPlayerUpdate(playerid)
{
  new Float:Health; GetPlayerHealth(playerid,Health);
  if(Health <= 25.0 && Life[playerid] == -1)
  {
    SendClientMessage(playerid,COLOR_PURPLE,"Wow looks like you're injured badly!take the heart pickup to heal yourself.");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Life[playerid] = AddStaticPickup(1240,2,X+2.00,Y+2.34,Z,0);
  }
  return 1;
}

public OnPlayerPickUpPickup(playerid)
{
  if(pickupid == Life[playerid])
  {
    SetPlayerHealth(playerid,100);
    Life[playerid] = -1;
  }
  return 1;
}
Thanks,i'll test it later (:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)