I will try to make an example for you:
Put this line in the beginning of ur code, before OnGameModeInit:
[pawn]forward IsPlayerAtZone(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy);[/pawn]
All the public functions must be forwarded, this is the rule of Pawn.
Now let's put our public function anywhere, between another public functions:
[pawn]public IsPlayerAtZone(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:plrx, Float:plry, Float:plrz; //we are declaring new floats - plrx, plr and plrz
GetPlayerPos(playerid, plrx, plry, plrz); //we are setting their parameters through getting player's position (x, y, z)
if(plrx >= minx && plrx <= maxx && plry >= miny && plry <= maxy) //if all the conditions (plrx >= minx && plrx <= maxx && plry >= miny && plry <= maxy) are true
{
return 1; // then we will be returned a "true" value of the "IsPlayerAtZone"function, like: -Is player at hospital? return 1 says: -Yes he is, because all the conditions are true!
}
return 0;
}[/pawn]
Now, let's use my stock function, that substracts player's cash according to the hp number he needs to be healthy
. Put this after public OnPlayerText:
[pawn]stock SellPlayerHealth(playerid)
{
new Float:phealth, Float:product1, Float:product2;
new pmoney = GetPlayerMoney(playerid);
new money2pay[256];
GetPlayerHealth(playerid, phealth);
if(phealth <= 99)
{
product1 = floatsub(100, phealth);
product2 = floatmul(product1, 5);//My price for 1hp is $5, change "5" on your integer if you want
format(money2pay, sizeof(money2pay), "%0.2f", product2);
new money2payfinal = strval(money2pay);
if(money2payfinal <= pmoney)
{
SetPlayerHealth(playerid, 100);
SetPlayerMoney(playerid, pmoney - money2payfinal);
new string2[256];
format(string2, sizeof(string2), "You have been healed for $%d", money2payfinal);
SendClientMessage(playerid, 0xFFFFFFAA, string2);
}
else
{
new string3[256];
format(string3, sizeof(string3), "You don't have enough money (you need $%d)", money2payfinal);
SendClientMessage(playerid, 0xFF0000AA, string3);
}
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "You don't need to heal yourself");
}
}[/pawn]
P.S. If u want to increase ur knowledge about this function PM me
Now let's put this in OnPlayerText:
[pawn]if(strcmp(text, "!healme", true)==0)
{
if(IsPlayerAtZone(playerid, -118.94831, -98.60392, -993.66656, -959.46441)) //we check if the player is at hospital, we will be returned true (yes, he is) if he is
{
SellPlayerHealth(playerid); //if he is, he will be "healed"
}
else //otherwise (if one or more conditions aren't true)
{
SendClientMessage(playerid, 0xFF0000AA, "You are not at the hospital!"); //he will be sent a message noticed that he isn't at the hospital coordinates
}
}[/pawn]
Good luck, tell me if I admitted any mistake