IsPlayerInArea help -
[BFT]eagles22 - 07.01.2011
First of all i want to say that i have searched for a solution to this problem several times and followed directions from several different posts and nothing ever changed. So when i enter the bank area i want it to give me a welcome message. Here is how i have it set up.
pawn Код:
//under OnGameModeInit()
SetTimer("AreaCheck",1000,true);
pawn Код:
public AreaCheck()
{
for (new i; i < MAX_PLAYERS; i++)
if(IsPlayerInArea(i,1717.8574,1725.7787,-1650.3363,-1659.9257))
{
SendClientMessage(i, COLOR_GREEN, "Welcome to the Bank!");
}
return 1;
}
pawn Код:
stock IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return 1;
return 0;
}
Re: IsPlayerInArea help -
Alex_Valde - 07.01.2011
Hmmm, maybe I don't get it or what, but this is very complicated way to do it. Isn't simpler just to make it in your "enter bank command"
pawn Код:
SendClientMessage(playerid, COLOR_GREEN, "Welcome to the Bank!");
Re: IsPlayerInArea help -
[BFT]eagles22 - 07.01.2011
because i dont want the entire interior to be the area where you can be to get banktime if you know what i am saying, also i want to be able to use it for exterior areas for mines too.
Re: IsPlayerInArea help -
admantis - 07.01.2011
Your code will spam 'Welcome to the bank' every second if he's in the area.
Re: IsPlayerInArea help -
[WF]Demon - 07.01.2011
You mean ATM's? this "AreaCheck" thing would not only cause lag but would also send the message every second if the player is in the area. if you have Command(s) then just put the message in those. just like all the other servers.
EDIT Yea what he said :P
Re: IsPlayerInArea help -
[BFT]eagles22 - 07.01.2011
So ive seen it other servers where it would say "Welcome to Bank" or "Welcome To Iron Mine" in other servers, then when you leave the area it would say "You left the bank" or "You left the Iron Mine". How would i do that?
Re: IsPlayerInArea help -
Kwarde - 07.01.2011
Do it like this:
Make an global bool (example:
new bool:PlayerIsInArea[MAX_PLAYERS] = false;)
Then, with "AreaCheck", it'll check if the player is in the area. If the player is in the area, AND the 'PlayerIsInArea[playerid]' is false, send the player an message and set it to true. If he's in the area, and the bool is true, he won't send the message.
And as last: if the player is not in the area, and the bool is true, send an message that he left and set the bool back to false
Re: IsPlayerInArea help -
[BFT]eagles22 - 08.01.2011
Quote:
Originally Posted by Kwarde
Do it like this:
Make an global bool (example: new bool:PlayerIsInArea[MAX_PLAYERS] = false;)
Then, with "AreaCheck", it'll check if the player is in the area. If the player is in the area, AND the 'PlayerIsInArea[playerid]' is false, send the player an message and set it to true. If he's in the area, and the bool is true, he won't send the message.
And as last: if the player is not in the area, and the bool is true, send an message that he left and set the bool back to false
|
I understand now how that would work, but i don't know whats wrong. I set that up and i still don't receive any message when a enter that area.
Re: IsPlayerInArea help -
Kwarde - 08.01.2011
Quote:
Originally Posted by [BFT]eagles22
I understand now how that would work, but i don't know whats wrong. I set that up and i still don't receive any message when a enter that area.
|
I'll make.
pawn Код:
#undef MAX_PLAYERS
#define MAX_SLOTS 500 //Max players of your server
#define MAX_PLAYERS MAX_SLOTS //If you wanna use MAX_PLAYERS instead of MAX_SLOTS...
#define CB:%0(%1) forward %0(%1); public %0(%1) //Now you don't need to forward for every custom callback. Juse use CB:Callbackname(params)
new bool:IsPInBankArea[MAX_PLAYERS] = false;
public OnFilterScriptInit() //Use OnGameModeInit if it's an gamemode
{
SetTimer("CheckPlayerArea", 1000, true);
return 1;
}
public OnPlayerConnect(playerid)
{
IsPInBankArea[playerid] = false;
return 1;
}
CB:CheckPlayerArea()
{
for(new i = 0; i < MAX_SLOTS; i++){
if(IsPlayerInArea(i, 1717.8574, 1725.7787, -1650.3363, -1659.9257)){
if(!IsPInBankArea[i]){
IsPInBankArea[i] = true;
SendClientMessage(i, COLOR_GREEN, "Welcome to the bank!");
}
}
if(!IsPlayerInArea(i, 1717.8574, 1725.7787, -1650.3363, -1659.9257)){
if(IsPInBankArea[i]){
IsPInBankArea[i] = false;
SendClientMessage(i, COLOR_GREEN, "You left the bank");
}
}
}
return 1;
}
stock IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return 1;
return 0;
}
By the way, do you have the good co-ordinations?
Because it can also be MinX,MinY,MaxX,MaxY instead of MinX,MaxX,MinY,MaxY
- Kevin
Re: IsPlayerInArea help -
[BFT]eagles22 - 08.01.2011
I think something is wrong with my coordinates, i tried a few different ways to get the coordinates but i just can't seem to get it to work.