SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 10/04/2019, 10:32 PM   #1
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Issue with /time command.

So I'm trying to make a /time command which should show a textdraw displaying the current time. But instead I see a black box. What did I do wrong?

PHP Code:
new Text:InfoText[MAX_PLAYERS], DisplayingText[MAX_PLAYERS], TextTiming[MAX_PLAYERS];
stock CreateInfoTextDraw(playerid)
{
    
InfoText[playerid] = TextDrawCreate(319.000000380.000000"");
    
TextDrawAlignment(InfoText[playerid], 2);
    
TextDrawBackgroundColor(InfoText[playerid], 255);
    
TextDrawFont(InfoText[playerid], 1);
    
TextDrawLetterSize(InfoText[playerid], 0.3200001.500000);
    
TextDrawSetProportional(InfoText[playerid], 1);
    
TextDrawSetShadow(InfoText[playerid], 1);
}

stock DisplayInfoTextDraw(playeridstr[], duration)
{
    if(
DisplayingText[playerid])
    {
        
KillTimer(TextTiming[playerid]);
    }

    
TextDrawSetString(InfoText[playerid], str);
    
TextDrawShowForPlayer(playeridInfoText[playerid]);
    
TextTiming[playerid] = SetTimerEx("HideInfoTextDraw"duration *10000"i"playerid);
    
DisplayingText[playerid] = 1;
    return 
1;
}

stock HideInfoTextDraw(playerid)
{
    
TextDrawHideForPlayer(playeridInfoText[playerid]);
    
DisplayingText[playerid] = 0;
    return 
1;
}


stock MonthName(Month)
{
    new 
MonthStr[15];
    switch(
Month)
    {
        case 
1:  MonthStr "January";
        case 
2:  MonthStr "February";
        case 
3:  MonthStr "March";
        case 
4:  MonthStr "April";
        case 
5:  MonthStr "May";
        case 
6:  MonthStr "June";
        case 
7:  MonthStr "July";
        case 
8:  MonthStr "August";
        case 
9:  MonthStr "September";
        case 
10MonthStr "October";
        case 
11MonthStr "November";
        case 
12MonthStr "December";
    }
    return 
MonthStr;
}


