Queue of help messages
#1

Hey guys, I basically want a message system where a message shows for 10 seconds displaying information and if there is already a message showing it will wait before showing itself. Right now I have the second message kill the first but I want it to queue itself. The code I currently have is:
pawn Код:
new PlayerText:JobHelpText[MAX_PLAYERS];
new bool:TimerRunning[MAX_PLAYERS];

// OnPlayerConnect:
TimerRunning[playerid] = false;

CMD:info(playerid, params[])
{
    new string[256];
    format(string,sizeof(string),"%s",params);
    if (!TimerRunning[playerid])
    {
        PlayerTextDrawSetString(playerid,JobHelpText[playerid], string);
        PlayerTextDrawShow(playerid,JobHelpText[playerid]);
        SetTimerEx("JobHelpTextTimer", 10000, false, "i", playerid);
    }
    else
    {
        new temp[12];
        for (new i; ; i++) // (semi-)infinite loop
        {
             format(temp, sizeof(temp), "HelpText%i", i);
             if (!GetPVarType(playerid, temp))
             {
                 SetPVarString(playerid, temp, string);
                 break;
             }
        }
    }
    return 1;
}

forward JobHelpTextTimer(playerid);
public JobHelpTextTimer(playerid)
{
    if (!GetPVarType(playerid, "HelpText0"))
    {
        PlayerTextDrawHide(playerid, JobHelpText[playerid]);
    }
    else
    {
        new string[256], temp[12], temp2[12];
        GetPVarString(playerid, temp, string, sizeof(string));
        PlayerTextDrawSetString(playerid,JobHelpText[playerid], string);
        SetTimerEx("JobHelpTextTimer", 10000, false, "i", playerid);
        for (new i; ; i++)
        {
            format(temp, sizeof(temp), "HelpText%i", i);
            format(temp2, sizeof(temp2), "HelpText%i", i + 1);
            if (!GetPVarType(playerid, temp2))
            {
                DeletePVar(playerid, temp);
                break;
            }
            else
            {
                GetPVarString(playerid, temp2, string, sizeof(string));
                SetPVarString(playerid, temp, string);
            }
        }
    }
    return 1;
}
Now I didn't write this code, a friend helped me with this but he wasn't able to help with the issue.
Basically whenever a message is shown it works first time, then if another message comes up before 10 seconds it messes around a bit. It will always override the first message but it sometimes shows for a few seconds or just for a second.. I hope I am making sense and if you need any more information please let me know. I just want to fix this and actually understand what the problem is. Thank you!
Reply
#2

I dont get you... But Here is a code which will show a message but after some time: (NOT TESTED)
PHP код:
new delayedMsgTime[MAX_PLAYERS];
SendDelayedMessage(playeridtimecolormsg[]) //time has to be in seconds and cant go less than 1 second.
{
    
delayedMsgTime[playerid] = time;
    
SetTimerEx("MinusTimer"10000"dds"playeridcolormsg);
    return 
1;
}

