Raised This Month: $22 Target: $400
 5% 

Request Plugin/Stock Function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
@LeX
Junior Member
Join Date: Nov 2018
Old 11-10-2023 , 05:12   Request Plugin/Stock Function
Reply With Quote #1

for a few days I've been facing a problem, centering the text in hud or text format (it doesn't really matter)

let's say we have this function (taken from ranksystem by oxicrom ( I think it is an edited version but it is a good example ) )
PHP Code:
public eShowHud(id
{
    
set_hudmessage(02552551.00.401.41.40.010.01, -1);
    
    if( 
g_iPlayerLevel[id] > MAXLEVEL 1)
    {
        
ShowSyncHudMsg(idSyncHudRankSystem,"[ Name: %s ]^n[ Rank: %s ]^n[ EXP: %i / %i ]^n[ Level: %i / %i ]",
        
szPlayerName[id],
        
g_mPlayerDatag_iPlayerLevelid ] ][ m_szRankName ],
        
g_iPlayerXPid ],
        
g_mPlayerDataMAXLEVEL ][ m_iRankXP ],
        
g_iPlayerLevel[id], MAXLEVEL );
    }
    else 
    {
        
ShowSyncHudMsg(idSyncHudRankSystem,"[ Name: %s ]^n[ Rank: %s ]^n[ EXP: %i / %i ]^n[ Level: %i / %i ]",
        
szPlayerName[id],
        
g_mPlayerDatag_iPlayerLevelid ] ][ m_szRankName ],
        
g_iPlayerXPid ],
        
g_mPlayerDatag_iPlayerLevelid ] + ][ m_iRankXP ],
        
g_iPlayerLevel[id], MAXLEVEL );
    }

