Vulnerable Actor
#1

Tittle says it all i guess.
How i could make an actor accepting damage when i shoot him?
Using Emmet's Extended Actor's Function
Reply
#2

Not really sure if that include changes anything but SA-MP offers the following functions:

https://sampwiki.blast.hk/wiki/IsActorInvulnerable
https://sampwiki.blast.hk/wiki/SetActorInvulnerable

Setting this to 0 will make the actor able to take damage and likewise setting to 1 will not allow it to take damage. You can detect actor damage through the OnPlayerGiveDamageActor callback;

https://sampwiki.blast.hk/wiki/OnPlayerGiveDamageActor
I wrote a brief tutorial on actors here as well.
Reply
#3

Something to get you started on (I pretty much thought you could do something as simple as this since you've been here since 2009 and you're making a CnR server, but meh. On LVCNR's ******** page you said that you've talked to a lot of experienced scripters and they said it was interesting or something like that, kinda doubting that now.):
pawn Код:
// ** INCLUDES

#include <a_samp>

// ** VARIABLES

// *** GLOBAL VARIABLES

// **** GENERAL

new gActor,
bool:gActorDead = false;

// ** MAIN

main()
{
    print("Loaded \"killable_actor.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    gActor = CreateActor(0, 136.6050, -74.2258, 1.4297, 0.0);
    SetActorInvulnerable(gActor, false);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    GivePlayerWeapon(playerid, 26, 500);
    return 1;
}

public OnPlayerGiveDamageActor(playerid, damaged_actorid, Float:amount, weaponid, bodypart)
{
    new Float:health;
    GetActorHealth(gActor, health);

    if(health >= 0.0)
    {
        SetActorHealth(gActor, health - amount);
    }

    if(!gActorDead && (health - amount) <= 0.0)
    {
        gActorDead = true;

        OnActorDeath(damaged_actorid, playerid, weaponid);
    }
    return 1;
}

forward OnActorDeath(actorid, killerid, reason);
public OnActorDeath(actorid, killerid, reason)
{
    if(!IsValidActor(actorid)) return 0;

    if(IsValidWeaponID(reason))
    {
        new weapon_name[20];
        if(reason == 0)
        {
            strcat(weapon_name, "Fists");
        }
        else
        {
            GetWeaponName(reason, weapon_name, sizeof(weapon_name));
        }

        new string[144];
        format(string, sizeof(string), "%s (%d) killed the actor #%d - %s.", PlayerName(killerid), killerid, actorid, weapon_name);
        SendClientMessageToAll(0x9F3535FF, string);
    }
    return 1;
}

// ** FUNCTIONS

forward bool:IsValidWeaponID(weaponid);
public bool:IsValidWeaponID(weaponid)
{
    if(weaponid < 0 || weaponid > 46) return false;

    switch(weaponid)
    {
        case 0, 19, 20, 21, 48: return false;
        default: return true;
    }
    return false;
}

stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    return name;
}
Reply
#4

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Something to get you started on (I pretty much thought you could do something as simple as this since you've been here since 2009 and you're making a CnR server, but meh. On LVCNR's ******** page you said that you've talked to a lot of experienced scripters and they said it was interesting or something like that, kinda doubting that now.):
pawn Код:
// ** INCLUDES

#include <a_samp>

// ** VARIABLES

// *** GLOBAL VARIABLES

// **** GENERAL

new gActor,
bool:gActorDead = false;

// ** MAIN

main()
{
    print("Loaded \"killable_actor.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    gActor = CreateActor(0, 136.6050, -74.2258, 1.4297, 0.0);
    SetActorInvulnerable(gActor, false);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    GivePlayerWeapon(playerid, 26, 500);
    return 1;
}

public OnPlayerGiveDamageActor(playerid, damaged_actorid, Float:amount, weaponid, bodypart)
{
    new Float:health;
    GetActorHealth(gActor, health);

    if(health >= 0.0)
    {
        SetActorHealth(gActor, health - amount);
    }

    if(!gActorDead && (health - amount) <= 0.0)
    {
        gActorDead = true;

        OnActorDeath(damaged_actorid, playerid, weaponid);
    }
    return 1;
}

forward OnActorDeath(actorid, killerid, reason);
public OnActorDeath(actorid, killerid, reason)
{
    if(!IsValidActor(actorid)) return 0;

    if(IsValidWeaponID(reason))
    {
        new weapon_name[20];
        if(reason == 0)
        {
            strcat(weapon_name, "Fists");
        }
        else
        {
            GetWeaponName(reason, weapon_name, sizeof(weapon_name));
        }

        new string[144];
        format(string, sizeof(string), "%s (%d) killed the actor #%d - %s.", PlayerName(killerid), killerid, actorid, weapon_name);
        SendClientMessageToAll(0x9F3535FF, string);
    }
    return 1;
}

// ** FUNCTIONS

forward bool:IsValidWeaponID(weaponid);
public bool:IsValidWeaponID(weaponid)
{
    if(weaponid < 0 || weaponid > 46) return false;

    switch(weaponid)
    {
        case 0, 19, 20, 21, 48: return false;
        default: return true;
    }
    return false;
}

stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    return name;
}
I had left SA-MP for 9 months so i wasn't really get used to actor system and i never used functionally an NPC so it was tough to me to start using Actors.
However, i already made that by myself using a custom callback thanks though since i forgot to reply at the post and i just noticed about the replies. It was really as simple as i could imagine. Thanks for the try to help me though.
P.S: I don't know what are you talking about on LV-CNR ******** page? I never was there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)