forward MinusTimer(playeridcolormsg[]);
public 
MinusTimer(playeridcolormsg[])
{
    if(
delayedMsgTime[playerid] == 0) return SendClientMessage(playeridcolormsg);
    else {
        
delayedMsgTime[playerid] - 1;
        
SetTimerEx("MinusTimer"10000"dds"playeridcolormsg);
        return 
1;
    }

E: Oh.. Just got that you need it to edit the text of the textdraw.. :P
Wait, I will rewrite it.
Reply
#3

Ok, There you go:
PHP код:
#define DelayedTextDraw JobHelpText[playerid] //Change this whenever you want to change the textdraw.
new delayedMsgTime[MAX_PLAYERS];
SetDelayedTextdrawText(playeridtimestr[]) //time has to be in seconds and cant go less than 1 second.
{
    
delayedMsgTime[playerid] = time;
    
SetTimerEx("MinusTimer"10000"ds"playeridstr);
    return 
1;
}
forward MinusTimer(playeridstr[]);
public 
MinusTimer(playeridstr[])
{
    if(
delayedMsgTime[playerid] == 0) return PlayerTextDrawSetString(playerid,DelayedTextDrawstr);
    else {
        
delayedMsgTime[playerid] - 1;
        
SetTimerEx("MinusTimer"10000"ds"playeridstr);
        return 
1;
    }

However, IDK how can I pass PlayerText to the SetTimer so this code will only work for the textdraw defined in the define in the first line.

USAGE:
PHP код:
SetDelayedTextdrawText(playerid1"Hello."); //Will show after one second.
SetDelayedTextdrawText(playerid2"Hello 2."); //Will show after two second.
SetDelayedTextdrawText(playerid3"Hello 3."); //Will show after three second. 
Hope I helped

EDIT: Oh and also, Its a player textdraw.... Why'd you create an array... Its called a playertextdraw because it has an array built in it with better optimizations... If you want to use an array than use normal textdraws.
Reply
#4

Hmm, now I'm the confused one. Haha!
Bascially the command /info - Which is a test command. Displays the textdraw of whatever i type. example, /info Hello. Shows Hello in the bottom centre. Now the way I have it is so whenever information on what you need to do for the job comes up it shows up there. It all works fine, it shows up for 10 seconds and dissapears just fine. The issue is if I show another info message before the last one finsihed the new one just kills the old. I want the first to finish and then display the second.
Reply
#5

Ok, wait... I will explain it better.

I will edit this post when I finish.

EDIT:
There you go:
PHP код:
//DelayFunction
#define DelayedTextDraw JobHelpText[playerid] //Change this whenever you want to change the textdraw. 
new delayedMsgTime[MAX_PLAYERS]; 
SetDelayedTextdrawText(playeridtimestr[]) //time has to be in milliseconds and cant go less than 1 second. 

    
delayedMsgTime[playerid] = time//Set the time needed to a global variable.
    
SetTimerEx("MinusTimer"10000"ds"playeridstr);  //Start a one second timer that will minus the global timer each secod.
    
return 1

forward MinusTimer(playeridstr[]); 
public 
MinusTimer(playeridstr[]) 

    if(
delayedMsgTime[playerid] == 0//if the global var is equal to 0 meaning that the given time has passed, Do this: 
    
{
        
PlayerTextDrawSetString(playerid,DelayedTextDrawstr); //Set the text of the draw.
        
PlayerTextDrawShow(playerid,DelayedTextDraw); //Show it.
        
SetTimerEx("JobHelpTextTimer"10000false"i"playerid); //Hide it after 10 seconds. (ASSUMING THAT TIMER HAS HIDING CODE)
        
return 1;
    }
    else { 
//Else if it still not equal to 0
        
delayedMsgTime[playerid] - 1000//Minus one second from the global var.
        
SetTimerEx("MinusTimer"10000"ds"playeridstr); //Rerun the timer after 1 second.
        
return 1
    } 
}  
// OnPlayerConnect:
new queueNum[MAX_PLAYERS]; //This will hold the amount of textdraws in queue.
CMD:info(playeridparams[])
{
    new 
string[256];
    
format(string,sizeof(string),"%s",params);
    if(
queueNum == 0//Check if there is any other one in queue.
    
{
        
PlayerTextDrawSetString(playerid,JobHelpText[playerid], string); //Set the string instantly
        
PlayerTextDrawShow(playerid,JobHelpText[playerid]); //Show it
        
SetTimerEx("JobHelpTextTimer"10000false"i"playerid); //Hide it after 10 seconds. (ASSUMING THAT TIMER HAS HIDING CODE)
        
queueNum += 10000//Add 10 seconds to the queue so the next one that is added, Gets that time which is after this one gets hidden.
    
} else { //Else if there is some in queue.
        
SetDelayedTextdrawText(playeridqueueNumstring); //Trigger that function [GO UP]
        
return 1;
    }
}
forward JobHelpTextTimer() //This is the hide global function that gets triggerd after 10 secs.
public JobHelpTextTimer()
{
    
PlayerTextDrawHide(playeridDelayedTextDraw); //Hide that textdraw.
    
if(queueNum >= 10000queueNum -= 10000//Minus 10 seconds from the global var so next one gets shorter time and dont get long.
    
return 1;

Explained in comments... However its not tested so expect any bugs :P
Reply
#6

Oh that looks pretty interesting. Ill take a look into it and test some code out and try and make sense of it all so i might be a little while. Thanks heaps for all your efforts though. Ill let you know how it all goes.


PHP код:
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(2913) : warning 204symbol is assigned a value that is never used"queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4107) : error 017undefined symbol "queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4112) : error 017undefined symbol "queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4112) : warning 215expression has no effect
D
:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4116) : error 017undefined symbol "queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4119) : warning 209: function "cmd_info" should return a value
D
:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(27998) : error 001expected token";"but found "public"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28000) : error 017undefined symbol "playerid"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28001) : error 017undefined symbol "queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28001) : error 017undefined symbol "queueNum"
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28001) : warning 215expression has no effect
D
:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28015) : warning 215expression has no effect
Pawn compiler 3.2.3664              Copyright 
(c1997-2006ITB CompuPhase
7 Errors

Just got these errors after putting the code into my script.
Reply
#7

Hmm.. How is it assigned and never used.. And than it says its undefined :/

Can you show me what you have in ur script ?
Reply
#8

What do you mean, I have pasted it all in pretty well just like you put.
pawn Код:
public OnPlayerConnect(playerid)
{
    new string[128];
    new queueNum[MAX_PLAYERS];////This will hold the amount of textdraws in queue.
pawn Код:
new PlayerText:JobHelpText[MAX_PLAYERS];

new TextTimer[MAX_PLAYERS];//Queue for messages jobs help
#define DelayedTextDraw JobHelpText[playerid]
Reply
#9

That queueNum should be public not inside OnPlayerConnect.

If you can, PM me the whole script and I will help u.
Reply
#10

Yeah i just got that, ive fixed up all the errors Just a couple warnings now. I also changed the queueNum to queueNum[playerid]
pawn Код:
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(4120) : warning 209: function "cmd_info" should return a value
D:\SAMP\Redback Roleplay R4_Current\gamemodes\OblexiveRP.pwn(28016) : warning 215: expression has no effect
28016: delayedMsgTime[playerid] - 1000; //Minus one second from the global var.
The other warning ive fixed up.

Not sure if its the issue but i changed delayedMsgTime[playerid] - 1000; and added an "=" sign. cleared up the warning.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)