I was wondering if someone could help me understand how to create a killstreak system? I want to check the player to see if they're part of a certain team (this is for DarkRP). If they are part of that team and kill someone then add money to them. If they kill more than one person without dying then add an increasing amount of money to them for every player of the same team they kill.
I had somewhat of a similar system for another addon I created unfortunately I still don't have a very good grasp on table data. Can anyone start me off/break it down for me?
GM/PlayerDeath
Player/Team
Functions/Player/Server/addMoney
Programming in Lua (about tables)
Is this right/am I on the right track?
purgekills = {}
function purgekillstorage(victim, inflictor, attacker)
local ID = attacker:GetCreationID()
if victim:Team() == TEAM_PURGE then attacker:table.insert(purgekills) end
if victim == attacker then cashout() table.remove(purgekills) end
end
hook.Add("PlayerDeath", "killcheck", function(victim, inflictor, attacker)
attacker.Killstreak = 1
if attacker:IsPlayer() && attacker:Team() == TEAM_PURGE && victim:Team() == TEAM_PURGE && PurgeState == 1 then
attacker.Killstreak = attacker.Killstreak + 1
attacker:addMoney(500*attacker.Killstreak)
end
if attacker:IsPlayer() && attacker == victim then ply.Killstreak = 0 end
end)
I really want to pretend this is a shitpost but I genuinely don't understand why I'm not getting money from the kills. Tell me what I'm doing wrong
HEEEEEEEEEEEEEELLLLLLLLPPPPPPPPPPPPPP PLZ
print every condition to see if any of them return something you didnt expect them to
Show us your current code.
You are settings the attacker’s killstreak to one every time they get a kill. Try something like:
attacker.Killstreak = attacker.Killstreak or 1
attacker.Killstreak = attacker.Killstreak and attacker.Killstreak + 1 or 1
I was referring to the first statement of the anonymous function as that will set their kill streak to 1 every time they get a kill (can only get a max of two). Which now that I think about it more, it would make more sense to do
attacker.Killstreak = attacker.Killstreak or 0
otherwise an extra kill will be added on their first kill.
I ended up getting it - I put a variable in the player during initial spawn function then just set that same variable to attacker during PlayerDeath
You seem to be asking a lot of questions around here, all of them are you asking to be pretty much spoonfed code for diffrent things. To me it seems like you're trying to make a server in which case I think you should hire a developer on gmodstore instead of asking here since your knowledge of Lua seems to be non-existent, if that isn't an option then I'd recommend taking time to learn properly.
A killstreak system is pretty simple disregarding more complicated rewards.
Where would you suggest I ask questions I have about gmod lua?
don't. follow tutorials and the wiki, then when you really truly don't know what to do - as in you have done what you know is right and it still isn't working for some reason - then you ask about your problem here. what you don't do is throw together three lines of code based on bare minimum knowledge and ask for "help."
furthermore, don't ask "am i on the right track," just test for yourself. if it doesn't work, manually walk through the logic path of your code. if you don't know what that means or how to do it, you need more experience with any sort of programming first.
So you're saying... don't but do - but only if I know I'm right. So the developers thread is only for bug reports?
No it's not.
The wiki library doesn't contain all of the context and different ways you can use the code. For example I didn't know that you could set a player's variable and that variable would carry over when the player's value was changed. In this case it would have been a change from ply to attacker.
How am I supposed to know how a custom version of lua with its own custom library is supposed to piece together in every situation? I'm sure no one here was born with the knowledge - so it must've taken time. Which means... everyone here was once where I am now. Just because you chose to learn the hard way, or maybe you got the same treatment you're giving me now, doesn't mean that I have to do what you do, or did.
I came here and read the rules. What may seem like "throwing three lines of code together" for you - might actually be really difficult for me (yes even after reading the library).
I can see this mob mentality brewing around the principle of "lol you're new to glua so you must not be capable of learning anything". Give people the benefit of the doubt once in a while, and if you're on here constantly answering these kinds of questions (which wears you out) then maybe you should take a break from the forums.
I'm literally just wanting to learn more about how all these individual pieces fit together. So I'd appreciate it if me asking a question wasn't treated as a crime against the community.
I know you're frustrated, we all been here, but programing it's all about angry/sad people yelling at each to other, you will find good apples, but most likely bad apples, and if you don't feel like dealing with it, i highly encourage you to look another discipline beside programing ,because this will also happen when you learn web dev, game development, anything regarding programming
You can't just enter into a math intercourse without not knowing how to sum and expect it to people to help you that easy!
But if you still want to learn from the ground, at least me, i've learned by editing garrysmod.org addons to fit my needs and learning from them, once you get the catch, test yourself into seeing if you can try again into building this addon, I did it in my really young age of learning programming, it's not hard at all! But if you're still struggling, you should start looking for way simpler things
https://steamcommunity.com/sharedfiles/filedetails/?id=12960
That's been 7 year, you don't born with knowledge
https://garrysmods.org/download/7551/iphone-4s-entity-0195
And I had to edit LOTS of addons so in 2011 i could release this dumb entity, once again, we are not here to be mean, it's not an excuse, but please understand that programming are it's pretty hostile with new comers
So keep learning and happy coding
Sorry, you need to Log In to post a reply to this thread.