SA-MP Forums Archive
[Tutorial] Simple jobs - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Simple jobs (/showthread.php?tid=369337)



Simple jobs - Squirrel - 16.08.2012

Introductions
Hello, this is simple tutorial on how to make jobs. These are simple jobs, that require less than 10 minutes to make each one, and they are really useful on all servers. These jobs that we are going to make, they do not have any sort of a cooldown, and things as such. Everyone can do them on your server and they do not have to type for example /joinjob or whatever.


Scripting and explanations
First thing we need to do is to make new variable that will be called later on when we make the job command.
So thing we need to add is:
Code:
 new SmugglerJob[256];
Put this at the very top of your script. Make sure that this is added because this is most important thing that you will need for this tutorial. Now we actually made the job by adding this but we need something that we will use this with.

Also we need one more this and that is to add vehicles that will be used for this job.
Add this bellow OnGameModeInit
Code:
	AddStaticVehicle(482,1772.6602,-2048.9277,13.6440,270.5698,3,0); // Smugglerjob 1
	AddStaticVehicle(482,1773.2407,-2042.7849,13.6227,269.7848,3,4); // Smugglerjob 2
	AddStaticVehicle(482,1772.5969,-2037.0247,13.6003,270.9971,3,6); // Smugglerjob 3
	AddStaticVehicle(482,1772.4786,-2031.4073,13.5899,270.2319,3,1); // Smugglerjob 4



Command
First of all we need to go down at the
Code:
public OnPlayerCommandText(playerid, cmdtext[])
Second thing is that we need some usage added to the actual Job. I will do it by creating simple strcmp command.
Code:
if (strcmp("/cratesmuggle", cmdtext, true, 0) == 0)
This is simple command that the script will execute for our job.

Now we have job and command, but even with that this command will be empty since there is no usage added to it. So let's start adding lines that this command will use. I am also making this job allowed only if player is in Vehicle model ID:482. We can add this by adding the next line
Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
This is checking if player is in vehicle model 482.

Now since we added new thing that is checking is player inside a vehicle that he needs to be, lets added what will happen if he is.
First thing we need to add is to assign player to the job.
Code:
SmugglerJob[playerid] = 1;
This is assigning player to the job that he is doing. If we set it to 0 it will mean that player is not doing the job.

Now let's add something that will tell player where to go in order to pick up his materials/crates.
Code:
SetPlayerCheckpoint(playerid,1751.0360,-2058.4458,13.5892,10);
This is going to set players checkpoint to the destination where we added. In the brackets you can see the coordinates. This is adding where player should go in order to pick his crates.

Now also we can add a message that will be sent to player when he does the command. Let's add simple SendClientMessage for this.
Code:
SendClientMessage(playerid, 0xFFFF00AA, "* Get the goods from the garage and deliver 'em lazy boy!");
This will send the player Yellow colored message.

Bellow this add
Code:
return 1;
This will prevent player from getting "Unknown message!"

Also we need one more this, after we close the script we need to add
Code:
SendClientMessage(playerid, COLOR_RED,"You have to be in a smuggling vehicle to do this!");
Why and what is this?
Well this will tell player that they need to be in a smuggling vehicle in order to do that business

FULL COMMAND:
Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
	//smuggler
	if (strcmp("/cratesmuggle", cmdtext, true, 10) == 0)
	{
	    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
	    {
	        SmugglerJob[playerid] = 1;
	        SetPlayerCheckpoint(playerid,1751.0360,-2058.4458,13.5892,10);
	        SendClientMessage(playerid, 0xFFFF00AA, "* Get the goods from the garage and deliver 'em lazy boy!");
	        return 1;
		}
		SendClientMessage(playerid, 0xFFFF00AA,"You have to be in a smuggling vehicle to do this!");
	}



Callback
Now let's add something that will call our command If player is at the checkpoint we need.
Now for this we are going to use
Code:
public OnPlayerEnterCheckpoint(playerid)
Why?
Well for the command we used SetPlayerCheckpoint and this is it's callback.

