30.11.2012, 12:37
How to add a timer when player near x y z it will show cp and when he's not near it, it will disable the cp
public OnPlayerUpdate(playerid)
{
if(IsPlayerInRangeOfPoint(playerid,distance,x,y,z))
{
//do anything here
}
else
{
//if he is not in the range of point
}
return 1;
}
//top of GM/FS
new UpdateTimer;
new InPos[MAX_PLAYERS];
//At gememodeint or filterscriptint
UpdateTimer = SetTimer("OnTimerUpdate", 3000, true);
//the callback
forward OnTimerUpdate();
public OnTimerUpdate{
for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
{
if(IsPlayerInRangeOfPoint(playerid ,distance,x,y,z) && InPos[playerid]==0)
{
InPos[playerid]=1;
//do what ever if the player is in the x,y,z cords
}else{
InPos[playerid]=0;
}
}
return 1;
}
forward isOnHouse(playerid); public isOnHouse(playerid) { for(new h = 0; h < sizeof(HouseInfo); h++) { if(PlayerToPoint(2.0, playerid, HouseInfo[h][hEntrancex], HouseInfo[h][hEntrancey], HouseInfo[h][hEntrancez])) { if(standingOnHouse[playerid] == 0) { nearHouse[playerid] = h; standingOnHouse[playerid] = 1; HouseEnter[h][playerid] = CreateDynamicCP(HouseInfo[h][hEntrancex],HouseInfo[h][hEntrancey],HouseInfo[h][hEntrancez], 1.5, -1, -1, -1, 100.0); } } } return 1; }
CreateDynamicCP(xPos, yPos, zPos, 1.5, -1, -1, -1, 5.5);
CreateDynamicCP(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
public isOnHouse(playerid) { for(new i = 0; i < sizeof(HouseInfo); i++) { if (gPlayerLogged[playerid] != 0 && nearHouse[playerid] != i && standingOnHouse[playerid] != 1 && PlayerToPoint(1.6, playerid,HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez]) || (PlayerToPoint(3, playerid,HouseInfo[i][hExitx], HouseInfo[i][hExity], HouseInfo[i][hExitz]) && HouseInfo[i][hWorld] == GetPlayerVirtualWorld(playerid))) { nearHouse[playerid] = i; standingOnHouse[playerid] = 1; HouseEnter[i] = CreateDynamicCP(HouseInfo[i][hEntrancex],HouseInfo[i][hEntrancey],HouseInfo[i][hEntrancez], 1.5, -1, -1, -1, 100.0); } } return 1; }
public OnPlayerLeaveDynamicCP(playerid, checkpointid) { for(new i = 0; i < sizeof(HouseInfo); i++) { nearHouse[playerid] = 255; standingOnHouse[playerid] = 0; DestroyDynamicCP(HouseEnter[i]); } }
for(new i = 0; i < MAX_HOUSES;i++) { if(checkpointid == HouseEnter[i]) { new pName[24]; GetPlayerName(playerid,pName,24); if(HouseInfo[i][hOwned] == 1 && PlayerInfo[playerid][pHouseKey] != i) { format(string, sizeof(string), "You're standing on %s's porch.",HouseInfo[i][hOwner]); SCM(playerid, COLOR_LIGHTGREEN, string); SCM(playerid, COLOR_WHITE, "Available commands: /enter, /ds(hout)"); } if(HouseInfo[i][hOwned] == 1 && PlayerInfo[playerid][pHouseKey] == i) { SCM(playerid, COLOR_LIGHTGREEN, "You're standing on your porch."); SCM(playerid, COLOR_WHITE, "Available commands: /enter, /open, /setrent, /setrentable, /sellhouse"); } if(HouseInfo[i][hOwned] == 0) { format(string, sizeof(string), "You're standing on free house to buy.",HouseInfo[i][hOwner]); SCM(playerid, COLOR_LIGHTGREEN, string); SCM(playerid, COLOR_WHITE, "Available commands: /buyhouse"); } } //Don't need it now |if(checkpointid == HouseExit[i]){}| }