❔ List string variables
Hello, I'm really new to C# and would like to get help.
How is the correct way to give variable for each case name? So it would display like - "WOOD x1" "STONE x2" etc... My code is below.
This is for Rust game plugin.
186 Replies
At the moment it just displays resources as text not values. those values are comming from another file.
i find it hard to understand what you're asking here
same
This line
List<string> u_ButtonNames = new List<string> { "WOOD " + "(resource)", "STONE " + "(resource)", "METAL " + "(resource)", "HQM " + "(resource)" };
WOOD, STONE ... are names for case break
How to pass variable in that name?
what variable?
from another file
so are you really asking how to read the contents of a file...?
What you mean how to read contents?
exactly what i said
I want to know how to pass variable in new List
what does variable mean to you?
changing number
if you already have the variable, you'd just do
$"WOOD x{amount}"
thanks
which is crazy if that's actually what you wanted to know
because you already use interpolated strings here
$"{player.UserIDString}.{t}"
I have only been working with C# like 2/3 days.
Sorry I'm just a fronend developer
Do you have spare time now?
I can show other file what I'm trying to get
uMod - Building Grades by Dana
Allows players to easily upgrade or downgrade an entire building
This is game plugin where my button executes this command - rust.RunClientCommand(player, "chat.say", "/up 1"); ...
Here is just plugin when user writes in chat like /up 1 /up 2 etc...
are u trying to display
Wood x1
instead of Wood resource
here?I'm trying to display ,
so just
wood x
not Wood x1
?yes
From that buildingGrade plugin I get in chat this x value
where are the names coming from?
But I want to get it on button
What names?
the names that are written in the buttons in ur image
from this?
from this
names are from here { $"WOOD x{amount}", $"WOOD x{amount}", $"WOOD x{amount}", $"WOOD x{amount}" };
thats weird, where is STONE, METAL and HQM?
yes
?
out sorry
this is original
where is STONE, METAL and HQM?
Sorry I edited with tha x{amount} and didnt change names
then why is
resource
written next to WOOD
here?now it's back where it was before
ok so apply string interpolation on ur list
I execute with button this command - case "WOOD": rust.RunClientCommand(player, "chat.say", "/up 1"); break; for stone, metal and hqm too
And I want to display in each button text + value
From that command
List<string> u_ButtonNames = new List<string> { $"WOOD x{woodAmount}", $"STONE x{stoneAmount}", $"METAL x{metalAmount}", $"HQM x{hqmAmount}" };
That "chat.say", "/up 1.2.3.4" executes from this file
uMod - Building Grades by Dana
Allows players to easily upgrade or downgrade an entire building
what file, this?
yes
buildingGrade.cs
If I'm correct than "UpgradeNotEnoughItems" is what I need for each value to get
did you finish naming the buttons correctly first?
What you mean naming correctly?
I can rewrite name on buttons
like naming them as u intended
Wood x1
On that button text even could be now wood but just w
etc...
this is how I need them
that number is chaning depending on base.
it could be 1k or 200k
can u elaborate?
what does that even mean
wait
it's indiscernible what your problem is
like do you not know how to display it, or do you not know how to get that number or
I need to display each chaning value for each button from that BuildingGrades.cs
Don't know how to get that value from that other file
what other file
and to display it in my file
display what in what file?
you're displaying it in the game, no?
you're not displaying anything in a file
yes
sorry not in file
that umod page has a discord server of its own
why not ask there?
Oh there is no help. toxic and asked like week ago another issue none responded
like in dev level
so where is the value
11500
stored?that's not what im asking
That value comes from building block
if i remove some wall add some wall it will change
where is that value originally stored, in a file? in the game itself?
yes
yes... for file.. or yes.. for in the game?
value comes from game
but that value in chat comes from that BuildingGrades.cs file
where in BuildingGrades.cs?
uMod - Building Grades by Dana
Allows players to easily upgrade or downgrade an entire building
Just to show those values can change
nothing "comes" from a
.cs
file. it comes from the code that's executed. the code for it just happens to exist in that fileokey sorry
looks like its coming from the
_missingItems
fieldyes could be
I could just write in my file this line?
nope
generally looking at the api surface of that plugin there isnt really a chance to get that information unless u copy the code over and do it urself
But how can I extuce that chat command then?
but for that u would need some modifications, and for that u would need a deeper understanding of c# and the rust plugin ecosystem
Yeah that's the problem that rust plugin ecosystem has no docs really
like normal examples
then its mostly try and error and looking at that building grades plugin
that BuildingGrade plugin works
my plugin works
You think there is no way to get those values from BuildingGrades in to my gui?
because I have seen simmular plugins on other servers, but those are custom written too
if u get the instance of the plugin somehow, u could try with reflection, but that will not be easy either
with tracking
missingItems
it looks like originally it constructs the value from constructionGrade.costToBuild
where constructionGrade
got its reference from buildingBlock.blockDefinition.GetGrade(targetGrade, 0);
yeah that I see
but how to get that value in my plugin to display on button?
basically u would have to write similar methods in ur plugin to get the desired info
That was the question
keep tracking where the references are coming from
there might be a way
That BuildingGrades is reference in my plugin
here is my all code
[PluginReference]
private readonly Plugin BuildingGrades;
it reads references from grade
yeah but it provides no public access to the info, so either use reflection to get the info the ugly way or reimplement modified versions of their methods to do so
what you mean by ugly way?
reflection
Reflection in .NET - .NET Framework
Review reflection in .NET. Get information about loaded assemblies and the types defined within them, such as classes, interfaces, structures, and enumerations.
so basically write new plugin?
reimplement modified versions of their methods to do sowould be probably faster, cleaner and more important, independent to code changes in their plugin
ahh
will think about it because I don't know C#
basically, in ur plugin, write some methods to get the cost info, u can use their implementation as reference on how to get that info
well all of that implies that u need to learn c# first
understand that, but can't figure out how to start that
I can't just copy necasery code in my file?
like some funcions etc?
first of all im not sure if their licensing allowes that, second u would still need to know what to copy and to modify to ur needs -> u need to learn c# anyway
ahh i just need to get value from each tier
oh, another way would probably be to kindly ask the plugin owners if they could provide the means to access that information, up to them if they do or not
what information do you mean?
tho thats probably the slowest way to get ur stuff done
the values u want to display
but if in that plugin already values display in chat
What is the problem to get them in my gui?
that they dont provide a way to publicly access these values
they just use them internally
looks like ur lucky, BuildingGrades is a singleton that can be accessed from its static field
?
you can just trace where the reference of the missing items message is coming from
they have a reference to their plguin, just not the underlying stuff is accessible
I see it from here i guess
something like
BuildingGrades.Instance.Assistant.AllBuildingItems
since those properties dont exist, you have to create them
to refer to their fieldin my plugin?
tho i cant guarantee it will work
the plugin clears the allbuildingItems list at some point
Basically i need private IEnumerator UpgradeBuildingBlocks(BasePlayer player, BuildingGrade.Enum targetGrade, PermissionSettings permissionSettings, bool isAdmin)
to work in my plugin
what does it do?
can u even modify BuildingGrades.cs ?
as i understood its not kokars plugin, kokars wants to write one on top of it, right?
yes i can
well I just need it in GUI
My buttons already are working with those chat commands from BuildingGrades
i gave you this hint, go try it
like in my code or in that building grades?
what do u think?
in my
you want to get the value and store it in your GUI button, right?
yeah
it sounds like you didnt get my hint
sorry I'm not backend developer
i wont write code for you
Can't figure it out yet
something like this?
nope
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
you are suppose to create a static property called Instance in your BuildingGrades class that gets the reference from the field _instance;
in BuildingGrade.cs
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
u posted ur GUI code somewhere, right?
yes here again
i wonder if you can get the value through the arguments
parent
or tc
in the methodtc
parent is for ui
can you show the file
BuildingPrivlidge.cs
?wrong file
?
BuildingPrivlidge.cs
not BuildingGrades.cs
sorry
no it is buildinggrades
where?
i cant find it
here
yes
where in the file?
which line?
i cant find
class BuildingPrivlidge
?
ou
that is from oxide it self
so its not possible to view that file?
BuildingPrivlidge tc - is needed to access in game toolcupboard
you mean like this?
what are u trying to show me
can u ctrl + left click
BuildingPrivlidge
?next?
?
I can't open it
but "BuildingPrivlidge tc" is only needed to shop gui interface when in game cupboard is opened and that's it
for that is no other purpose
then how would it know which building you are trying to build/upgrade?
When cupboard is placed it automatically detects building
BuildingPrivlidge tc = is when player is authorized to toolcupboard
what a hugely embarrassing typo
well yes, that class must have some references to those missing blocks
any chance tc has a property called
allowedConstructionItems
?that i don't know
but will try to find out
Did it
u figured out how to get the references from tc?
Will show in a while
Not at pc right now
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.