SA-MP Forums Archive
quick question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: quick question (/showthread.php?tid=596497)



quick question - iNuBe - 18.12.2015

hey how to make an actor killable
and yes i read the SetActorInvulnerable and didn't undrestand how to exactly use the second thing pleas help
(give an example if u can)


Re: quick question - SickAttack - 18.12.2015

Everything you need to know is here: https://sampwiki.blast.hk/wiki/Category:Actor


Re: quick question - iNuBe - 18.12.2015

i told yo i do not undrestand the second parameter make some effor damn it


Re: quick question - SickAttack - 18.12.2015

Quote:
Originally Posted by iNuBe
Посмотреть сообщение
i told yo i do not undrestand the second parameter make some effor damn it
If only people would read...



"u make some effor damn it"

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;
}



Re: quick question - iNuBe - 18.12.2015

but sir i'm but a simple scripter and it takes a lot of time to find this out on y own why not use my professional scripting brothers who know better


Re: quick question - SickAttack - 18.12.2015

Quote:
Originally Posted by iNuBe
Посмотреть сообщение
but sir i'm but a simple scripter and it takes a lot of time to find this out on y own why not use my professional scripting brothers who know better
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;
}