Assistance with changing a string value in a table or removing/replacing the string altogether

I am no professional coder, but have been running and developing a gmod server (Stranded gamemode) very successfully with custom stuff and some code written from scratch, and I’m having a blast learning some lua

On to the help needed:

Stranded is a survival mode, for those who don’t know, and when a player Mines on a rock, they get ores. K, great.

When they do so, a menu called Skills gets an entry called “Mining”. awesome.

Once that player hits the max value for skill level in “Mining” I’d like the word in their skill menu “Mining” to become “Mining II”.

The code I originally used was an attempt to add the " II" prefix to the already existing “Mining” string. That resulted in lua created an additional entry under “Mining” skill as “Mining II” instead of appending it.
The code was similar to this:




ply:setSkill( "Mining" .. " II" )



Here is the gmod lua that should assist you all in helping me getting the correct syntax for this to work properly…
All of this is default code from the gamemode all I have added is the last “if” statement. Will that work for me??

p.s. the self.Owner:HasUnlock( “Mining_II” ) works elsewhere in game and I have other unlocks that I’ve used successfully. The part I need help with is getting the Mining to change to Mining II once they’ve unlocked a certain level of Mining.



function PlayerMeta:SetSkill( skill, int )
	skill = string.Capitalize( skill )
	if ( !self.Skills[ skill ] ) then self.Skills[ skill ] = 0 end

	if ( skill != "Survival" ) then
		int = math.Clamp( int, 0, 200 )
	else
		self.MaxResources = ( int * 5 ) + 25
	end
	self.Skills[ skill ] = int

	umsg.Start( "gms_SetSkill", self )
		umsg.String( skill )
		umsg.Short( self:GetSkill( skill ) )
	umsg.End()
end

function PlayerMeta:GetSkill( skill )
	skill = string.Capitalize( skill )
	if ( skill == "Survival" ) then self:SetNWInt( skill, self.Skills[skill] ) end
	return self.Skills[ skill ] or 0
end

function PlayerMeta:IncSkill( skill, int )
	skill = string.Capitalize( skill )
	if ( !self.Skills[ skill ] ) then self:SetSkill( skill, 0 ) end
	if ( !self.Experience[ skill ] ) then self:SetXP( skill, 0 ) end

	if ( skill != "Survival" ) then
		int = math.Clamp( int, 0, 200 )
		for id = 1, int do self:IncXP( "Survival", 20 ) end
		self:SendMessage( string.Replace( skill, "_", " " ) .. " +" .. int, 3, Color( 10, 200, 10, 255 ) )
	else
		self.MaxResources = self.MaxResources + 5
		self:SendAchievement( "Level Up!" )
	end
	
	self.Skills[skill] = self.Skills[skill] + int

	umsg.Start( "gms_SetSkill", self )
	umsg.String( skill )
	umsg.Short( self:GetSkill( skill ) )
	umsg.End()

	self:CheckForUnlocks()
	
	if self.Owner:HasUnlock( "Mining_II" ) then self.Skills["Mining"] = self.Skills["Mining II"] end -- Will this do what I want it to do? or am I way off base here? This seems to easy for it to work like i want.

end 



Will update if i figure it out before I get a response. Thanks all!!!

ok, I tested with what I thought may work (last if statement in the code pasted), it did not.

the unlock works and all, but the “Mining” word in the skills menu stays as “Mining” and doesn’t change to “Mining II”

is there anything else you would need for you guys to help me?

did i post incorrectly or something? or am I just not getting lucky with someone who can help? Thanks in advance!

p.s. I get no Lua errors clientside nor serverside. All works as usual, just doesn’t change the mining word for me

so, let me get this straight, when mining is maxed out, you want the mining skill to be replaced with “Mining II” and reset, however, all of the bonuses from maxing out Mining I will still be applied, but the user can still increase their skill further and get more bonuses?

Just trying to understand so my advice isn’t completely off base.

yes, correct! If I was to just get the name to change, I’d be happy.
pic is just to help understand what I’m looking at

https://image.ibb.co/cQph5Q/skill_menu_example.png

What does work:
The achievement unlocks, pop up message tells player Mining II is unlocked
If player continues mining, Mining II skill appears in Skill menu as it should and life goes on

Only thing that doesn’t work:
“Mining” skill entry in menu (pictured below) isn’t removed or replaced with “Mining II”
Mining II gets added to the list under Mining.