how could I make a function to calculate the length of the string and then inside `[ ]' to be able to center and align the text? (i.e. add left and right spaces for centering and the brackets should be one under the other)

I have a similar plugin that prints hud messages in about the same way, that's why I gave this example ( it's more beautifully arranged in this example and expresses exactly what I want )

I want a plugin or a stock function.
if there is a rank plugin that centers the text and brackets in the hud, it would be even nicer (I haven't found such a plugin so far)
( mine is similar but contains more information and is not a simple rank system )

I was thinking of a stock function because it is easier for me to manage the centering (it is possible to do the same for other functions as well)

p.s. I didn't know where to post for problems like this, so sorry if I didn't post in the right place

Thanks for your time

Last edited by @LeX; 11-10-2023 at 05:14.
@LeX is offline
@LeX
Junior Member
Join Date: Nov 2018
Old 11-11-2023 , 04:15   Re: Request Plugin/Stock Function
Reply With Quote #2

up ?
@LeX is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 11-11-2023 , 09:22   Re: Request Plugin/Stock Function
Reply With Quote #3

  • Quote:
    Originally Posted by mlibre View Post
    with amxxStudio you could make it easier by moving the message exactly where you want it to appear



    then copy the generated code set_hudmessage ...
    Quote:
    Originally Posted by mlibre View Post
    look Hudmessage Generator works miracles
  • we get rid of the condition by simplifying levels
    PHP Code:
    public eShowHud(id
    {
        
    set_hudmessage(02552551.00.401.41.40.010.01, -1);
        
        
    ShowSyncHudMsg(idSyncHudRankSystem,"[ Name: %s ]^n[ Rank: %s ]^n[ EXP: %i / %i ]^n[ Level: %i / %i ]",
        
    szPlayerName[id],
        
    g_mPlayerDatag_iPlayerLevelid ] ][ m_szRankName ],
        
    g_iPlayerXPid ],
        
    g_iPlayerLevel[id] > MAXLEVEL g_mPlayerDataMAXLEVEL ][ m_iRankXP ] : g_mPlayerDatag_iPlayerLevelid ] + ][ m_iRankXP ],
        
    g_iPlayerLevel[id], MAXLEVEL );

__________________
mlibre is offline
@LeX
Junior Member
Join Date: Nov 2018
Old 11-11-2023 , 17:37   Re: Request Plugin/Stock Function
Reply With Quote #4

i don't think i made myself understood, sorry for theat

currently, this function will display the hud like this:
Code:
[ Name: @LeX ]
[ Rank: Newbie ]
[ EXP: 0 / 90 ]
[ Level: 0 / 71 ]
but i want it like this:
Code:
[  Name: @LeX    ]
[  Rank: Newbie  ]
[   EXP: 0 / 90  ]
[ Level: 0 / 71  ]
do you understand the difference now?
what i specified with that function is just an example that happens to be how i would display the hud

I can calculate the maximum length but I always encounter problems, apparently, the hud is oriented from right to left (which confuses me a bit)

I can center the whole format, but inside the brackets, for me it is more complicated
I want both the brackets ( [ ] ) and the format inside to be aligned
only that somehow the length of the name must not matter, for example, if the name is longer, spaces will be added until the brackets are one under the other
@LeX is offline
Tote
Senior Member
Join Date: Jul 2023
Old 11-12-2023 , 06:39   Re: Request Plugin/Stock Function
Reply With Quote #5

Quote:
Originally Posted by @LeX View Post
i don't think i made myself understood, sorry for theat

currently, this function will display the hud like this:
Code:
[ Name: @LeX ]
[ Rank: Newbie ]
[ EXP: 0 / 90 ]
[ Level: 0 / 71 ]
but i want it like this:
Code:
[  Name: @LeX    ]
[  Rank: Newbie  ]
[   EXP: 0 / 90  ]
[ Level: 0 / 71  ]
do you understand the difference now?
what i specified with that function is just an example that happens to be how i would display the hud

I can calculate the maximum length but I always encounter problems, apparently, the hud is oriented from right to left (which confuses me a bit)

I can center the whole format, but inside the brackets, for me it is more complicated
I want both the brackets ( [ ] ) and the format inside to be aligned
only that somehow the length of the name must not matter, for example, if the name is longer, spaces will be added until the brackets are one under the other
just put space til the space is equal between all brackets same as you did on the 2nd one "but i want it like this:"

Last edited by Tote; 11-12-2023 at 06:39.
Tote is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-12-2023 , 13:47   Re: Request Plugin/Stock Function
Reply With Quote #6

Kind of hardcoded but should do the job
Code:
[        Name: coconut tree            ]
[        Rank: Newbie                  ]
[         EXP: 0 / 90                  ]
[       Level: 0 / 71                  ]
PHP Code:
#include <amxmodx>

const maxlen_category 12
const maxlen 24

public plugin_init()
{
    
register_srvcmd("f""srvcmd_f")
}

public 
srvcmd_f()
{
    
server_print("%s"FormatString("Name""coconut tree"))
    
server_print("%s"FormatString("Rank""Newbie"))
    
server_print("%s"FormatString("EXP""0 / 90"))
    
server_print("%s"FormatString("Level""0 / 71"))
}

stock FormatString(text1[], text2[]){
    return 
fmt("%s%s"FormatString1(text1), FormatString2(text2))
}

stock FormatString1(text[]){
    new 
len strlen(text)
    new 
space maxlen_category len
    
new spaces[maxlen_category]

    while (
space 3)
    {
        
add(spacesmaxlen_category 1"    ")
        
space -= 4
    
}

    while (
space 2)
    {
        
add(spacesmaxlen_category 1"   ")
        
space -= 3
    
}

    while (
space 1)
    {
        
add(spacesmaxlen_category 1"  ")
        
space -= 2
    
}

    if (
space == 1)
    {
        
add(spacesmaxlen_category 1" ")
    }

    return 
fmt("[%s%s: "spacestext)
}

stock FormatString2(text[]){
    new 
len strlen(text)
    new 
space maxlen len
    
new spaces[maxlen]
    
    while (
space 3)
    {
        
add(spacesmaxlen 1"    ")
        
space -= 4
    
}

    while (
space 2)
    {
        
add(spacesmaxlen 1"   ")
        
space -= 3
    
}

    while (
space 1)
    {
        
add(spacesmaxlen 1"  ")
        
space -= 2
    
}

    if (
space == 1)
    {
        
add(spacesmaxlen 1" ")
    }
    return 
fmt("%s%s]"textspaces)

__________________
bigdaddy424 is offline
@LeX
Junior Member
Join Date: Nov 2018
Old 11-13-2023 , 05:16   Re: Request Plugin/Stock Function
Reply With Quote #7

Spoiler


did it work for you ?
I don't think that amxmodx can return a strings in a function

PHP Code:
L 11/13/2023 12:13:17: [AMXXDisplaying debug trace (plugin "fmt.amxx"version "1.0")
L 11/13/2023 12:13:17: [AMXXRun time error 5memory access
L 11
/13/2023 12:13:17: [AMXX]    [0fmt.sma::FormatString2 (line 85)
L 11/13/2023 12:13:17: [AMXX]    [1fmt.sma::FormatString (line 22)
L 11/13/2023 12:13:17: [AMXX]    [2fmt.sma::srvcmd_f (line 14

Edit:

the thing is that i can do what you did (adapted as i want)
that is, let's take for example what you said (designed to work)

to make it even more complicated (why not)
i also made an include dedicated to these functions of yours and some of mine )

i made it work in an array to keep everything in one place (something like this)

this is the include:
Spoiler

then using include, i did this:
Spoiler


result:
in hud is not aligned
in the console is

image:

Spoiler

Last edited by @LeX; 11-13-2023 at 09:04.
@LeX is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-13-2023 , 14:20   Re: Request Plugin/Stock Function
Reply With Quote #8

https://en.wikipedia.org/wiki/Monospaced_font
__________________
bigdaddy424 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Location: Siiiiiiiiuu
Old 11-13-2023 , 14:51   Re: Request Plugin/Stock Function
Reply With Quote #9

First i felt bad for you, playing Riot games damages a person’s soul. Then i saw cheat engine.
__________________
Jhob94 is offline
@LeX
Junior Member
Join Date: Nov 2018
Old 11-17-2023 , 04:09   Re: Request Plugin/Stock Function
Reply With Quote #10

sorry for the late reply

Quote:
Originally Posted by bigdaddy424 View Post
very interesting, i will try something then
maybe i can use other spaces depending on the letters using ascii

Quote:
Originally Posted by Jhob94 View Post
First i felt bad for you, playing Riot games damages a person’s soul. Then i saw cheat engine.
Off Topic:
I've had Riot games since my friends wanted us to play valorant, i think i played for a max 30 min and then i uninstalled it =))
and the cheat engine is not only used for cheating, you can inform yourself, i don't even have to explain to you what i use it for.
however, i don't know what it has to do with this topic, did you want attention?

sorry for off topic

Last edited by @LeX; 11-17-2023 at 04:14.
@LeX is offline
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

Forum Jump


All times are GMT -4. The time now is 22:19.


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