SA-MP Forums Archive
OnPlayerTargetActor robberies - 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: OnPlayerTargetActor robberies (/showthread.php?tid=648272)



OnPlayerTargetActor robberies - Ducati - 19.01.2018

Ok so i'm trying to make actors to put inside ammunations/247s which allow players to rob the store by aiming at the actor. My problem is that once I aim at the actor and begin the robbery, I can't figure out how to make the robbery cancel itself if I stop aiming.

Anybody have any ideas how to fix this?

Код:
public OnPlayerTargetActor(playerid, newtarget, oldtarget)
{
    if (newtarget == prostitutebot)
    {
        ApplyActorAnimation(newtarget, "PED", "handsup", 4.1, 0, 0, 0, 1, 0);
        if(GetPVarInt(playerid,"RobTime")>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"Please wait 5 minutes before another robbery.");
	if(gTeam[playerid] == TEAM_COP) return SendClientMessage(playerid, red, "Cops cannot rob stores");
        pRobTimerID[playerid] = SetTimerEx("pRobTimer", 1000, true, "i", playerid);
        pRobCount[playerid] = 31;
   	SetPVarInt(playerid,"RobTime",GetTickCount()+300000);
    }
    
    if (oldtarget != INVALID_ACTOR_ID)
    {
        ClearActorAnimations(oldtarget);
    }
}



Re: OnPlayerTargetActor robberies - RogueDrifter - 19.01.2018

Off topic: what the fuck lmao i didn't even know that this callback exists i always used getplayertargetactor under onplayerupdate or a fixed timer lol!


On topic: you can set a timer for 3-5 seconds and check if isplayeraiming = rob else = return 0; if you want the player aiming function here it is:
PHP код:
stock IsPAiming(playerid)
{
    new 
playeranim GetPlayerAnimationIndex(playerid);
    if (((
playeranim >= 1160) && (playeranim <= 1163)) || (playeranim == 1167) || (playeranim == 1365) ||
    (
playeranim == 1643) || (playeranim == 1453) || (playeranim == 220)) return 1;
     return 
0;




Re: OnPlayerTargetActor robberies - Ducati - 19.01.2018

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Off topic: what the fuck lmao i didn't even know that this callback exists i always used getplayertargetactor under onplayerupdate or a fixed timer lol!


On topic: you can set a timer for 3-5 seconds and check if isplayeraiming = rob else = return 0; if you want the player aiming function here it is:
PHP код:
stock IsPAiming(playerid)
{
    new 
playeranim GetPlayerAnimationIndex(playerid);
    if (((
playeranim >= 1160) && (playeranim <= 1163)) || (playeranim == 1167) || (playeranim == 1365) ||
    (
playeranim == 1643) || (playeranim == 1453) || (playeranim == 220)) return 1;
     return 
0;

Could you give me an example code for a timer to do that? I am terrible at making/implementing timers, it took me hours to get the pRobTimer to work


Re: OnPlayerTargetActor robberies - Misiur - 19.01.2018

From quick glance at the include, it seems when you stop aiming at the actor the callback gets called with newtarget = INVALID_ACTOR_ID. Use that


Re: OnPlayerTargetActor robberies - Ducati - 19.01.2018

Adding this seems to have solved the problem, I should've read through the include again before asking here
thank you both for your help!

Код:
    if (oldtarget != INVALID_ACTOR_ID)
    {
        ClearActorAnimations(oldtarget);
        if(IsRobbing[playerid] == 1)
      	{
	SendClientMessage(playerid,0xFF0000FF,"You lowered your gun and abandoned the robbery.");
	GameTextForPlayer(playerid, "~r~Robbery Failed", 3000, 5);
	IsRobbing[playerid] =0;
	pRobCount[playerid] = 0;
	KillTimer(pRobTimerID[playerid]);
	robmoney[playerid] = 1;
	    }

    }