AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ShowSyncHudMsg to all players with languages (https://forums.alliedmods.net/showthread.php?t=163238)

e12harry 07-28-2011 05:04

ShowSyncHudMsg to all players with languages
 
Hello.
I have plugin whitch allows voting for map length.
Results are displayed as hud msg in format:

[minutes count] [minutes string for players language] [(votes count)]

10 Minutes (1)
20 Minutes (3)
30 Minutes (0)

this is my function uset for displaying results:

Code:

public showTimeVoteResults() {
    new t;
    new msg[256];
    new item[32];
    new result = get_pcvar_num(gCvarTimeVoteResults);
    if(get_pcvar_num(gCvarTimeVoteWin) != 2 && result == 3)
        result = 1;
    switch(result){
        case 0: return;
        case 1:{
            for(new i=0;i<mapTimesCount;i++){
                t = mapTimes[i];
                formatex(item, charsmax(item), "%d %L [%d]^n", t, LANG_PLAYER, "MINUTES", mapTimesVotes[i]);
                add(msg, charsmax(msg), item);
            }
        }
        case 2: {
            new itm1 = -1, itm1count=-1, idx1, idx2, itm2=-1,itm2count=-1;
            getTop2(mapTimes, mapTimesVotes, mapTimesCount, itm1, idx1,itm1count,itm2,idx2, itm2count);
   
            formatex(item, charsmax(item), "%d %L [%d]^n", itm1, LANG_PLAYER, "MINUTES", itm1count);
            add(msg, charsmax(msg), item);
            formatex(item, charsmax(item), "%d %L [%d]", itm2, LANG_PLAYER, "MINUTES", itm2count);
            add(msg, charsmax(msg), item);
        }
        case 3:{
            new sum = 0;
            for(new i =1;i<mapTimesCount;i++){
                sum += mapTimesVotes[i] * mapTimes[i];
            }
            new num = getRealPlayersnum();
            formatex(msg, charsmax(msg), "%d %L", floatround(float(sum)/ float(num)),  LANG_PLAYER, "MINUTES");
        }
    }
    trim(msg);
    set_hudmessage(255, 0, 0, 0.01, 0.14, 0, 6.0, 1.0);
    ShowSyncHudMsg(0, gHudCenteredMsg,  msg);
   
    if(!mapTimeVoteEnd){
        set_task(0.5, "showTimeVoteResults");
    }
}


Unfortunetly results are displayed incorrectly. The MINUTES word is displaying in different languages. It changes constantly from Minutes (en) to Minut (pl). How can I format this to display for each player in his own language?

Exolent[jNr] 07-28-2011 10:01

Re: ShowSyncHudMsg to all players with languages
 
You have to format and display individually for each player.

e12harry 07-28-2011 10:54

Re: ShowSyncHudMsg to all players with languages
 
No I did not. I waned to use one function for all. I saw this kind of work in many plugins, but I dont't know results in them.
If this is normal behaviour I will format message for each player and display separately.
Will the message be formated this way than:

Code:

public showTimeVoteResults(){
    new players[32];
    new num;
    get_players(players, num, "ch");
    new result = get_pcvar_num(gCvarTimeVoteResults);
    if(get_pcvar_num(gCvarTimeVoteWin) != 2 && result == 3)
        result = 1;
       
    for(new i=0;i<num;i++)
        showTimeVoteResultsForPlayer(players[i], result);
if(!mapTimeVoteEnd){
        set_task(0.5, "showTimeVoteResults");
    }
}


public showTimeVoteResultsForPlayer(id, result) {
    new t;
    new msg[256];
    new item[32];
   
    switch(result){
        case 0: return;
        case 1:{
            for(new i=0;i<mapTimesCount;i++){
                t = mapTimes[i];
                formatex(item, charsmax(item), "%d %L [%d]^n", t, id, LANG_PLAYER, "MINUTES", mapTimesVotes[i]);
                add(msg, charsmax(msg), item);
            }
        }
        case 2: {
            new itm1 = -1, itm1count=-1, idx1, idx2, itm2=-1,itm2count=-1;
            getTop2(mapTimes, mapTimesVotes, mapTimesCount, itm1, idx1,itm1count,itm2,idx2, itm2count);
   
            formatex(item, charsmax(item), "%d %L [%d]^n", itm1, id, LANG_PLAYER, "MINUTES", itm1count);
            add(msg, charsmax(msg), item);
            formatex(item, charsmax(item), "%d %L [%d]", itm2, id, LANG_PLAYER, "MINUTES", itm2count);
            add(msg, charsmax(msg), item);
        }
        case 3:{
            new sum = 0;
            for(new i =1;i<mapTimesCount;i++){
                sum += mapTimesVotes[i] * mapTimes[i];
            }
            new num = getRealPlayersnum();
            formatex(msg, charsmax(msg), "%d %L", floatround(float(sum)/ float(num)), id,  LANG_PLAYER, "MINUTES");
        }
    }
    trim(msg);
    set_hudmessage(255, 0, 0, 0.01, 0.14, 0, 6.0, 1.0);
    ShowSyncHudMsg(id, gHudCenteredMsg,  msg);
}

Or should it be formated in other way ?
Can I use one SyncHudObject for all players?

Exolent[jNr] 07-28-2011 10:58

Re: ShowSyncHudMsg to all players with languages
 
Quote:

Originally Posted by e12harry (Post 1520414)
No I did not. I waned to use one function for all. I saw this kind of work in many plugins, but I dont't know results in them.
If this is normal behaviour I will format message for each player and display separately.
Will the message be formated this way than:

Code:

        set_task(0.5, "showTimeVoteResults");
                formatex(item, charsmax(item), "%d %L [%d]^n", t, id, LANG_PLAYER, "MINUTES", mapTimesVotes[i]);

where id is id of player?
Or should it be formated in other way ?
Can I use one SyncHudObject for all players?

I meant to say "you have to" not just "you have".
You almost got it right, except for a few things:
- That set task I show above needs to be outside the loop.
- When formatting ML for player id, the format is: id, "KEY" (remove your LANG_PLAYER arg)
You should be able to use the same SyncHudObject for all players.

e12harry 07-28-2011 11:10

Re: ShowSyncHudMsg to all players with languages
 
set_task is outside loop
Thanks for help

Exolent[jNr] 07-28-2011 11:13

Re: ShowSyncHudMsg to all players with languages
 
Quote:

Originally Posted by e12harry (Post 1520426)
set_task is outside loop

I overlooked your tabbing too quickly, my mistake.

e12harry 07-29-2011 05:15

Re: ShowSyncHudMsg to all players with languages
 
I have changed formatting, but I have another question.
Is
Code:

ShowSyncHudMsg(0, gHudCenteredMsg, "%L", LANG_PLAYER, "VOTING_FAILED_NEXT_IN_TEN");
ok or should I show message separately for each player?

Exolent[jNr] 07-29-2011 09:29

Re: ShowSyncHudMsg to all players with languages
 
If you get those language issues, then do it separately.


All times are GMT -4. The time now is 00:54.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.