Hospital System (isPlayerInArea Help)
#1

Here is my code

Код:
forward isPlayerInArea();
Код:
public OnGameModeInit()
{
	SetTimer("isPlayerInArea", 1000, 1);
Timer is set at the very first line of the OnGameModeInit

Код:
public isPlayerInArea()
{
	new Float:X, Float:Y, Float:Z;
	for(new i=0; i < MAX_PLAYERS; i++)
	{
	    GetPlayerPos(i, X, Y, Z);
	    if (X <= -2885.0598 && X >= -1405.0571 && Y <= -1021.6824 && Y >= 1436.9240)
	    {
	        HospLocation[i] = sf;
	        return 1;
		}
		GetPlayerPos(i, X, Y, Z);
		if (X <= 130.7416 && X >= 1447.1925 && Y <= -2843.7100 && Y >= -799.4094)
		{
		    HospLocation[i] = lsas;
		    return 1;
		}
		GetPlayerPos(i, X, Y, Z);
		if(X <= 1700.8179 && X >= 2903.0476 && Y <= -2860.2761 && Y >= -701.8962)
		{
		    HospLocation[i] = lscg;
		    return 1;
		}
	}
	return 1;
}
Код:
forward DeadCountdown(playerid);
public DeadCountdown(playerid)
{
	if(DeadTimer[playerid] == 0 && HospLocation[playerid] == sf)
	{
	    KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, -2557.6716,661.3848,14.4531);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at San Fierro Medical Centre");
	    TogglePlayerControllable(playerid, 1);
	    return 1;
	}
	if(DeadTimer[playerid] == 0 && HospLocation[playerid] == lsas)
	{
 		KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, 2034.2024,-1405.9485,17.2210);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
        SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at Los Santos/All Saints Hospital");
		TogglePlayerControllable(playerid, 1);
	    return 1;
	}
 	if(DeadTimer[playerid] == 0 && HospLocation[playerid] == lscg)
	{
 		KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, 1178.5688,-1323.7841,14.1265);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
        SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at Los Santos/County General Hospital");
		TogglePlayerControllable(playerid, 1);
	    return 1;
	}
	DeadTimer[playerid] --;
	new string[128];
    format(string, sizeof(string), "~g~Seconds Left: ~w~ %d", DeadTimer[playerid]);
    GameTextForPlayer(playerid, string, 3000, 4);
	return 1;
}
Every time I die it spawns me at the San Fierro medical centre with the message I specified in the DeadTimer. I'm not sure where I've gone wrong. It must be setting the HospLocation to SF some how but it seems to only set it to SF and nothing else.
Reply
#2

yea that's ugly.. create a list of hospital spawn points, when the player dies, get his pos, loop through points, get the player's distance, return the index of the nearest point. done!
Reply
#3

Quote:
Originally Posted by Ada32
Посмотреть сообщение
yea that's ugly.. create a list of hospital spawn points, when the player dies, get his pos, loop through points, get the player's distance, return the index of the nearest point. done!
Thanks for the suggestion I just worked on the first solution I found. This certainly does sound alot better. I'll give this a write up and see how I get on.
Reply
#4

I've looked into what you suggested but I'm not too familiar with this. I'd like to know why the method I was using (even though it's a little messy) isn't working.
Reply
#5

It's not working, because I'm guessing this is how you created the variables:

pawn Код:
new sf;
new lsas;
new lscg;
These variables are all set to 0. So, when the script is going through the first if statement in DeadCountdown(), the HospLocation[playerid] is always going to equal to zero, which is also equal to "sf". This is why the player always spawns in San Fierro.

Edit:
Try using this:
pawn Код:
#define sf      1
#define lsas    2
#define lscg    3

public isPlayerInArea(playerid) // If you want you change this to getPlayerArea so it could match the function more.
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(X <= -2885.0598 && X >= -1405.0571 && Y <= -1021.6824 && Y >= 1436.9240) return sf;
    else if(X <= 130.7416 && X >= 1447.1925 && Y <= -2843.7100 && Y >= -799.4094) return lsas;
    else if(X <= 1700.8179 && X >= 2903.0476 && Y <= -2860.2761 && Y >= -701.8962) return lscg;
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    HospLocation[playerid] = isPlayerInArea(playerid);
    return 1;
}
Reply
#6

Quote:
Originally Posted by JJB562
Посмотреть сообщение
It's not working, because I'm guessing this is how you created the variables:

pawn Код:
new sf;
new lsas;
new lscg;
These variables are all set to 0. So, when the script is going through the first if statement in DeadCountdown(), the HospLocation[playerid] is always going to equal to zero, which is also equal to "sf". This is why the player always spawns in San Fierro.

Edit:
Try using this:
pawn Код:
#define sf      1
#define lsas    2
#define lscg    3

public isPlayerInArea(playerid) // If you want you change this to getPlayerArea so it could match the function more.
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    if(X <= -2885.0598 && X >= -1405.0571 && Y <= -1021.6824 && Y >= 1436.9240) return sf;
    else if(X <= 130.7416 && X >= 1447.1925 && Y <= -2843.7100 && Y >= -799.4094) return lsas;
    else if(X <= 1700.8179 && X >= 2903.0476 && Y <= -2860.2761 && Y >= -701.8962) return lscg;
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    HospLocation[playerid] = isPlayerInArea(playerid);
    return 1;
}
I solved it by doing the following which was much simpler.

Код:
public OnPlayerEnterDynamicZone(playerid, zoneid)
{
	if(IsPlayerInDynamicZone(playerid, sfhospzone) && PlayerInfo[playerid][pDead] == 0 && JustDied[playerid] == 0)
	{
	    PlayerInfo[playerid][pSF] = 1;
	    return 1;
	}
	if(IsPlayerInDynamicZone(playerid, lsashospzone) && PlayerInfo[playerid][pDead] == 0 && JustDied[playerid] == 0)
	{
	    PlayerInfo[playerid][pLSAS] = 1;
	    return 1;
	}
	if(IsPlayerInDynamicZone(playerid, lscghospzone) && PlayerInfo[playerid][pDead] == 0 && JustDied[playerid] == 0)
	{
	    PlayerInfo[playerid][pLSCG] = 1;
	    return 1;
	}
	return 1;
}
Код:
forward DeadCountdown(playerid);
public DeadCountdown(playerid)
{
    if(DeadTimer[playerid] == 0 && PlayerInfo[playerid][pSF] == 0 && PlayerInfo[playerid][pLSAS] == 0 && PlayerInfo[playerid][pLSCG] == 0)
	{
	    KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, -2557.6716,661.3848,14.4531);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at San Fierro Medical Centre");
	    TogglePlayerControllable(playerid, 1);
	    return 1;
	}
	if(DeadTimer[playerid] == 0 && PlayerInfo[playerid][pSF] == 1)
	{
	    KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, -2557.6716,661.3848,14.4531);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at San Fierro Medical Centre");
	    TogglePlayerControllable(playerid, 1);
	    return 1;
	}
	if(DeadTimer[playerid] == 0 && PlayerInfo[playerid][pLSAS] == 1)
	{
 		KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, 1178.5688,-1323.7841,14.1265);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
        SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at Los Santos/All Saints Hospital");
		TogglePlayerControllable(playerid, 1);
	    return 1;
	}
 	if(DeadTimer[playerid] == 0 && PlayerInfo[playerid][pLSCG] == 1)
	{
 		KillTimer(deadt[playerid]);
	    PlayerInfo[playerid][pDead] = 0;
	    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	    SetPlayerPos(playerid, 2034.2024,-1405.9485,17.2210);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SetCameraBehindPlayer(playerid);
	    ClearChat(playerid);
	    SendClientMessage(playerid, COLOR_SPRINGGREEN, "The Hospital said you made a full recovery! Be more careful next time!");
        SendClientMessage(playerid, COLOR_SPRINGGREEN, "You have spawned at Los Santos/County General Hospital");
		TogglePlayerControllable(playerid, 1);
	    return 1;
	}
	DeadTimer[playerid] --;
	new string[128];
    format(string, sizeof(string), "~g~Seconds Left: ~w~ %d", DeadTimer[playerid]);
    GameTextForPlayer(playerid, string, 3000, 4);
	return 1;
}
Works like a treat now but thanks for the help guys!
Reply
#7

Just stop everything your doing, and use the streamer plugin it has areas built in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)