Skip to content

Instantly share code, notes, and snippets.

@dennorske
Last active January 11, 2016 20:29
Show Gist options
  • Save dennorske/821cdce5fa29e59d7845 to your computer and use it in GitHub Desktop.
Save dennorske/821cdce5fa29e59d7845 to your computer and use it in GitHub Desktop.
//add this on top
new bool:TimerHasBeenCalled[MAX_PLAYERS]; //global
new bool:pickedup[MAX_PLAYERS]; //global
//replace with this
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
if(pickedup[playerid] == false) //to prevent multiple "pickups" by a player to confuse the timers
{
pickedup[playerid] == true;
PickupInRange(playerid);
}
return 1;
}
//add this:
function PickupInRange(playerid)
{
for(new i;i<MAX_PROPERTIES;i++)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, PropInfo[i][PropX], PropInfo[i][PropY], PropInfo[i][PropZ]) //are there any houses within 3.0 range?
{
printf("debug: Showing textdraws");
new str[140], str2[44];
format(str, 140, "~y~Property name: ~w~~h~%s~n~~y~Property ID: ~w~~h~%d~n~~y~Cost: ~g~$%d~n~~y~Earnings: ~g~$%d (every 2 minuts)", PropInfo[i][PropName], PropInfo[i][pid], PropInfo[i][PropValue], PropInfo[i][PropEarning]);
PlayerTextDrawSetString(playerid, pTextdraw[1][playerid], str);
format(str2, sizeof(str2),"Prop Owner: %s",PropInfo[i][PropOwner]);
PlayerTextDrawSetString(playerid, pTextdraw[0][playerid],str2);
ShowPropertyTextdraw(playerid);
SetTimerEx("PickupInRange", 1000, false, "d", playerid); //it will keep the timer alive as long as the house is nearby. When you go far away, the "else" will be called and the destroytextdraw will be called
break;
}
else //if not, then hide the textdraw
{
if(TimerHasBeenCalled[playerid] == false) //to prevent it calling it again before ending.
{
SetTimerEx("DestoryPropertyTextdraw", 3000, false, "d", playerid);
}
TimerHasBeenCalled[playerid] = true; //make this FALSE under "destroypropertytextdraw".
}
}//loop ends
return 1;
}
function DestoryPropertyTextdraw(playerid)
{
PlayerTextDrawHide(playerid, PlayerText:pTextdraw[0][playerid]);
PlayerTextDrawHide(playerid, PlayerText:pTextdraw[1][playerid]);
PlayerTextDrawHide(playerid, PlayerText:pTextdraw[2][playerid]);
//KillTimer(pTTime[playerid]); //no need for this, it's not looping.
TimerHasBeenCalled[playerid] = false;
pickedup[playerid] = false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment