Ulysses
General => Developers Corner => Topic started by: Nightmare2244 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
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
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!
-
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
-
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.
-
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.
-
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:
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.
-
but leaves my SuperAdmin having the shield of the admin now.
Heres the code now:
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.
-
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.