icantevenname Posted July 20, 2021 Share Posted July 20, 2021 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? Link to comment Share on other sites More sharing options...
Thomas Die Posted July 20, 2021 Share Posted July 20, 2021 (edited) 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 July 20, 2021 by Thomas Die 1 1 Link to comment Share on other sites More sharing options...
GearBull Posted July 20, 2021 Share Posted July 20, 2021 I've got an error: in badgename.lua in 4th line: variable 'art' is not declared Link to comment Share on other sites More sharing options...
Thomas Die Posted July 20, 2021 Share Posted July 20, 2021 probably replace with "status_health" 1 Link to comment Share on other sites More sharing options...
GearBull Posted July 20, 2021 Share Posted July 20, 2021 now "status_health" is not declared Link to comment Share on other sites More sharing options...
Thomas Die Posted July 20, 2021 Share Posted July 20, 2021 Yknow just replace with 'nil' if it doesn't exist it can not not say it doesn't exist. Link to comment Share on other sites More sharing options...
icantevenname Posted July 22, 2021 Author Share Posted July 22, 2021 Is there a template for the badge, or do I make it myself? Link to comment Share on other sites More sharing options...
Thomas Die Posted July 22, 2021 Share Posted July 22, 2021 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. Link to comment Share on other sites More sharing options...
icantevenname Posted July 24, 2021 Author Share Posted July 24, 2021 The Netvars confuse me. I get their purpose, but what I don't get is where to put them. In the modmain? Modinfo? In their own file and folder? Link to comment Share on other sites More sharing options...
Thomas Die Posted July 24, 2021 Share Posted July 24, 2021 Before anything server related For a player file inside common_postinit Link to comment Share on other sites More sharing options...
icantevenname Posted July 25, 2021 Author Share Posted July 25, 2021 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? Link to comment Share on other sites More sharing options...
Thomas Die Posted July 25, 2021 Share Posted July 25, 2021 Oh sorry put just inst maybe instead of self.inst Link to comment Share on other sites More sharing options...
icantevenname Posted July 26, 2021 Author Share Posted July 26, 2021 Now it says that inst.name:set(100) is nil. Did I do it wrong? I tried to set the value as 100 and I got the same error. Link to comment Share on other sites More sharing options...
Monti18 Posted August 30, 2021 Share Posted August 30, 2021 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 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 30, 2021 Author Share Posted August 30, 2021 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 If you need more info, just let me know. Link to comment Share on other sites More sharing options...
Monti18 Posted August 31, 2021 Share Posted August 31, 2021 I would need the common post init code to see what is wrong 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 31, 2021 Author Share Posted August 31, 2021 (edited) 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 August 31, 2021 by icantevenname Link to comment Share on other sites More sharing options...
Monti18 Posted August 31, 2021 Share Posted August 31, 2021 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 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 31, 2021 Author Share Posted August 31, 2021 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. Link to comment Share on other sites More sharing options...
Monti18 Posted September 1, 2021 Share Posted September 1, 2021 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. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted September 1, 2021 Author Share Posted September 1, 2021 So I did do that, but then an error happened in the badge lua. Does that mean my mod's badge code is too wonky? Should I provide the rest of my badge's lua? Link to comment Share on other sites More sharing options...
Monti18 Posted September 1, 2021 Share Posted September 1, 2021 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 1 Link to comment Share on other sites More sharing options...
icantevenname Posted September 1, 2021 Author Share Posted September 1, 2021 (edited) 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 September 1, 2021 by icantevenname Link to comment Share on other sites More sharing options...
Monti18 Posted September 2, 2021 Share Posted September 2, 2021 (edited) 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 September 2, 2021 by Monti18 1 Link to comment Share on other sites More sharing options...
icantevenname Posted September 2, 2021 Author Share Posted September 2, 2021 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now