03.03.2018, 17:00
(
Последний раз редактировалось wallen; 05.03.2018 в 11:43.
)
Hello, in this tutorial you will also see there the usage of Floats(RandomSpawns), SetPlayerPos, SetPlayerInterior , SetPlayerVirtualWorld which will not be explained. This is only explaining how the bool variable works and checks made.
This tutorial is using arrays and operators check this out
https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
https://sampwiki.blast.hk/wiki/Control_Structures#Operators
(the basics) What is a bool?
We will start with something easy, we will try to send a message that will be shown for one time when a player spawns and so basically OnPlayerSpawn callback will be called and a simple DM respawn.
Different ways of checking a specific bool *4/03/2018
This kind of check can be also written to:
And if "CheckFirstTimeMessagel" is false can be used in:
Starting with coding it
So at the first, we obviously start defining the variable name and it's functions.
Once we finished defining our boolean variable we start now working under OnPlayerConnect callback, this is a very important thin line if we want that our boolean will work without problems, we need to make the boolean variable true to all the new incoming players on our server in order to show our stuff we want.
So let's now analyze our code on this specific callback to see how and what is used, so as i stated above with the tutorial booleans can be true or false regarding on what we want, we decided that we want to show for every new player that will spawn on the server a specific message that will not be shown for a second time.
So, what we did on that callback.
Now we need to work on OnPlayerDisconnect callback, otherwise it won't be fun having the message not shown for other players with same ID.
We simply do the same exactly thing we did with the OnPlayerConnect callback, but instead returning it to true, we must return it to false.
Respawn on DM locations (with random spawn) *4/03/2018
Another example of this following tutorial, how to make a player respawn when entering a certain DM zone.
This is our dm location we called it /zone.
As you see there are no booleans defined inside this command and so we can't make a player respawn, so let's go ahead and make our new bool variable, and don't forget that for these kind of stuffs we need to declare it as ARRAY, because every player in the server has their own value for it.
So once we finished with that, we add the check inside our command, so it will be like that:
Now we need to work on our callback and it will be OnPlayerSpawn, which will be called when or not the player must be spawned on DM, and based on our checks he must respawn on DM zone he entered before with /zone command.
So as we did we placed the right check on our interested callback, and the player will now get respawned on the interested area, but it's not finished. Because we didn't worked on our 2 last callback and they are OnPlayerConnect and OnPlayerDisconnect, it's to simply avoid that a player with same ID (as told before) gets respawned there for no reasons, so let's work on it by simply adding false on both callbacks.
Thanks for reading and following my first tutorial, we now ended this simple tutorial about these kind of variables. If you got anything to tell, notice me by commenting this thread. Don't send any PM's. !!
This tutorial is using arrays and operators check this out
https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
https://sampwiki.blast.hk/wiki/Control_Structures#Operators
(the basics) What is a bool?
- A bool is a variable that can be true (1) or false (0), regarding on how you want these booleans to be like.
- It's also a variable, we can make any variables we wan't, we name it, and we tell what it need to do.
- Also important part: these variables aren't really meant to be booleans when we talk about SA-MP PAWN. Their usage and meaning are similar to the boolean variable on C++.
We will start with something easy, we will try to send a message that will be shown for one time when a player spawns and so basically OnPlayerSpawn callback will be called and a simple DM respawn.
Different ways of checking a specific bool *4/03/2018
PHP код:
if(CheckFirstTimeMessagel == true)
PHP код:
if(CheckFirstTimeMessagel)
PHP код:
if(!CheckFirstTimeMessagel)
So at the first, we obviously start defining the variable name and it's functions.
PHP код:
new bool:CheckFirstTimeMessagel;
PHP код:
public OnPlayerConnect(playerid)
{
CheckFirstTimeMessagel[playerid] = true;
}
- We made the boolean true on the connection of the player. "= true".
- We specified the player ID that is connecting to our server "playerid".
PHP код:
public OnPlayerSpawn(playerid)
{
if(CheckFirstTimeMessagel[playerid] == true) // checking if the boolean is true
{
CheckFirstTimeMessagel[playerid] = false; //checking false to make it get called once
SendClientMessage(playerid, -1, "Welcome to our server, read /rules and /cmds");
}
}
- Checking if the boolean is true.
- Making the boolean false so it gets called once.
- And sending our holy message.
Now we need to work on OnPlayerDisconnect callback, otherwise it won't be fun having the message not shown for other players with same ID.
We simply do the same exactly thing we did with the OnPlayerConnect callback, but instead returning it to true, we must return it to false.
PHP код:
public OnPlayerDisconnect(playerid)
{
CheckFirstTimeMessagel[playerid] = false;
}
Another example of this following tutorial, how to make a player respawn when entering a certain DM zone.
This is our dm location we called it /zone.
PHP код:
new Float:zone[][] =
{
{-1469.6196,1617.4175,1052.5313},
{-1416.2900,1616.4597,1052.5313},
{-1373.7206,1588.0524,1052.5313},
{-1370.3744,1561.4594,1052.5313},
{-1357.4647,1618.7813,1052.5313}
};
PHP код:
CMD:zone(playerid)
{
SetPlayerVirtualWorld(playerid, 3);
SetPlayerInterior(playerid, 14);
new zones = random(sizeof(zone));
SetPlayerPos(playerid, zone[zones][0],zone[zones ]
[1],zone[zones ][2],zone[zones ][3],zone[zones ][4]);
return 1;
}
PHP код:
new bool:IsInZone[MAX_PLAYERS];
PHP код:
IsInZone[playerid] = true;
PHP код:
if(IsInZone[playerid] == 1)
{
new zones = random(sizeof(zone));
SetPlayerPos(playerid, zone[zones][0],zone[zones ]
[1],zone[zones ][2],zone[zones ][3],zone[zones ][4]);
}
PHP код:
IsInZone[playerid] = false;