PAWN tutorial 3

From SA-MP Wiki

Jump to: navigation, search

Tutorial 3
How to make houses for players

First make a filterscript. It doesnt matter what you call it, but I called it houses.

Now look for "public OnPlayerCommandText(playerid, cmdtext[])".
Add this to the script with the coords you want.

Make a command simular to this one:

//begin
if (strcmp(cmdtext, "/enter", true)==0)
{
	new i, Float:X, Float:Y, Float:Z; //this is where your coords will get stored
	for (i = 0; i < MAX_PLAYERS; i++) //this is a loop
	{
		GetPlayerPos(i, X, Y, Z); //stores your pos
		if(X >= minimum X && X <= Maximum X && Y >= Minimum Y && Y <= Maximum Y) //coords for entering house
		{
			SetPlayerInterior(playerid, interiorID); //interiorID is the Interior the house is in
			SetPlayerPos(playerid, X, Y, Z); // X, Y, Z are the coords where the house is located
			GameTextForPlayer(playerid, "Welcome to Owners house",3000,5); //Change Owners to name of player the house is of
		}
	}
	return 1;
}
//end

That was for entering the house.
Now for leaving it:

//begin
if(strcmp(cmdtext, "/leave", true)==0)
{
	new i, Float:X, Float:Y, Float:Z; //again for storing your coords
	for (i = 0; i < MAX_PLAYERS; i++)//again for a loop
	{
		GetPlayerPos(i, X, Y, Z); //stores your pos
		if(X >= minimum X && X <= Maximum X && Y >= Minimum Y && Y <= Maximum Y) //Inside the house coords for leaving
		{
			SetPlayerInterior(playerid, 0); //interior of outside
			SetPlayerPos(playerid, X, Y, Z); //pos of where you entered
		}
	}
	return 1;
}
//end

Ok that was for leaving the house.

You could also make a /roof command.
It would look almost the same but with other coords and stuff.
Try to figure that out yourself.
Happy Scripting!

Personal tools
Navigation
Toolbox