SA-MP Forums Archive
Aim at NPC to start Rob! - 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: Aim at NPC to start Rob! (/showthread.php?tid=633253)



Aim at NPC to start Rob! - ChandraLouis - 28.04.2017

Can you show me the code to rob with time when i aimed at the NPC?


Re: Aim at NPC to start Rob! - raydx - 28.04.2017

For actors: GetPlayerTargetActor(playerid)
For NPC: GetPlayerTargetPlayer(playerid)

Use it in OnPlayerUpdate or timer.


Re: Aim at NPC to start Rob! - ChandraLouis - 28.04.2017

I created one like this:
pawn Code:
forward RobCluckin(playerid);

public RobCluckin(playerid)
{
    new rand = random(5000)+0;
    GivePlayerMoney(playerid,rand);
    new pname[MAX_PLAYER_NAME], string[80 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, sizeof(string), ""COLOR_RED"[ROBBERY] %s has robbed Cluckin Bell (Downtown) and received %i.", pname, rand);
    SendClientMessageToAll(-1, string);
    return 1;
}

public OnGameModeInit()
{
    ConnectNPC("CluckinBOT","Cluckin");
    CreatePickup(1318, 1, -1816.5437,618.0901,35.1719, 0);
    CreatePickup(1318, 1, 364.8150,-11.6074,1001.8516, 9);
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, -1816.5437,618.0901,35.1719))
        {
            SetPlayerPos(playerid, 364.8150,-11.6074,1001.8516);
            SetPlayerInterior(playerid, 9);
        }
        else if(IsPlayerInRangeOfPoint(playerid, 3.0, 364.8150,-11.6074,1001.8516))
        {
            SetPlayerPos(playerid, -1816.5437,618.0901,35.1719);
            SetPlayerInterior(playerid, 0);
        }
    }
    if(PRESSED(KEY_HANDBRAKE))
    {
        new wid = GetPlayerWeapon(playerid);
        if(wid > 10)
        {
            new NPCID = GetPlayerIDFromName("CluckinBOT");
            if(IsPlayerFacingPlayer(playerid,NPCID,10) == 1)
            {
                ApplyAnimation(NPCID,"ped","handsup",3.0,0,0,0,1,0);
                SendClientMessage(playerid, -1, ""COLOR_YELLOW"[WANTED LEVEL] {FFFFFF}Your wanted level is increased by four. (Robbing Cluckin Bell)");
                SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid)+4);
                SetTimerEx("RobCluckin", 25000, false, "i", playerid);
                SetTimerEx("After1", 50000, false, "i", playerid);
            }
        }
    }
    return 1;
}
How can i get the timer showing like this in a gamemodetext?
"Robbery Time: timer
Please wait until the robbery is done."


Re: Aim at NPC to start Rob! - iLearner - 28.04.2017

Use actors for such purposes instead of NPCs, and there are some includes that provide you with callbacks such as "OnPlayerAimActor(playerid, actorid)".


Re: Aim at NPC to start Rob! - ChandraLouis - 28.04.2017

Quote:
Originally Posted by iLearner
View Post
Use actors for such purposes instead of NPCs, and there are some includes that provide you with callbacks such as "OnPlayerAimActor(playerid, actorid)".
And, which include is that?


Re: Aim at NPC to start Rob! - Kane - 28.04.2017

Quote:
Originally Posted by ChandraLouis
View Post
And, which include is that?
Extended Actor Functions by Emmet.

https://sampforum.blast.hk/showthread.php?tid=573504