AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   show last 10 line (https://forums.alliedmods.net/showthread.php?t=340502)

SoccerjamTR 11-22-2022 07:30

show last 10 line
 
PHP Code:

public pShowNames(uIndex){
    new 
bmMotd[1680],bmAnlat;
    
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<head><style>table,th,td { border: 1px solid green;color:white; } td { width:100% }</style></head>");
    
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<center><ul>");    
    
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<span></span>")
    new 
lTotal ArraySize(gNames),lSearchForName[128],lGetTime[128];
    if(
lTotal){
        for(new 
ilTotali++){
            
ArrayGetString(gNames,i,lSearchForName,charsmax(lSearchForName));
            
ArrayGetString(gDates,i,lGetTime,charsmax(lGetTime));
            
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<li>%s %s</li>",lSearchForName,lGetTime);
        }    
    }
    
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"</ul><center>");
    
show_motd(uIndex,bmMotd,"");


This is motd show plugin but after 10 lines, lines don't fit on screen and i want to show last 10 lines. Player when open motd, shows 10 lines and this 10 line will be last lines. I want only the last 10 lines to appear when players open motd. Example if there is 30 lines, only last 10 line shows.

kww 11-22-2022 08:10

Re: show last 10 line
 
Something like this?
PHP Code:

    if(lTotal){
        for(new 
lTotal=> lTotal 10i--){
            
ArrayGetString(gNames,i,lSearchForName,charsmax(lSearchForName));
            
ArrayGetString(gDates,i,lGetTime,charsmax(lGetTime));
            
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<li>%s %s</li>",lSearchForName,lGetTime);
        }    
    } 

Or this:
PHP Code:

    if(lTotal){
        for(new 
lTotal 10<= lTotali++){
            
ArrayGetString(gNames,i,lSearchForName,charsmax(lSearchForName));
            
ArrayGetString(gDates,i,lGetTime,charsmax(lGetTime));
            
bmAnlat += formatex(bmMotd[bmAnlat],charsmax(bmMotd)-bmAnlat,"<li>%s %s</li>",lSearchForName,lGetTime);
        }    
    } 

Also you could do some refactoring and use add(); native:
PHP Code:

public pShowNames(uIndex) {
    new 
szMotd[MAX_MOTD_LENGTH];
    
    
add(szMotdcharsmax(szMotd), "<head><style>table,th,td { border: 1px solid green;color:white; } td { width:100% }</style></head>"); // Minimize?
    
add(szMotdcharsmax(szMotd), "<center><ul>");
    
//add(szMotd, charsmax(szMotd), "<span></span>"); // you can omit this container because you don't use it
    
    
new iTotal ArraySize(gNames);
    
    if(
iTotal) {
        new 
szBuffer[32 128];
        
// Player name max size is 32 characters + I'm sure the date you store there is much lesser than 128 characters
        
new szName[32], lGetTime[128];
        
        for(new 
iTotal 10<= iTotali++) {
            
ArrayGetString(gNamesiszNamecharsmax(szName));
            
ArrayGetString(gDatesilGetTimecharsmax(lGetTime));
            
formatex(szBuffercharsmax(szBuffer), "<li>%s %s</li>"szNamelGetTime);
            
add(szMotdcharsmax(szMotd), szBuffer);
        }
    }
    
    
add(szMotdcharsmax(szMotd), "</ul></center>");
    
show_motd(uIndexszMotd"");


Plus you need to learn some more html basics :)

I think this is none of my business but do you make table or list? I could help you if needed

SoccerjamTR 11-22-2022 16:37

Re: show last 10 line
 
i tried both but it gave error.
PHP Code:

Invalid cellvector handle provided (9:10:10)
[
AMXXDisplaying debug trace (plugin "g.amxx")
[
AMXXRun time error 10native error (native "ArrayGetString")
[
AMXX]    [0g.sma::pShowNames (line 15321

also i tried your full code. It gives same error.

SoccerjamTR 12-07-2022 07:22

Re: show last 10 line
 
These are nvault codes
PHP Code:

public plugin_init() 
{
        
gNames ArrayCreate(512);
    
gDates ArrayCreate(512);
    
get_time("(%H.%M-%d.%m)",gDateNow,charsmax(gDateNow));
    new 
lKey[16],lCountNames;
    
formatex(lKey,charsmax(lKey),"TotalName");
    
lCountNames nvault_get(cVault,lKey);

    if(
lCountNames){
    new 
lGetName[32],lGetDate[32];
    for(new 
ilCountNamesi++){
    
formatex(lKey,charsmax(lKey),"%i-Name",i);
    
nvault_get(cVault,lKey,lGetName,charsmax(lGetName));
    
ArrayPushString(gNames,lGetName);
    
formatex(lKey,charsmax(lKey),"%i-Time",i);
    
nvault_get(cVault,lKey,lGetDate,charsmax(lGetDate));
    
ArrayPushString(gDates,lGetDate);
    }
}



bigdaddy424 12-07-2022 11:53

Re: show last 10 line
 
maybe you surpassed character limit.
at the end of the function pShowNames run this code
client_print(uIndex, "%d", bmAnlat)
it'll print how many characters you've used.


All times are GMT -4. The time now is 15:38.

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