Let's start off and add things that will happen when player arrives at his checkpoint!
First thing we need to check player vehicle to see if he/she is still in the vehicle that is for this job.
So let's add the line that we previously added onto the OnPlayerCommandText.
Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
{
Now we checked if player in is vehicle model 482, and if he is let's add few lines what will happen.

Now we need to set "switchers" for those checkpoints.
Code:
if(SmugglerJob[playerid] == 1){
			SmugglerJob[playerid] = 2;
This basically means if player is on smuggler point 1, he will be redirected to second checkpoint.

Now let's add that second checkpoint. This will show player where to load up his crates.
Code:
SetPlayerCheckpoint(playerid,1751.0360,-2058.4458,13.5892,10);
And also let's add message to the player that will say something.
Code:
SendClientMessage(playerid, 0xFFFF00AA, "*Crazy ED: Move your lazzy ass to bayside and deliver those crates!");
And of course again
Code:
return 1;
As we have setted this, this will add another checkpoint to a player when he arrives at the first stop. So let's add something that will another him another checkpoint. Same thing as the previous.
Code:
   		if(SmugglerJob[playerid] == 2){
			SmugglerJob[playerid] = 3;
			SetPlayerCheckpoint(playerid,-2431.2441,2312.9509,4.9844,10);
			return 1;
		}
So we are adding these lines that will add player "dropoff" checkpoint.

Let's add lines that will reconise if player is inside the last checkpoint.
Code:
if(SmugglerJob[playerid] == 3){
			SmugglerJob[playerid] = 0;
			SendClientMessage(playerid, 0xFFFF00AA, "*Crazy ED: Fine... Here you go! Come back soon when you get more crates! Now piss off!");
			SendClientMessage(playerid, 0xFFFF00AA, "Gradulations. You have completed your Smuggling route. You have received 500$");
                        GivePlayerMoney(playerid, 500);
			DisablePlayerCheckpoint(playerid);
			return 1;
As you see this time we dont have any more switchers. We are setting players job usage to 0, which will stop player job and reward him. The current reward is 500$, which you can see at the GivePlayerMoney, and also we have DisablePlayerCheckpoint that will delete players checkpoint that he is currently on, or any that he has on the map.

FULL CALLBACK:
Code:
public OnPlayerEnterCheckpoint(playerid)
{
	 if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
	 {
	    if(SmugglerJob[playerid] == 1){
			SmugglerJob[playerid] = 2;
			SetPlayerCheckpoint(playerid,1751.0360,-2058.4458,13.5892,10);
			SendClientMessage(playerid, 0xFFFF00AA, "*Crazy ED: Move your lazzy ass to bayside and deliver those crates!");
			return 1;
   		}
   		if(SmugglerJob[playerid] == 2){
			SmugglerJob[playerid] = 3;
			SetPlayerCheckpoint(playerid,-2431.2441,2312.9509,4.9844,10);
			return 1;
		}
   		if(SmugglerJob[playerid] == 3){
			SmugglerJob[playerid] = 0;
			SendClientMessage(playerid, 0xFFFF00AA, "*Crazy ED: Fine... Here you go! Come back soon when you get more crates! Now piss off!");
			SendClientMessage(playerid, 0xFFFF00AA, "Gradulations. You have completed your Smuggling route. You have received 500$");
                        GivePlayerMoney(playerid, 500);
			DisablePlayerCheckpoint(playerid);
			return 1;
	    }
	 }



Canceling players job
Okay so the thing is we need to add something that will cancel the player if he leaves his vehicle for example. Let's add some lines to the script that will do this.
For this we are going to use:
Code:
public OnPlayerExitVehicle(playerid, vehicleid)
Now, let's add some lines that will set players working to 0 if he is smuggling and he leaves the vehicle.
Code:
if(SmugglerJob[playerid] > 0)
Once again we are checking if player is working as smuggler.

Now we need to set player working to 0!
Code:
SmugglerJob[playerid] = 0;
We did it? No. We have just set player working to 0 but we also need to delete his current checkpoint.

And this will delete his checkpoint!
Code:
DisablePlayerCheckpoint(playerid);
CANCELING JOB FULL CODE:
Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
	if(SmugglerJob[playerid] > 0)
	{
	    SmugglerJob[playerid] = 0;
	    DisablePlayerCheckpoint(playerid);
	}
}
I hope you enjoyed the tutorial!


Re: Simple jobs - Kindred - 16.08.2012

Not that bad, although you could have explained it a bit better and use better methods.

Such as a Job variable, so that you can set the value to the jobid to make sure that you don't have to continuously make new variables for each job.


Re: Simple jobs - Squirrel - 16.08.2012

Quote:
Originally Posted by Kindred
View Post
Not that bad, although you could have explained it a bit better and use better methods.

Such as a Job variable, so that you can set the value to the jobid to make sure that you don't have to continuously make new variables for each job.
Thanks mate, I wrapped this up somehow, I will edit the thread and post more explanations. Thanks once more!


Re: Simple jobs - Daniel Zero - 16.08.2012

Nice tutorial ..


Re: Simple jobs - Squirrel - 16.08.2012

Quote:
Originally Posted by Daniel Zero
View Post
Nice tutorial ..
Thanks!


Re: Simple jobs - Roddan - 17.08.2012

Nice!


Re: Simple jobs - J4mmyHD - 05.05.2013

Nice Could be used on a Roleplay Server ! 9/10


Re: Simple jobs - Renas - 05.05.2013

Not bad! Well done! I will use this idea on my gm.


Re: Simple jobs - iHaze. - 06.05.2013

That's nice.


Re: Simple jobs - Chasm - 06.05.2013

Thanks for this tutorial! Helped me alot!

+Rep.