[Tutorial] Making a building enterable
#1

This tutorial is for those who are new to scripting, to show them multiple ways to enter a building.
__________________________________________________ ______________________________________________
The first method that we will be using is a simple /enter command. This command will be done in zcmd, since it is a lot quicker than OnPlayerCommandText, so go to the top of your script, and add this:
PHP код:
#include <zcmd> 
Now, we can start on the command.
First of all, we will need to put this:
PHP код:
CMD:enter(playerid,params[]) 
This is to make it as an /enter command, but, if you want to, you can change the text to whatever you want. Now, we will move on to the next step.
We will check if a player is near a point. For this tutorial, i will use LSPD, but you can choose any location. Now, lets do a check on if the player is near the point:
PHP код:
if(!IsPlayerInRangeOfPoint(playerid,2,1554.682495,-1675.988403,16.195312)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not near LSPD"); 
This will check if the player is near the point: 1554.682495,-1675.988403,16.195312 with a radius of 2, and if they arent, they get sent a message saying that they are not near lspd.
Now, we will use SetPlayerPos to put the player inside the building.
PHP код:
SetPlayerPos(playerid246.391220,62.97142,1003.640625); // Set the position of the player as 246.391220,62.97142,1003.640625 
This code will just put the player inside LSPD. We will need to set the player's interior too, otherwise, they would just be falling.
PHP код:
SetPlayerInterior(playerid,6); // Set the player's interior to 6 
Now, add return 1; at the end of your code, otherwise, you will get a compiling error that says that the command should return a value, and if you put return 0; it will come up with the 'unknown command' thing.
__________________________________________________ ______________________________________________

There is another way to do this too, by using a pickup. You can now make a new variable for the pickup.
PHP код:
new pickup
Under ongamemodeinit (or onfilterscriptinit), you will create the pickup. Example: if i was doing one for lspd, i would do the following:
PHP код:
pickup CreatePickup(1239,1,246.391220,62.97142,1003.640625); // create a pickup with model: 1239, at 246.391220,62.97142,1003.640625, and will use the type 1, which will make it always visible. 
So far, the pickup will have no effect on the player whatsoever. But, you can add an effect by using the following callback:
PHP код:
public OnPlayerPickUpPickup(playeridpickupid// When a player picks up a pickup 
Now, we will use a similar thing to the /enter command. But, we will add a check for the pickup, by adding the following code:
PHP код:
if(pickupid == pickup// if the player has picked up the pickup that we defined earlier 
Now, we will set the player's position inside LSPD:
PHP код:
SetPlayerPos(playerid246.391220,62.97142,1003.640625); // Set the position of the player as 246.391220,62.97142,1003.640625 
And then, we will set the interior of the player again:
PHP код:
SetPlayerInterior(playerid,6); // Set the player's interior as 6 
Thank you for reading this tutorial. Want to see another tutorial? PM me with one, and i will be willing to post it. Constructive criticism is always welcome on this topic, but don't rage e.g. 'OMG U SUX DOESNT WORK !!1', just tell me the problem and i will help you as soon as possible.
Reply
#2

Is this possible with the use of DCMD instead of ZCMD?
Reply
#3

Nice tutorial thanks.
Reply
#4

Quote:
Originally Posted by michaeli
Посмотреть сообщение
Is this possible with the use of DCMD instead of ZCMD?
all things are possible with zcmd , dcmd but you need to do some changes in starting of the code . like if you are making a /help cmd then you will need to make it in zcmd like that:
pawn Код:
Zcmd Code:
CMD:help(playerid, params)
{
    your code..
     return 1;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])

dcmd(help,4,cmdtext);

dcmd_help(playerid, params)
{
    #pragma unused params (if you are not using params)
   your code..
   return 1;
}
Reply
#5

Thanks for the details...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)