Help with my placemine command
#1

The textdraw and progressbar doesn't destroy after i leave the area

Код:
forward MineTimer(playerid);
public MineTimer(playerid)
{
	new string[124];
	new Count2;
	for(new i = 0; i < MAX_PLAYERS; i++)
	if(IsPlayerConnected(i))
	{
	    if(IsPlayerInRangeOfPoint(i, 2.0, MinePos[playerid][0], MinePos[playerid][1], MinePos[playerid][2]))
		{
	       if(GetPlayerState(i) != PLAYER_STATE_WASTED)
	         {
	            CreateExplosion(MinePos[i][0], MinePos[i][1], MinePos[i][2], 7, 30.0);
	            SendClientMessage(i,COLOR_INDIANRED,"You got blown away by a land mine.");
	 			DestroyObject(MineObject);
	 			DeletePlayer3DTextLabel(i,MineLabel[i]);
	 			MinePlaced[i] = 0;
				KillTimer(MineTimerUpdate[i]);
			 }
		}
		else if(IsPlayerInRangeOfPoint(i, 2.0, MinePos[playerid][0], MinePos[playerid][1], MinePos[playerid][2]) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
		{
	       if(GetPlayerState(i) != PLAYER_STATE_WASTED)
	         {
	            CreateExplosion(MinePos[i][0], MinePos[i][1], MinePos[i][2], 7, 30.0);
	            SendClientMessage(i,COLOR_INDIANRED,"Your vehicle touched a land mine.");
	 			DestroyObject(MineObject);
	 			DeletePlayer3DTextLabel(i,MineLabel[i]);
	 			MinePlaced[i] = 0;
				KillTimer(MineTimerUpdate[i]);
			 }
		}
		else if(IsPlayerInRangeOfPoint(i, 10.0, MinePos[playerid][0], MinePos[playerid][1], MinePos[playerid][2]))
		{
			Count2++;
			format(string,sizeof(string),"!DANGER ZONE!\nWatch your steps");
			UpdatePlayer3DTextLabelText(i,MineLabel[i], COLOR_RED,string);
			MineBar[i] = CreatePlayerTextDraw(i, 134.871246, 302.916717, "usebox");
			PlayerTextDrawLetterSize(i, MineBar[i], 0.000000, 1.639824);
			PlayerTextDrawTextSize(i, MineBar[i], 39.698383, 0.000000);
			PlayerTextDrawAlignment(i, MineBar[i], 1);
			PlayerTextDrawColor(i, MineBar[i], 0);
			PlayerTextDrawUseBox(i, MineBar[i], true);
			PlayerTextDrawBoxColor(i, MineBar[i], -570405291);
			PlayerTextDrawSetShadow(i, MineBar[i], 0);
			PlayerTextDrawSetOutline(i, MineBar[i], 0);
			PlayerTextDrawFont(i, MineBar[i], 0);
	        PlayerTextDrawShow(i, MineBar[i]);
	        MineBar2[i] = CreatePlayerProgressBar(i, 45.000000, 305.000000, 88.000000, 12.000000, -16447233, 10.000000, BAR_DIRECTION_RIGHT);
	        ShowPlayerProgressBar(i,MineBar2[i]);
	        SetPlayerProgressBarValue(i, MineBar2[i], Count2);
		}
		else if(!IsPlayerInRangeOfPoint(i, 10.0, MinePos[playerid][0], MinePos[playerid][1], MinePos[playerid][2]))
		{
			format(string,sizeof(string),"MINE HERE");
			UpdatePlayer3DTextLabelText(i,MineLabel[i], COLOR_INDIANRED, string);
			PlayerTextDrawDestroy(i,MineBar[i]);
			DestroyPlayerProgressBar(i,MineBar2[i]);
			
		}
	}
	return 1;
}
Код:
CMD:placemine(playerid,params[])
{
	new Float:MineX,Float:MineY,Float:MineZ;
	new Mine[128],sec;
	new TMine[128];
	if(MinePlaced[playerid] == 1 || TimeBombPlaced[playerid] == 1)
	return SendClientMessage(playerid,COLOR_INDIANRED,"You have already place a mine or bomb somewhere.");
	if(GetPlayerState(playerid) == PLAYER_STATE_WASTED)
	return SendClientMessage(playerid,COLOR_INDIANRED,"You dead bruh.");
	if(sscanf(params,"s[128]",Mine,TMine))
	return SendClientMessage(playerid,COLOR_PAPAYAWHIP,"USAGE: /placemine [Mine]/[TMine]");
	else if(!strcmp(Mine, "Mine", true))
	{
		GetPlayerPos(playerid,MineX,MineY,MineZ);
		MineObject = CreateObject(1252,MineX,MineY,MineZ-1,0.0, 0.0, 96.0);
		MinePos[playerid][0] = MineX;
		MinePos[playerid][1] = MineY;
		MinePos[playerid][2] = MineZ;
		SendClientMessage(playerid,COLOR_PURPLE,"You have placed a mine.");
		MinePlaced[playerid] = 1;
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i))
			{
				MineLabel[i] = CreatePlayer3DTextLabel(i,"MINE HERE",COLOR_INDIANRED, MineX, MineY, MineZ,20.0);
				MineTimerUpdate[i] = SetTimerEx("MineTimer", 1000, true,"i",i);
			}
		}
	}
Reply
#2

This is more for information for you, over all... Not really a fix for your situation.

Quote:
Originally Posted by Ramblings
You may have some luck and more ease using the zone streamer to create and delete zones, and use the OnPlayerEnterDynamicArea, OnPlayerLeaveDynamicArea (I THINK those are the callbacks it introduces).

https://sampforum.blast.hk/showthread.php?tid=102865

It'll simply mean you don't need to really have the timer, as the plugin will do that for you. However in saying that, you'll also need to redo your 3dtext to the streamers functions as it also streams those as well.

Don't confuse PlayerTextDraw for 3DText.

With the streamer you can make areas that are cylinders around the mines.

1 being 10, another being 2 on each mine. This will give you a callback situation for each of your mines, and not rely so much on the timer.
pawn Код:
else if(!IsPlayerInRangeOfPoint(i, 10.0, MinePos[playerid][0], MinePos[playerid][1], MinePos[playerid][2]))
        {
// Not needed           format(string,sizeof(string),"MINE HERE");
// Not needed           UpdatePlayer3DTextLabelText(i,MineLabel[i], COLOR_INDIANRED, string);
            PlayerTextDrawHide(i,MineBar[i]);
            DestroyPlayerProgressBar(i,MineBar2[i]);
           
        }
https://sampwiki.blast.hk/wiki/PlayerTextDrawHide

Only destroy it on disconnection, you can re-use the textdraws, and update them to show the color change.

You don't need to update its contents if you're only going to hide it. You will update it when you get close again.
Reply
#3

So i can't remove the textdraw and progressbar when the player leaves the area of mine?

EDIT: I re-read your post again,i don't have problem with 3dtextlabel,my only problem is that the TextDraw and ProgressBar doesn't delete when i leave the zone
Reply
#4

PlayerTextDrawHide(i,MineBar[i]);

That's to do with the textdraw... I just said to not mix up what I was saying above about the 3dText being overhauled with the TextDraw issue you have.

What I posted up, will work. Hide it, don't destroy it.

Then when you create it, only create it once, and simply update it.


Furthermore, read about the streamer, it'll remove the need for you to run timers, and it'll be a little more accurate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)