SA-MP Forums Archive
[HELP]Robbery system : Commands and checkpoints - 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: [HELP]Robbery system : Commands and checkpoints (/showthread.php?tid=550006)



[HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

hey guys.

Ok here is my problem. I have made a robbery system for which the player must stand in the dynamic checkpoint and then he must enter a command to start robbing. I want to change it that the player doesnt have to use a command and that he goes into the checkpoint and the robbery must then start automatically. I will post all the coding i have done with this system. I will only post the coding of one shop.

Right down here i forwarded.

Код:
forward robBarber(playerid);
Right down here i declared the timers and checkpoints and such more.

Код:
new
    robTimerB[ MAX_PLAYERS ],
    cp_Barber,
    bool: pRobbingB[ MAX_PLAYERS ],	//Los Santos, Idlewood, Barber Shop
    bool: BarberRobbed;
Then placed the coordinates of where the checkpoint must be with a 3D Text Label.

Код:
	Create3DTextLabel("/robbarber", COLOR_YELLOW, 413.265 , -17.957 , 1001.804, 40.0, 0, 0);   		
	cp_Barber = CreateDynamicCP(413.265 , -17.957 , 1001.804, 2.0, .interiorid = 2);
Right down i here i made my public which does few of the things.

Код:
public robBarber(playerid)			//Barber Shop LS
{
    new
        randMoney = random(8000) + 1000;
   
    new
        szStr[ 128],
        usrName[24],
		string[128];

    GetPlayerName( playerid, usrName, 24 );
    format( szStr, 128, "%s has robbed $%d from the Barber Shop", usrName, randMoney );
    SendClientMessageToAll( COLOR_ORANGERED, szStr );

    format( szStr, 128, "{CC6600}[ROBBERY INFO] {FFFFFF}Robbery successful! You have earned {CC6600}$%d {FFFFFF}, Score Earned : {CC6600}1 ", randMoney );
    SendClientMessage( playerid, COLOR_WHITE, szStr );

    pRobbingB[ playerid ] = false;
    SetTimer( "barberDelay", 90000, false );

	pInfo[playerid][Cash] += randMoney;

    pInfo[playerid][Score] += 1;
	pInfo[playerid][Robs] += 1;
	format(string, 128, "{CC6600}[ROBBERY INFO] {FFFFFF}Your robbing skill has increased to {CC6600}%d", pInfo[playerid][Robs]);
	SendClientMessage(playerid, COLOR_WHITE, string);
	
	new color = GetPlayerColor(playerid);
	if(color == COLOR_WHITE)
		return SetPlayerColor(playerid, COLOR_ORANGE);
	else if(color == COLOR_ORANGE)
		return SetPlayerColor(playerid, COLOR_RED);
	return 1;
}
And i made a few things under "OnPlayerEnterDynamicCP" with the checkpoint. Right down here

Код:
if (pRobbingB[playerid])
	{
			if (checkpointid == cp_Barber)
			{
				pRobbingB[playerid] = false;
				KillTimer(robTimerB[playerid]);
				BarberRobbed = false;
				GameTextForPlayer(playerid, "~r~You have failed the robbery!", 1000, 3);
			}
	}
Down here i made a delay public which works with the timer.

Код:
forward barberDelay( );
public barberDelay( )
{
    BarberRobbed = false;
    return true;
Now finally down here is the command the player must first type to rob the barber shop.

Код:
CMD:robbarber(playerid, params[])		//Barber Shop, Idlewood
{
    if (pRobbingB[ playerid ])
        return SendClientMessage( playerid, COLOR_RED, "ERROR:{FFFFFF} You are already robbing Idlewood Barber Shop" );

    if (!IsPlayerInRangeOfPoint( playerid, 3.0, 413.265 , -17.957 , 1001.804 ) )
		return SendClientMessage( playerid, COLOR_RED, "ERROR:{FFFFFF} You must be in the checkpoint at Idlewood Barber Shop to use this command!" );

    if (BarberRobbed )
        return SendClientMessage( playerid, COLOR_WHITE, "{CC6600}Idlewood Barber Shop {FFFFFF}has been {CC6600}robbed recently." );

    robTimerB[ playerid ] = SetTimerEx( "robBarber", 30000, false, "i", playerid );
    SendClientMessage( playerid, COLOR_YELLOW, "[ROBBERY INFO] You have started a robbery, it will last 30 seconds. Do not leave the checkpoint!" );

    pRobbingB[ playerid ] = true;
    BarberRobbed = true;

 //     format( szStr, 128, "[ROBBERY] %s has began a robbery at Idlewood Pizza!", GetName(playerid) );
 //     SendClientMessageToAll( COLOR_ORANGERED, szStr );

    GameTextForPlayer( playerid, "~g~Robbery in process~n~~r~Do not leave the checkpoint!", 32000, 3 );
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +2);
    return 1;
}
Any help will be appreciated guys. Just show me how the command's code can go into the OnPlayerEnterDynamicCP. So that the player doesnt have to enter a command to rob the store.


Re: [HELP]Robbery system : Commands and checkpoints - Divergent - 10.12.2014

if(checkpointid == cp_Barber)
{
robTimerB[ playerid ] = SetTimerEx( "robBarber", 30000, false, "i", playerid );
SendClientMessage( playerid, COLOR_YELLOW, "[ROBBERY INFO] You have started a robbery, it will last 30 seconds. Do not leave the checkpoint!" );

pRobbingB[ playerid ] = true;
BarberRobbed = true;

// format( szStr, 128, "[ROBBERY] %s has began a robbery at Idlewood Pizza!", GetName(playerid) );
// SendClientMessageToAll( COLOR_ORANGERED, szStr );

GameTextForPlayer( playerid, "~g~Robbery in process~n~~r~Do not leave the checkpoint!", 32000, 3 );
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +2);
return 1;
}

That's all you have to do. Then add the opposite to OnPlayerLeaveDynamicCP. Also it would be more efficient to create a custom function like RobBarber(playerid) and place the command code under there.


Re: [HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

Wait Wait, i dont understand. can i just drag the Commands data over to the OnPlayerEnterDynamicCP


Re: [HELP]Robbery system : Commands and checkpoints - Divergent - 10.12.2014

Quote:
Originally Posted by MrViolence101
Посмотреть сообщение
Wait Wait, i dont understand. can i just drag the Commands data over to the OnPlayerEnterDynamicCP
Yeah you can, it's the same code but just a different way of calling it.


Re: [HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

If i put that coding you gave me now into my OnPlayerEnterDynamicCP. will it work?


Re: [HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

Can you make a coding like
Код:
 Example
and show me precisely what i must insert into the OnPlayerEnterDynamicCP. I wil Rep++


Re: [HELP]Robbery system : Commands and checkpoints - Divergent - 10.12.2014

Yeah it should, if not post here again and I'll help you out.


Re: [HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

Quote:
Originally Posted by Divergent
Посмотреть сообщение
Yeah it should, if not post here again and I'll help you out.
Check above your reply, i replied


Re: [HELP]Robbery system : Commands and checkpoints - Divergent - 10.12.2014

Код:
	if(pRobbingB[playerid])
	{
		if(checkpointid == cp_Barber)
		{
			robTimerB[playerid] = SetTimerEx( "robBarber", 30000, false, "i", playerid);
			SendClientMessage(playerid, COLOR_YELLOW, "[ROBBERY INFO] You have started a robbery, it will last 30 seconds. Do not leave the checkpoint!");

			pRobbingB[playerid] = true;
			BarberRobbed = true;

			// format( szStr, 128, "[ROBBERY] %s has began a robbery at Idlewood Pizza!", GetName(playerid) );
			// SendClientMessageToAll( COLOR_ORANGERED, szStr );

			GameTextForPlayer(playerid, "~g~Robbery in process~n~~r~Do not leave the checkpoint!", 32000, 3);
			SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +2);
			return 1;
		}
	}



Re: [HELP]Robbery system : Commands and checkpoints - MrViolence101 - 10.12.2014

Quote:
Originally Posted by Divergent
Посмотреть сообщение
Код:
	if(pRobbingB[playerid])
	{
		if(checkpointid == cp_Barber)
		{
			robTimerB[playerid] = SetTimerEx( "robBarber", 30000, false, "i", playerid);
			SendClientMessage(playerid, COLOR_YELLOW, "[ROBBERY INFO] You have started a robbery, it will last 30 seconds. Do not leave the checkpoint!");

			pRobbingB[playerid] = true;
			BarberRobbed = true;

			// format( szStr, 128, "[ROBBERY] %s has began a robbery at Idlewood Pizza!", GetName(playerid) );
			// SendClientMessageToAll( COLOR_ORANGERED, szStr );

			GameTextForPlayer(playerid, "~g~Robbery in process~n~~r~Do not leave the checkpoint!", 32000, 3);
			SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +2);
			return 1;
		}
	}
When i walk into the checkpoint nothing responds