OnPlayerTargetActor robberies
#1

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);
    }
}
Reply
#2

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;

Reply
#3

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
Reply
#4

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
Reply
#5

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

    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)