CMD:time(playerid,params[])
{
    new 
monthdayyearhourminutesecondstr[500];
    
getdate(yearmonthday);
    
gettime(hourminutesecond);

    if(
Account[playerid][Prison] == 1)
    {
        
format(strsizeof(str), "~y~%02d %s, %d ~w~~n~%02d:%02d:%02d~n~Prison Sentence: %d minutes and %d seconds"dayMonthName(month), yearhourminutesecondAccount[playerid][PrisonTime] / 60Account[playerid][PrisonTime] / 60 60);
    }
    else
    {
        
format(strsizeof(str), "~y~%02d %s, %d ~w~~n~%02d:%02d:%02d"dayMonthName(month), yearhourminutesecond);
    } 

    
DisplayInfoTextDraw(playeridstr8);
    return 
1;

Stefhan is offline   Reply With Quote
Old 10/04/2019, 10:59 PM   #2
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Issue with /time command.

Alright, few things ...

1.
You're using global textdraws everywhere, that's not good, since you'll hit the max of 2048 quite quick. In your time command you show one of two things:
  • current time + prison sentence: since the prison sentence is different for each player, it's a prime example of when you need a player textdraw
  • current time: since the current time is the same for every player, it's a prime example of when you need a global textdraw
So in total you only need 1 player texdraw and 1 global textdraw.

2.
You don't initialize your textdraws, this can lead to very strange behaviour in the future.

3.
You're also doing this:
Code:
new str[500];
new MonthStr[15];
Just learn to calculate how large the string can get, but this is just a minor issue.

Other than that, I just tested you're code, and the time does show for me.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 10/04/2019, 11:02 PM   #3
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with /time command.

Quote:
Originally Posted by Freaksken View Post
Alright, few things ...

1.
You're using global textdraws everywhere, that's not good, since you'll hit the max of 2048 quite quick. In your time command you show one of two things:
  • current time + prison sentence: since the prison sentence is different for each player, it's a prime example of when you need a player textdraw
  • current time: since the current time is the same for every player, it's a prime example of when you need a global textdraw
So in total you only need 1 player texdraw and 1 global textdraw.

2.
You don't initialize your textdraws, this can lead to very strange behaviour in the future.

3.
You're also doing this:
Code:
new str[500];
new MonthStr[15];
Just learn to calculate how large the string can get, but this is just a minor issue.

Other than that, I just tested you're code, and the time does show for me.

I am getting this black box, how come it would work for you? I'm confused. What's wrong with making a textdraw like this? I don't want to make 200 different textdraws, just change the text based on what I want to tell the player at that time.
Stefhan is offline   Reply With Quote
Old 10/04/2019, 11:06 PM   #4
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Issue with /time command.

Quote:
Originally Posted by Stefhan View Post
I am getting this black box, how come it would work for you? I'm confused. What's wrong with making a textdraw like this? I don't want to make 200 different textdraws, just change the text based on what I want to tell the player at that time.
That's because most likely you've hit the global textdraw limit (just like I've told you you would) and the script is trying to display another textdraw and not the one you just created.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 10/04/2019, 11:08 PM   #5
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with /time command.

Quote:
Originally Posted by Freaksken View Post
That's because most likely you've hit the global textdraw limit (just like I've told you you would) and the script is trying to display another textdraw and not the one you just created.
I understand, so how would I go over making it a player textdraw instead?
Stefhan is offline   Reply With Quote
Old 10/04/2019, 11:16 PM   #6
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Issue with /time command.

Quote:
Originally Posted by Stefhan View Post
I understand, so how would I go over making it a player textdraw instead?
Instead of giving you the code on a plate, I'd suggest you read this tutorial. It's about how to create a speedometer with textdraws, but similar concepts apply here. Definitely read the first section, since it explains the difference between global and player textdraws.

After reading that, and you have any further questions, let me know here.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 11/04/2019, 08:34 PM   #7
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with /time command.

Quote:
Originally Posted by Freaksken View Post
Instead of giving you the code on a plate, I'd suggest you read this tutorial. It's about how to create a speedometer with textdraws, but similar concepts apply here. Definitely read the first section, since it explains the difference between global and player textdraws.

After reading that, and you have any further questions, let me know here.
As far as I'm aware, what I have is fine. I have like 2-3 global textdraws only, not 2048. And it is already a player textdraw, and it should be. I just want to fix the black box. Time shouldn't always display, just sometimes when the player types /time.
Stefhan is offline   Reply With Quote
Old 11/04/2019, 08:45 PM   #8
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Issue with /time command.

Quote:
Originally Posted by Stefhan View Post
As far as I'm aware, what I have is fine. I have like 2-3 global textdraws only, not 2048. And it is already a player textdraw, and it should be. I just want to fix the black box. Time shouldn't always display, just sometimes when the player types /time.
No, this is the code you gave:
Code:
new Text:InfoText[MAX_PLAYERS];
Text means global textdraw, PlayerText means player textdraw. You also have an array of MAX_PLAYERS, which by default is 1000. Thus this leads to a potential 1000 global textdraws.

Do you have any other textdraws (from other features, for example) that you create like this? If so, you're having textdraws conflicts, because with the code above, you're already using up 1000 global textdraw IDs.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 11/04/2019, 08:48 PM   #9
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with /time command.

Quote:
Originally Posted by Freaksken View Post
Instead of giving you the code on a plate, I'd suggest you read this tutorial. It's about how to create a speedometer with textdraws, but similar concepts apply here. Definitely read the first section, since it explains the difference between global and player textdraws.

After reading that, and you have any further questions, let me know here.
Quote:
Originally Posted by Freaksken View Post
No, this is the code you gave:
Code:
new Text:InfoText[MAX_PLAYERS];
Text means global textdraw, PlayerText means player textdraw. You also have an array of MAX_PLAYERS, which by default is 1000. Thus this leads to a potential 1000 global textdraws.

Do you have any other textdraws (from other features, for example) that you create like this? If so, you're having textdraws conflicts, because with the code above, you're already using up 1000 global textdraw IDs.
I have these:
PHP Code:
new Text:LobbyScreenText[3];
new 
Text:Date;
new 
Text:Time;
new 
Text:Injured;
new 
Text:NoKnife;
new 
Text3D:PlayerAdminLabel[MAX_PLAYERS];
new 
Text3D:PlayerDevLabel[MAX_PLAYERS];
new 
Text3D:PlayerSpawnLabel[MAX_PLAYERS] = {Text3D:INVALID_3DTEXT_ID, ...};
new 
Text:InfoText[MAX_PLAYERS]; 
Should I make it PlayerText instead then?

Please note that I undefined MAX_PLAYERS and redefined it to 200. Even changing it to 5 didn't remove the black box.
Stefhan is offline   Reply With Quote
Old 11/04/2019, 08:57 PM   #10
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 501
Reputation: 367
Default Re: Issue with /time command.

Quote:
Originally Posted by Stefhan View Post
Should I make it PlayerText instead then?
No, not necessarily all of them.

Let's start with the code you gave in your first post. Ask yourself this question: Does the InfoText textdraw need to show any information that is specific for a particular user? If not, then you need exactly 1 global textdraw, otherwise you'll need a player textdraw array.

If you want me to guide you through the solution, DM me on Discord, which talks a bit easier.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken 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
Time Issue SkyWinder Scripting Help 2 01/07/2015 03:29 AM
How to make when player type command one time to enable, second time to disable ? bustern Scripting Help 3 04/09/2013 09:35 AM
Time Issue CrystalMethod Scripting Help 1 03/07/2013 07:44 PM
Online Time System Issue LeeXian99 Scripting Help 5 23/04/2013 02:52 PM
Time Issue Abreezy Scripting Help 2 22/02/2012 03:33 AM


All times are GMT. The time now is 01:07 AM.


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