SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 10/01/2020, 04:07 PM   #1
DomagojSellug
Huge Clucker
 
DomagojSellug's Avatar
 
Join Date: Sep 2016
Location: Croatia
Posts: 255
Reputation: 22
Default Updating 3D text label makes it dissapear

Basically I want to add a sort of a "loading bar" with 3D text labels for when player gets revived, but it doesn't seem to work. It starts at two bars and just disappears, that's it.

pawn Code:
RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "ddfff", playerid, reviveCount[playerid], pX, pY, pZ);

forward updateRevivingText(playerid, count, Float:x, Float:y, Float:z);
public updateRevivingText(playerid, count, Float:x, Float:y, Float:z)
{
    switch(count)
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            KillTimer(reviveTextTimer[playerid]);
            reviveCount[playerid] = 0;
            count = 0;
            return 1;
        }
    }
    count++;
    reviveCount[playerid]++;
    return 1;
}
__________________

San Andreas Multiplayer server based off Counter Strike: Global Offensive.

Join us today!

DISCORD: discord.sa-go.info
WEBSITE: http://sa-go.info
SERVER IP: samp.sa-go.info
DomagojSellug is offline   Reply With Quote
Old 10/01/2020, 05:35 PM   #2
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,229
Reputation: 205
Default Re: Updating 3D text label makes it dissapear

`count` is always 0, it does not matter if you modify its value in the callback. The initial value you passed in `SetTimerEx` is used.

pawn Code:
reviveCount[playerid] = 0;
reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);
// position is not used in `Update3DTextLabelText` function and counter will be increased and checked in the callback
pawn Code:
forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
    switch (reviveCount[playerid]++) // ++ or -- after the variable returns the old value and then it increases/decreases
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            RevivingText[playerid] = Text3D: INVALID_3DTEXT_ID;

            KillTimer(reviveTextTimer[playerid]);
            reviveTextTimer[playerid] = -1; // always reset ids to avoid destroying/killing the wrong thing

            reviveCount[playerid] = 0;
        }
    }
}
__________________
Calisthenics is offline   Reply With Quote
Old 10/01/2020, 07:38 PM   #3
DomagojSellug
Huge Clucker
 
DomagojSellug's Avatar
 
Join Date: Sep 2016
Location: Croatia
Posts: 255
Reputation: 22
Default Re: Updating 3D text label makes it dissapear

Quote:
Originally Posted by Calisthenics View Post
`count` is always 0, it does not matter if you modify its value in the callback. The initial value you passed in `SetTimerEx` is used.

pawn Code:
reviveCount[playerid] = 0;
reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);
// position is not used in `Update3DTextLabelText` function and counter will be increased and checked in the callback
pawn Code:
forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
    switch (reviveCount[playerid]++) // ++ or -- after the variable returns the old value and then it increases/decreases
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            RevivingText[playerid] = Text3D: INVALID_3DTEXT_ID;

            KillTimer(reviveTextTimer[playerid]);
            reviveTextTimer[playerid] = -1; // always reset ids to avoid destroying/killing the wrong thing

            reviveCount[playerid] = 0;
        }
    }
}
I made some minor changes and added debugging, here's a picture.
https://prnt.sc/qm08km
https://prnt.sc/qm06g8
https://prnt.sc/qm06t4
__________________

San Andreas Multiplayer server based off Counter Strike: Global Offensive.

Join us today!

DISCORD: discord.sa-go.info
WEBSITE: http://sa-go.info
SERVER IP: samp.sa-go.info
DomagojSellug is offline   Reply With Quote
Old 10/01/2020, 07:44 PM   #4
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,229
Reputation: 205
Default Re: Updating 3D text label makes it dissapear

Quote:
Originally Posted by DomagojSellug View Post
I made some minor changes and added debugging, here's a picture.
https://prnt.sc/qm08km
https://prnt.sc/qm06g8
https://prnt.sc/qm06t4
You modify the parameter and print its new value which is misleading. Move the debug message at the top and see for yourself or here is a sample of code:
pawn Code:
new timer_test;

main()
{
    timer_test = SetTimerEx("OnTestParameterValue", 500, true, "d", 1);
}

forward OnTestParameterValue(value);
public OnTestParameterValue(value)
{
    printf("OnTestParameterValue(%d);", value);
    value++;
   
    if (value == 5) KillTimer(timer_test);
}
Output is always the same:
pawn Code:
OnTestParameterValue(1);
.
.
.
OnTestParameterValue(1);
__________________
Calisthenics is offline   Reply With Quote
Old 10/01/2020, 07:45 PM   #5
DomagojSellug
Huge Clucker
 
DomagojSellug's Avatar
 
Join Date: Sep 2016
Location: Croatia
Posts: 255
Reputation: 22
Default Re: Updating 3D text label makes it dissapear

