Health Regeneration [HELP]
#1

I want to try this new thing on my server. Easy for Medics to use. Well this is what I want. Anyone who helps get's +Rep.

Alright the vehicle ID is 416 a.k.a Ambulance. Now how do I make this regeneration process that when any player enter's the Ambulance, their health is regenerated +10 health per second either Driver or Passenger? And I don't want the ambulance to be abused so how can I make it restricted? I had an idea. With a Medic's skin. How do I make the ambulance only have access to anyone who has the medic skin, ID 274. I would really appreciate it, if someone could help me.
Reply
#2

here u go!
pawn Код:
#include <a_samp>
forward heal(playerid);
forward heal1(playerid);
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetVehicleModel(GetPlayerVehicleID(playerid));
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
    if (vehicleid == 416 && GetPlayerSkin(playerid) == 274)
    {
    SetTimerEx("heal", 1000, false, "d", 1337);
    }
    }
    return 1;
}
public heal(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    SetPlayerHealth(playerid,health+3);
    SetTimerEx("heal1", 1000, false, "d", 1337);
}
public heal1(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    SetPlayerHealth(playerid,health+3);
    SetTimerEx("heal", 1000, false, "d", 1337);

}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    new vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
    if (vehicle == 416)
    {
    KillTimer(heal(playerid));
    }
    return 1;
}
Edited Sorry Was To Sleepy ..
Reply
#3

that script wouldn't work as desired, that's not how you use timers.
I'd suggest under OPU checking if 1 second has gone by and they are in an ambulance then changing their health there
Reply
#4

Quote:
Originally Posted by XtremeR
Посмотреть сообщение
here u go!
pawn Код:
#include <a_samp>
forward heal(playerid);
forward heal1(playerid);
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetVehicleModel(GetPlayerVehicleID(playerid));
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
    if (vehicleid == 416 && GetPlayerSkin(playerid) == 274)
    {
    SetTimer("heal(playerid)", 1000, false);
    }
    }
    return 1;
}
public heal(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    SetPlayerHealth(playerid,health+3);
    SetTimer("heal1(playerid)", 1000, false);
}
public heal1(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    SetPlayerHealth(playerid,health+3);
    SetTimer("heal(playerid)", 1000, false);
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    new vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
    if (vehicle == 416)
    {
    KillTimer(heal(playerid));
    }
    return 1;
}
You have to use SetTimerEx bro
Reply
#5

Alright thanks guys. I'm kind of out right now. When I'm back home, I'll +Rep you guys.
Reply
#6

EDIT: The whole thing is not working. How do I make it work. I get a lot of errors.
Reply
#7

pawn Код:
KillTimer(heal(playerid));
Where did you saved this timer to variable? Where's the variable? If you are too sleepy then stop writing stupid things.

Not tested. Check:
pawn Код:
#include    <a_samp>

new Timer[MAX_PLAYERS];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if((newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 416 && GetPlayerSkin(playerid) == 274)
        {
            HealPlayer(playerid);
        }
    }
   
    if((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) && newstate == PLAYER_STATE_ONFOOT)
    {
        KillTimer(Timer[playerid]);
    }
    return true;
}

forward HealPlayer(playerid);
public  HealPlayer(playerid)
{
    new Float:Health;
    GetPlayerHealth(playerid, Health);
    if(Health < 100.0)
    {
        SetPlayerHealth(playerid, Health+10.0);
        Timer[playerid] = SetTimerEx("HealPlayer", 1000, true, "d", playerid);
    }

    else
    {
        KillTimer(Timer[playerid]);
        SetPlayerHealth(playerid, 100.0);
        GameTextForPlayer(playerid, "You have been healed!", 3000, 3);
    }
    return true;
}
Reply
#8

Tested and works In-Game. Heals any player with the medic skin who enters an ambulance.
pawn Код:
new g_healTimer[MAX_PLAYERS];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT && GetVehicleModel(GetPlayerVehicleID(playerid)) == 416 && GetPlayerSkin(playerid) == 274) {
        g_healTimer[playerid] = SetTimerEx("passengerHeal", 1000, 1, "d", playerid);
    }
}

forward passengerHeal(playerid);
public passengerHeal(playerid)
{
    new Float:health;
   
    GetPlayerHealth(playerid, health);
    SetPlayerHealth(playerid, health + 10.0);
    GetPlayerHealth(playerid, health);
   
    if(health > 100.0) {
        SetPlayerHealth(playerid, 100.0);
        KillTimer(g_healTimer[playerid]);
    }
    return 1;
}
Reply
#9

Guys, by the code, it says that it will heal the medic. The medic is to drive the vehicle. The vehicle is Restricted. Only Medics can drive it. I mean even civilians which are hurt, enter the ambulance, their health is regenerated. Not the medic that is regenerated.
Reply
#10

Quote:
Originally Posted by RTR12
Посмотреть сообщение
Guys, by the code, it says that it will heal the medic. The medic is to drive the vehicle. The vehicle is Restricted. Only Medics can drive it. I mean even civilians which are hurt, enter the ambulance, their health is regenerated. Not the medic that is regenerated.
Then remove the
pawn Код:
&& GetPlayerSkin(playerid) == 274
.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)