05.11.2016, 12:47
Hello guys. This is my second tutorial called quick interior doors.
In this tutorial I'm going to teach you how to script quick doors that require 1 neccessary function and 1 optional function.
Step 1)
Importing the functions.
In the first step, we are adding the function that will allow you to add as many doors as you want:
As you can see, we have X, Y, Z and X2, Y2, Z2.
The X, Y, Z is the entrance and the X2, Y2, Z2 is the finishing position.
We also have the angle, virtual world ID and interior ID.
SetCameraBehindPlayer sets the camera behind the player obviously.
Now we add the optional loadingobj(playerid) function. It will freeze you for 2 seconds and display some gametexts.
Here it is:
And the timer:
You can change the gametext however you want. Now after we all got that all set up, we can finally add our interiors.
Step 2)
Adding the interiors.
Define PRESSED:
Under OnPlayerKeyStateChange, add the key that you want to enter/exit your interiors with. You can learn more about keys here. I personally use Y to enter or exit interiors:
As you can see above, I added a custom interior that will allow us to enter and exit Madd Dogg's mansion from the back door. The entrance is at 1259.0759,-785.4166,92.0302, and it will get us to: 1262.2357,-785.3707,1091.9063. The facing angle the player is going to face is: 270.0000. The virtual world will be 69 and the interior will be 5.
The exit is at 1261.2383,-785.3589,1091.9063 and it will get us to: 1256.9819,-785.3765,92.0302. It will also set our facing angle to 90.0000, our virtual world to 0 and our interior to 0.
You can also define your virtual world and interior so you can use them later like so:
and then it will be:
Step 3)
Adding some pickups and 3D labels.
Add this under OnGameModeInit or under your custom pickup/label loading function:
You can change the pickupid, coordinates, color, text, etc. how you want. This is just an example for Madd Dogg's mansion back door.
That's pretty much it. I hope you guys like it!
In this tutorial I'm going to teach you how to script quick doors that require 1 neccessary function and 1 optional function.
Step 1)
Importing the functions.
In the first step, we are adding the function that will allow you to add as many doors as you want:
PHP Code:
stock InteriorDoor(playerid, Float:x, Float:z, Float:y, Float:x2, Float:z2, Float:y2, Float:angle, vwid, interiorid)
{
if(IsPlayerInRangeOfPoint(playerid, INTERIOR_ENTEREXIT_RANGE, Float:x, Float:z, Float:y))
{
SetPlayerVirtualWorld(playerid, vwid);
SetPlayerInterior(playerid, interiorid);
SetPlayerPos(playerid, Float:x2, Float:z2, Float:y2);
SetPlayerFacingAngle(playerid, Float:angle);
SetCameraBehindPlayer(playerid);
loadingobj(playerid);
}
return 1;
}
The X, Y, Z is the entrance and the X2, Y2, Z2 is the finishing position.
We also have the angle, virtual world ID and interior ID.
SetCameraBehindPlayer sets the camera behind the player obviously.
Now we add the optional loadingobj(playerid) function. It will freeze you for 2 seconds and display some gametexts.
Here it is:
PHP Code:
stock loadingobj(playerid)
{
TogglePlayerControllable(playerid, 0);
GameTextForPlayer(playerid, "~r~LOADING OBJECTS...", 2000, 3);
SetTimerEx("loadingobjects", 2000, false, "i", playerid);
}
PHP Code:
forward loadingobjects(playerid);
public loadingobjects(playerid)
{
TogglePlayerControllable(playerid, 1);
GameTextForPlayer(playerid, "~g~OBJECTS LOADED!", 2000, 3);
}
Step 2)
Adding the interiors.
Define PRESSED:
PHP Code:
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
PHP Code:
if(PRESSED( KEY_YES ))
{
InteriorDoor(playerid, 1259.0759,-785.4166,92.0302, 1262.2357,-785.3707,1091.9063, 270.0000, 69, 5); // back door entrance
InteriorDoor(playerid, 1261.2383,-785.3589,1091.9063, 1256.9819,-785.3765,92.0302, 90.0000, 0, 0); // back door exit
}
The exit is at 1261.2383,-785.3589,1091.9063 and it will get us to: 1256.9819,-785.3765,92.0302. It will also set our facing angle to 90.0000, our virtual world to 0 and our interior to 0.
You can also define your virtual world and interior so you can use them later like so:
PHP Code:
#define MADDDOGG_INT 5
#define MADDDOGG_VW 69
PHP Code:
InteriorDoor(playerid, 1259.0759,-785.4166,92.0302, 1262.2357,-785.3707,1091.9063, 270.0000, MADDDOGG_VW, MADDDOGG_INT);
InteriorDoor(playerid, 1261.2383,-785.3589,1091.9063, 1256.9819,-785.3765,92.0302, 90.0000, 0, 0);
Adding some pickups and 3D labels.
Add this under OnGameModeInit or under your custom pickup/label loading function:
PHP Code:
CreatePickup(1254, 1, 1259.0759,-785.4166,92.0302, -1); // madd dogg back door
CreatePickup(1318, 1, 1261.2383,-785.3589,1091.9063, -1); // boss house back exit
Create3DTextLabel("Back door", COLORNOTIF, 1261.2383,-785.3589,1091.9063, 15.0, BOSS_VW, 1); // madd dogg back exit
Create3DTextLabel("Madd Dogg's mansion\nBack door", COLORNOTIF, 1259.0759,-785.4166,92.0302, 15.0, 0, 1); // madd dogg back door entrance
That's pretty much it. I hope you guys like it!