I feel like a dumb dumb because I believe it is something easy that I am just overlooking or not understanding.
I wouldn’t be surprised if my verbiage in the thread title is wrong

thanks again

[editline]19th July 2017[/editline]

here is the full part of that section that deals with player skills and experience, my first post of it was probably lacking a few parts


function PlayerMeta:SetSkill( skill, int )
	skill = string.Capitalize( skill )
	
	if ( !self.Skills[ skill ] ) then self.Skills[ skill ] = 0 end
		
	if ( skill != "Survival" ) then
		int = math.Clamp( int, 0, 200 )
	else
		self.MaxResources = ( int * 5 ) + 25
	end
	self.Skills[ skill ] = int

	umsg.Start( "gms_SetSkill", self )
		umsg.String( skill )
		umsg.Short( self:GetSkill( skill ) )
	umsg.End()
end

function PlayerMeta:GetSkill( skill )
	skill = string.Capitalize( skill )
	if ( skill == "Survival" ) then self:SetNWInt( skill, self.Skills[skill] ) end
	return self.Skills[ skill ] or 0
end

function PlayerMeta:IncSkill( skill, int )
	skill = string.Capitalize( skill )
	if ( !self.Skills[ skill ] ) then self:SetSkill( skill, 0 ) end
	if ( !self.Experience[ skill ] ) then self:SetXP( skill, 0 ) end

	if ( skill != "Survival" ) then
		int = math.Clamp( int, 0, 200 )
		for id = 1, int do self:IncXP( "Survival", 20 ) end
		self:SendMessage( string.Replace( skill, "_", " " ) .. " +" .. int, 3, Color( 10, 200, 10, 255 ) )
	else
		self.MaxResources = self.MaxResources + 5
		self:SendAchievement( "Level Up!" )
		
	end
	
	self.Skills[skill] = self.Skills[skill] + int

	umsg.Start( "gms_SetSkill", self )
	umsg.String( skill )
	umsg.Short( self:GetSkill( skill ) )
	umsg.End()

	self:CheckForUnlocks()
	
end


function PlayerMeta:DecSkill( skill, int )
	skill = string.Capitalize( skill )
	self.Skills[skill] = math.max( self.Skills[skill] - int, 0 )
	
	umsg.Start( "gms_SetSkill", self )
		umsg.String( skill )
		umsg.Short( self:GetSkill( skill ) )
	umsg.End()
end

function PlayerMeta:SetXP( skill, int )
	skill = string.Capitalize( skill )
	if ( !self.Skills[skill] ) then self:SetSkill( skill, 0 ) end
	if ( !self.Experience[skill] ) then self.Experience[skill] = 0 end

	self.Experience[skill] = int

	umsg.Start( "gms_SetXP", self )
		umsg.String( skill )
		umsg.Short( self:GetXP( skill ) )
	umsg.End()
end

function PlayerMeta:GetXP( skill )
	skill = string.Capitalize( skill )
	return self.Experience[skill] or 0
end

function PlayerMeta:IncXP( skill, int )
	skill = string.Capitalize( skill )
	if ( !self.Skills[skill] ) then self.Skills[skill] = 0 end
	if ( !self.Experience[skill] ) then self.Experience[skill] = 0 end

	if ( self.Experience[skill] + int >= 100 ) then
		self.Experience[skill] = 0
		self:IncSkill( skill, 1 )
	else
		self.Experience[skill] = self.Experience[skill] + int
	end

	umsg.Start( "gms_SetXP", self )
		umsg.String( skill )
		umsg.Short( self:GetXP( skill ) )
	umsg.End()
end

function PlayerMeta:DecXP( skill, int )
	skill = string.Capitalize( skill )
	self.Experience[skill] = self.Experience[skill] - int

	umsg.Start( "gms_SetXP", self )
		umsg.String( skill )
		umsg.Short( self:GetXP( skill ) )
	umsg.End()
end


seems it may be easier to create a PlayerMeta:RemSkill function to serve my purpose, since the gamemode does not have this built-in, but I’m not learned in lua enough to do this properly

Please stop using usermessages. You’ll find the net library is far superior.

Not really, just has a larger data buffer iirc

[editline]19th July 2017[/editline]

The main reason to use net is that usermessages are deprecated

This ^ , is actually noted in the lua’s of this gamemode that the usermsg are deprecated, but they use it anyway. I am not the creator of the gamemode, just a modder persay

::bump::

any help with this anyone? :frowning: