Author Topic: Chat icon problem With ulx  (Read 3593 times)

0 Members and 4 Guests are viewing this topic.

Offline Nightmare2244

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Chat icon problem With ulx
« on: March 29, 2016, 04:04:42 PM »
NOTE: I tried to add the whole code in here, but it's WAY to big, like 26k characters, so unfortunately I had to use pastebin

LINK: http://pastebin.com/GK9xJanS

So as can see this is a nice chatbox, but... I have problems. I am trying to add my own custom ulx group for this chatbox, and whenever adding this to code


Code: [Select]
local OwnerIcon = Material("C:/garrysmod/garrysmod/materials/icon16/shield_rainbow.png") // ULX Owner custom group, added to custom code below. (As seen on line 30) It doesn't work, I also made sure that I added this to the code below

Code: [Select]
table.insert(TextTable, i+1, TextTable[i]:Nick())
            TextTableNum = TextTableNum + 1
            if !NoFirstPlayer and ShowIconsForPlayers then
                if ShowPlayerAvatars then
                    avatar = vgui.Create("AvatarImage")
                    avatar:SetPlayer(TextTable[i], 16)
                    avatar:SetSize(16, 16)
                    TextPosX = 17
                elseif ShowPlayerRanks then
                    if TextTable[i]:IsSuperAdmin() then
                        icon = SuperAdminIcon
                    elseif TextTable[i]:IsAdmin() then
                        icon = AdminIcon
                    elseif TextTable[i]:IsUserGroup("owner") then
                        icon = OwnerIcon
                    else
                        icon = DefaultUserIcon
                    end
                    TextPosX = 17
                end
(This starts on line 374)

As can see I added elseif TextTable:IsUserGroup("owner) then

and for some reason it uses the superadmins shield preset, mostly because I made the owner rank inherit from superadmin, which gives me a hunch of why it wont add it's own shield. but how do I fix this? Thanks!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat icon problem With ulx
« Reply #1 on: March 29, 2016, 07:02:04 PM »
1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Nightmare2244

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Chat icon problem With ulx
« Reply #2 on: March 29, 2016, 07:28:30 PM »
1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

I will try, I will report if it works.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Chat icon problem With ulx
« Reply #3 on: March 29, 2016, 07:45:17 PM »
My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

You're correct.

If..ElseIf..Else logic works in a manner that once one condition is met, the code is executed and the if block is escaped.
If more than one condition is possible to meet, you should always put the more desirable first in your statement.

Offline Nightmare2244

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Chat icon problem With ulx
« Reply #4 on: March 30, 2016, 05:36:07 AM »
1) I've not looked at your pastebin code, only your sample.
2) It's been 2+ years since I had to think about if/then/else statements.

My guess, 'elseif' gets skipped when first 'if' condition is met.
Meaning, if true elseif <skipped, first if was true, nothing 'else' to do>.

Try starting comparison high, working down low.
if owner elseif superadmin elseif admin

You where quite right on this part, it gives me the tag, and the shield like wanted, but leaves my SuperAdmin having the shield of the admin now. And I don't know if adding if statements to every adminicon in the code would work or not?

Heres the code now:
Code: [Select]
if TextTable[i]:IsUserGroup("owner") then
icon = OwnerIcon
elseif TextTable[i]:IsSuperAdmin() then
icon = AdminIcon
elseif TextTable[i]:IsAdmin() then
icon = SuperAdminIcon
As can see the if statement is now the owner, as I wanted a seperate shield for that. Knowing that the creator of this chatbox didn't really think they would want any other shield higher than superadmin shows this, but what gets me is that before it worked with superadmin and admin having their own seperate shields because it calls the first if statement of course, and then the first elseif statement, the others are ignored and the code moves on. So I am just trying to get if I need to add a if statement of each individual shield, or if I just need something else.
« Last Edit: March 30, 2016, 05:48:23 AM by Nightmare2244 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat icon problem With ulx
« Reply #5 on: March 30, 2016, 08:05:23 PM »
but leaves my SuperAdmin having the shield of the admin now.

Heres the code now:
Code: [Select]
if TextTable[i]:IsUserGroup("owner") then
icon = OwnerIcon
elseif TextTable[i]:IsSuperAdmin() then
icon = AdminIcon
elseif TextTable[i]:IsAdmin() then
icon = SuperAdminIcon
You need to adjust your icon assignment order too. :)
Your code currently assigns AdminIcon to icon if IsSuperAdmin, and SuperAdminIcon to icon if IsAdmin.

I'll also go ahead and give you a tip; learn how to use Gmod relative paths.
If you share this code as an addon with others, the files they have aren't going to be the same as your c:/garrysmod/garrysmod/Materials/. Gmod's "Material" command starts in <server root>/Materials. So, changing your Material statements, as an example from your first post for ownericon to Material("icon16/shield_rainbow.png") should work, and be transportable as a pack to others.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Nightmare2244

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Chat icon problem With ulx
« Reply #6 on: March 31, 2016, 09:34:02 AM »
You need to adjust your icon assignment order too. :)
Your code currently assigns AdminIcon to icon if IsSuperAdmin, and SuperAdminIcon to icon if IsAdmin.

I'll also go ahead and give you a tip; learn how to use Gmod relative paths.
If you share this code as an addon with others, the files they have aren't going to be the same as your c:/garrysmod/garrysmod/Materials/. Gmod's "Material" command starts in <server root>/Materials. So, changing your Material statements, as an example from your first post for ownericon to Material("icon16/shield_rainbow.png") should work, and be transportable as a pack to others.

Very true, I jused used my whole path so if error did wanna appear about it, I wouldn't have to take the time to fix it. I am just experimenting with it, but yes I should use relative paths.