Quote:
Originally Posted by Calisthenics View Post
You modify the parameter and print its new value which is misleading. Move the debug message at the top and see for yourself or here is a sample of code:
pawn Code:
new timer_test;

main()
{
    timer_test = SetTimerEx("OnTestParameterValue", 500, true, "d", 1);
}

forward OnTestParameterValue(value);
public OnTestParameterValue(value)
{
    printf("OnTestParameterValue(%d);", value);
    value++;
   
    if (value == 5) KillTimer(timer_test);
}
Output is always the same:
pawn Code:
OnTestParameterValue(1);
.
.
.
OnTestParameterValue(1);
So... how should I edit my code in order to make it work?
__________________

San Andreas Multiplayer server based off Counter Strike: Global Offensive.

Join us today!

DISCORD: discord.sa-go.info
WEBSITE: http://sa-go.info
SERVER IP: samp.sa-go.info
DomagojSellug is offline   Reply With Quote
Old 10/01/2020, 07:49 PM   #6
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,229
Reputation: 205
Default Re: Updating 3D text label makes it dissapear

Quote:
Originally Posted by DomagojSellug View Post
So... how should I edit my code in order to make it work?
You check and increase the variable `reviveCount[playerid]` in the callback.

I also mention about resetting label/time ids in my first post which is quite important.
__________________
Calisthenics is offline   Reply With Quote
Old 10/01/2020, 07:51 PM   #7
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default Re: Updating 3D text label makes it dissapear

You could set the timer to not repeat, and then recreate the timer at the bottom each time it repeats.
Joe Staff is offline   Reply With Quote
Old 10/01/2020, 09:19 PM   #8
DomagojSellug
Huge Clucker
 
DomagojSellug's Avatar
 
Join Date: Sep 2016
Location: Croatia
Posts: 255
Reputation: 22
Default Re: Updating 3D text label makes it dissapear

For some reason it always sets the target ID to 0, I don't know why. But whatever I do, it always attaches the label and handles everything with ID 0 which causes some weird bugs (e.g. if ID 0 is trying to revive ME, it'll show something random from another label e.g. "Use F to enter.")
__________________

San Andreas Multiplayer server based off Counter Strike: Global Offensive.

Join us today!

DISCORD: discord.sa-go.info
WEBSITE: http://sa-go.info
SERVER IP: samp.sa-go.info
DomagojSellug is offline   Reply With Quote
Old 10/01/2020, 09:26 PM   #9
Radless
Little Clucker
 
Join Date: Jul 2019
Posts: 43
Reputation: 3
Default Re: Updating 3D text label makes it dissapear

Code:
		RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);

forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
	if(reviveCount[playerid] != 9)
	{
		switch(reviveCount[playerid])
		{
			case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
			case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
			case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
			case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
			case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
			case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");
			case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
			case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
			case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
		}
		reviveCount[playerid]++;
	}
	if(reviveCount[playerid] == 9)
	{
		Delete3DTextLabel(RevivingText[playerid]);
		reviveCount[playerid] = 0;
		KillTimer(reviveTextTimer[playerid]);
	}
	return 1;
}
Radless is offline   Reply With Quote
Old 10/01/2020, 09:37 PM   #10
DomagojSellug
Huge Clucker
 
DomagojSellug's Avatar
 
Join Date: Sep 2016
Location: Croatia
Posts: 255
Reputation: 22
Default Re: Updating 3D text label makes it dissapear

Quote:
Originally Posted by Radless View Post
Code:
		RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);

forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
	if(reviveCount[playerid] != 9)
	{
		switch(reviveCount[playerid])
		{
			case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
			case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
			case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
			case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
			case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
			case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");
			case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
			case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
			case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
		}
		reviveCount[playerid]++;
	}
	if(reviveCount[playerid] == 9)
	{
		Delete3DTextLabel(RevivingText[playerid]);
		reviveCount[playerid] = 0;
		KillTimer(reviveTextTimer[playerid]);
	}
	return 1;
}
That didn't help me with my issue though, my issue currently is that it's always setting the target ID to 0 for some reason...
__________________

San Andreas Multiplayer server based off Counter Strike: Global Offensive.

Join us today!

DISCORD: discord.sa-go.info
WEBSITE: http://sa-go.info
SERVER IP: samp.sa-go.info
DomagojSellug is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Texdraw Label o 3D text Label ? Attack97 Scripting Help 6 06/11/2019 05:28 PM
Updating label Despacito Scripting Help 6 15/05/2017 01:19 PM
Text Draw wont dissapear when new players register KyleSta123 Server Support 2 11/12/2013 03:23 PM
Text Label Not Updating San1 Scripting Help 0 29/06/2013 04:25 PM
3D Text Label not Updating San1 Scripting Help 2 28/06/2013 06:09 AM


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.