Recommended Posts

I wanna give a character I'm working on a fourth meter that pretty much functions as an ammo meter that slowly regenerates on its own. I'm sure I can work out everything else on my own, but the first step's a doozy. Any help?

Share this post


Link to post
Share on other sites
Thomas Die    891

Netvars to send data to the client so your badge shows your stats
--my summary

inst.name = net_ushortint(self.inst.GUID, "name", "namedirty" )
--net_ushortint is the typical use of stats

--"name" is the name of the netvariable
--"namesdirty" is an Event which is called whenever this is changed

inst.name:set(amount beign set too)
-- inst.name:set(number) [same as] inst.name = number

inst.name:value()
--getting the value of the net_variable 


Next is badges, these are the little icons which we use to display the amounts
you put the below in a lua file called by itself in scripts\widgets

local Badge = require "widgets/badge" -- badge template to be used 

local badgename  = Class(Badge, function(self, owner)
    Badge._ctor(self, art, owner, { 174 / 255, 21 / 255, 21 / 255, 1 }, "status_health") -- status health = texture --  { 174 / 255, 21 / 255, 21 / 255, 1 } = colour in an rbg format 
    self.owner = owner
    self.num.max = max_value
    self.num.current = self.num.max

    owner:ListenForEvent("namedirty",function(owner,data)

        self.num.current = inst.name:value()
        self.percent = inst.name:value()  / self.num.max
    end)     

    self:StartUpdating() -- does uhhhhhgh something
end)

function badgename:OnUpdate(dt) -- every time it updates i guess
    self.num:SetString(tostring(math.floor(self.num.current)))
    self.anim:GetAnimState():SetPercent("anim", 1 - self.percent) 
end

return badgename


and to put it into modmain so it hits your character

 


badgename  = require "widgets/badgename"
AddClassPostConstruct("widgets/statusdisplays", function(self)
if self.owner.prefab ~= 'your character' then
     return
end

self.name = self:AddChild(badgename(self.owner))
self.name:SetPosition(62, 35, 0)

end)

 

Edited by Thomas Die
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Thomas Die    891

In terms of code or art, if you're talking about code i explained prior
for art just use text tool to extract an existing image or use ktool krane to extract and replace, like i did for the custom badges.

 

Share this post


Link to post
Share on other sites

In 

inst.name = net_ushortint(self.inst.GUID, "name", "namedirty" )

it says that the self ain't declared. I put it in my character's common_postinit. Was that the right place?

Share this post


Link to post
Share on other sites
Monti18    341

I just saw your thread from the other post, so I just thought I will hopefully give you an answer.

If you post the code that you have, I can try to find the error.

Normally this is pretty easy to do, Thomas Die already gave you most you need to know, so let's find the last error :D

 

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, Monti18 said:

I just saw your thread from the other post, so I just thought I will hopefully give you an answer.

If you post the code that you have, I can try to find the error.

Normally this is pretty easy to do, Thomas Die already gave you most you need to know, so let's find the last error :D

 

If you need more info, just let me know.

20210830151434_1.jpg

Share this post


Link to post
Share on other sites
40 minutes ago, Monti18 said:

I would need the common post init code to see what is wrong ;)

Oh.

inst.name = net_ushortint(inst.GUID, "sptnink", "sptninkdirty" )
	 --net_ushortint is the typical use of stats

	 --"name" is the name of the netvariable
	 --"namesdirty" is an Event which is called whenever this is changed

	 inst.sptnink:set(100)
	 -- inst.name:set(number) [same as] inst.name = number

	 inst.sptnink:value()
	 --getting the value of the net_variable 

The error points out the "inst.sptnink:set(100)" line. But I felt that including the rest of the badge info would help.

Edited by icantevenname

Share this post


Link to post
Share on other sites
Monti18    341

Well you defined your netvar as inst.name but then you use inst.sptnink, which is nil as you didn't define it.

Change 

inst.name = net_ushortint(inst.GUID, "sptnink", "sptninkdirty" )

to

 

inst.sptnink= net_ushortint(inst.GUID, "sptnink", "sptninkdirty" )

and it should work :)

  • Like 1

Share this post


Link to post
Share on other sites

Ah. Thought that was one of those things that'll make everything fall apart when changed.

But now it says that "art" ain't declared.

local sptninkbadge  = Class(Badge, function(self, owner)
    Badge._ctor(self, art, owner, { 174 / 255, 21 / 255, 21 / 255, 1 }, "inkmeter_inky") -- status health = texture --  { 174 / 255, 21 / 255, 21 / 255, 1 } = colour in an rbg format 
    self.owner = owner
    self.num.max = max_value
    self.num.current = self.num.max

    owner:ListenForEvent("sptninkdirty",function(owner,data)

        self.num.current = inst.name:value()
        self.percent = inst.name:value()  / self.num.max
    end)     

    self:StartUpdating() -- does uhhhhhgh something
end)

An' I've tried to change "inkmeter_inky" back to "status_health" and "nil" as Mr. Die suggested, but art's still ain't declared.

Share this post


Link to post
Share on other sites
Monti18    341

You declare the class as a badge with the function with the arguments self and owner. 

Then, in this function, you declare Badge._ctor with the arguments self,art and owner. But as the function is in the previous function, there is no art argument there. So the thing to remove the error is to just delete the art argument, as it doesn't help you with anything.

  • Like 1

Share this post


Link to post
Share on other sites
Monti18    341

Oh sorry I made an error, had a look again at badge.lua.

You can either replace the art with nil or with the animation that you have for your badge. I think you will also need to get rid of the inkmeter_inky argument as you don't have it probably at this moment. The easiest is to just enter nil so like this:

Badge._ctor(self, nil, owner, { 174 / 255, 21 / 255, 21 / 255, 1 }) -- status health = texture --  { 174 / 255, 21 / 255, 21 / 255, 1 } = colour in an rbg format 

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Monti18 said:

Oh sorry I made an error, had a look again at badge.lua.

You can either replace the art with nil or with the animation that you have for your badge. I think you will also need to get rid of the inkmeter_inky argument as you don't have it probably at this moment. The easiest is to just enter nil so like this:


Badge._ctor(self, nil, owner, { 174 / 255, 21 / 255, 21 / 255, 1 }) -- status health = texture --  { 174 / 255, 21 / 255, 21 / 255, 1 } = colour in an rbg format 

 

Okay, a few things...

It does work now!

But I needed to give a number to "self.num.max".

I already do have "inkmeter_inky" made.

But hey, it shows up! I just need to know how to make it regen over time and lower when using a weapon. I'm sure I can figure the rest out from there.

Edited by icantevenname

Share this post


Link to post
Share on other sites
Monti18    341

You will need a bit more to make an updating badge.

I don't think you need self.num.max, I don't even know if it's declared somewhere. You can do this with the self:SetPercent function.

Depending on what your badge should do, you can either make your own SetPercent function or use the one that is already defined.

Then, you need to tell the badge what it should do when you tell him StartUpdating(). This will run the function OnUpdate I think each frame.

So let's say you just use the SetPercent function that is already defined.

Then you add in your widget file after self:StartUpdating() this code snippet:

function self:OnUpdate(dt)
	    if self.owner ~= nil and self.owner.sptnink ~= nil then
    		local val = self.owner.sptnink:value()
		self:SetPercent(val,100) --100 is just an example, enter the max value that your badge should have.
	end
end

Now the badge will update itself automatically, so now you will only need to change the value of netvar to make it work.

You will need to make your own SetPercent function if you want to make it compatible with combined status or some other things.

For regen over time, use a periodic task that increases the meter and for the weapon, I don't know if you want it to only only decrease when using it, in this case you can use SetOnAttack on the weapon and apply it to the owner, otherwise you will need to check if you have a weapon equipped with a periodic task.

 

Edited by Monti18
  • Like 1

Share this post


Link to post
Share on other sites

Yes, I do want sptnink to deplete on use. I also kinda wanna have it so that if the character using the weapon has not enough or no sptnink, then they end up using the weapon as a blunt instrument.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now