• Revive script help
    56 replies, posted
I was looking for a little help in my code. It works fine but I was hoping to add a function, problem is, I'm stuck. Now I'm only looking for a line of code that checks if the player was shot in the head, and if they have, it should turn a network value true so that only the player that got head-shotted can't be revived. I'm really stuck. If someone were to help me, I would credit them. I shouldn't think my code is needed, but if it is, I will post it.
[lua] if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then -- your shit here end [/lua] Put that in a DoPlayerDeath or DoPlayerDamage hook. You can figure out the rest for yourself.
Well that's 1 thing sorted. Thank you. But I'm still trying to figure out how to make a value unique to a player. When the player dies of a headshot, the value that changes is global. How would I make it unique to a player?
[QUOTE=extra.game;45711968]Well that's 1 thing sorted. Thank you. But I'm still trying to figure out how to make a value unique to a player. When the player dies of a headshot, the value that changes is global. How would I make it unique to a player?[/QUOTE] What code are you using to set the value now?
[QUOTE=Chimpanzee;45712111]What code are you using to set the value now?[/QUOTE] I'm trying to do: if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then deadMe = "dead" end I managed to make it so the defibs don't revive if deadMe is set to "dead" but deadMe is a global value which means it sets it for everyone. So if 1 guy dies then it sets it so everyone's value is dead. I need to make it so it's unique to everyone.
Since the server does the reviving, you could just set _p.deadMe = true; where _p is the player object in PlayerDeath. On PlayerSpawn reset _p.deadMe = false; When a player tries reviving, you could notify them that the player looks dead...
[QUOTE=Acecool;45712233]Since the server does the reviving, you could just set _p.deadMe = true; where _p is the player object in PlayerDeath. On PlayerSpawn reset _p.deadMe = false; When a player tries reviving, you could notify them that the player looks dead...[/QUOTE] Yeah possibly. I haven't tested it yet but wouldn't deadMe still be a global value? Even if it's being set when you die I'm not sure how it will make it seperate value to all players
[QUOTE=extra.game;45712309]Yeah possibly. I haven't tested it yet but wouldn't deadMe still be a global value? Even if it's being set when you die I'm not sure how it will make it seperate value to all players[/QUOTE] No, you didn't properly read what he said. When you set it as _p.deadMe = true instead of deadMe = true, it only places the variable on the player object in the code, not globally EDIT: Sorry, I realized where you made the mistake. His focus was on the _p part but yours was on the = true part
[QUOTE=extra.game;45712309]Yeah possibly. I haven't tested it yet but wouldn't deadMe still be a global value? Even if it's being set when you die I'm not sure how it will make it seperate value to all players[/QUOTE] _p is the player object ( in my example, you may have it as pl, ply, Player, etc... ). When you assign _p.deadMe = true; you're setting it to be known by the realm ( where the code is executed, client/server or both ie shared ), Lua is a language of tables, the player object is a table. Behaviors of tables can be expanded by making it a metatable. The player object is a table, but it is also a metatable. Metatables behave similarly to objects; essentially a metatable is a template for an object, that table can be cloned as many times as needed, or used as is. So, when you set a value such as _p.deadMe = true;, you can access it by _p[ "deadMe" ] or _p.deadMe for the value. It will be assigned to the individual player metatable / object, so you'll have a "globally accessible variable" for the realm is was called in but it can be different for other players. In fact, players that it isn't set on, if you try to access it, it'll be nil.
[QUOTE=Acecool;45713354]_p is the player object ( in my example, you may have it as pl, ply, Player, etc... ). When you assign _p.deadMe = true; you're setting it to be known by the realm ( where the code is executed, client/server or both ie shared ), Lua is a language of tables, the player object is a table. Behaviors of tables can be expanded by making it a metatable. The player object is a table, but it is also a metatable. Metatables behave similarly to objects; essentially a metatable is a template for an object, that table can be cloned as many times as needed, or used as is. So, when you set a value such as _p.deadMe = true;, you can access it by _p[ "deadMe" ] or _p.deadMe for the value. It will be assigned to the individual player metatable / object, so you'll have a "globally accessible variable" for the realm is was called in but it can be different for other players. In fact, players that it isn't set on, if you try to access it, it'll be nil.[/QUOTE] Wow your right. It was early in the morning when I posted that comment and I wasn't thinking straight. I'll go test this and see how it goes. I'll post and update if it works out :) [editline]17th August 2014[/editline] [QUOTE=Chimpanzee;45712342]No, you didn't properly read what he said. When you set it as _p.deadMe = true instead of deadMe = true, it only places the variable on the player object in the code, not globally EDIT: Sorry, I realized where you made the mistake. His focus was on the _p part but yours was on the = true part[/QUOTE] Yeah, figured that out shortly after. It was quite early in the morning when I posted that. I'll go test the code and see how it goes :)
Ok so I did: function HeadShot(ply) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then ply.deadMe == ply.deadMe + 1 end end hook.Add( "DoPlayerDeath", "headit", HeadShot ) It's not detecting the headshot for some reason. What have I done wrong?
[QUOTE=extra.game;45715287]Ok so I did: function HeadShot(ply) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then ply.deadMe == ply.deadMe + 1 end end hook.Add( "DoPlayerDeath", "headit", HeadShot ) It's not detecting the headshot for some reason. What have I done wrong?[/QUOTE] use code tags also your not doing anything with this ply.deadMe == ply.deadMe + 1 also don't use a int use a boolean
[QUOTE=frietje2008;45715313]use code tags also your not doing anything with this ply.deadMe == ply.deadMe + 1 also don't use a int use a boolean[/QUOTE] ply.deadMe is a value that I didn't include in this example. It works, it's just that the head shot isn't detected. I just find it easier using int since I've used it more than boolean. Oh and lastly, what do you mean by use code tags? Can you give an example or possible fix my errors?
[code]function whatvver() if ... then //what ?? end end [/code] [code] [./code] without dot easyer to read
The player object is a table. You can manipulate it like any other table. I suggest learning basic your operators first though.
Unless you set the last hitgroup to a variable named that, you need to use the function to retrieve it. [url]http://wiki.garrysmod.com/page/Player/LastHitGroup[/url]
.
[QUOTE=extra.game;45715414]ply.deadMe is a value that I didn't include in this example. It works, it's just that the head shot isn't detected. I just find it easier using int since I've used it more than boolean. Oh and lastly, what do you mean by use code tags? Can you give an example or possible fix my errors?[/QUOTE] No. You are saying that because you don't know what a boolean is. Do not use an integer. A boolean is true or false. In player damage you need a single statement. I'm on my phone, but essentially If hitgroup == hitgroup_head then player.deadbyhs = true end
[QUOTE=LauScript;45715688]No. You are saying that because you don't know what a boolean is. Do not use an integer. A boolean is true or false. In player damage you need a single statement. I'm on my phone, but essentially If hitgroup == hitgroup_head then player.deadbyhs = true end[/QUOTE] I'm pretty aware what Boolean is mate. I already tried = true but it gives and error saying then expected near "="
Because you have a syntax error and didn't put 'then', just like the error says. [editline]17th August 2014[/editline] And you don't need to record the headshot. Store a boolean on the player object IsRevivable and modify it when the player dies. Use player damage. Player scale damage. Or something similar [editline]17th August 2014[/editline] Also why are you adding numbers? You need to learn the very basics of lua operation before you do this sort of thing. == is for comparing and + is for adding. = is for defining
[QUOTE=LauScript;45715706]Because you have a syntax error and didn't put 'then', just like the error says. [editline]17th August 2014[/editline] And you don't need to record the headshot. Store a boolean on the player object IsRevivable and modify it when the player dies. Use player damage. Player scale damage. Or something similar [editline]17th August 2014[/editline] Also why are you adding numbers? You need to learn the very basics of lua operation before you do this sort of thing. == is for comparing and + is for adding. = is for defining[/QUOTE] 1) I did add then. It still gives an error. 2) I am adding the headshot thing because you can't be revived from a headshot in real life. As for the Boolean, I am having errors with it. If you can get a code to work that checks headshot with a Boolean statement, please post it :) 3) == means equal to* I am doing this because I can't get Boolean statements to work. I added then but it's expected near = for some reason. Again, if you can get a code to work them please post it. Have a nice day.
Dude I told you what to do you just aren't fluent in lua enough to understand what I mean. I can't write it for you because I am on a phone. In the playerscaledamage hook, check if the hitgroup passed to the function is a headshot. If it is, store a variable on the player object IsRevivable and set it to false. When it comes to someone trying to revive them, check if the variable is true and if so, revive them. If it isn't, disallow it. Your mistakes are from you being unexperienced with lua(which is fine!). But ive been doing this for 10 years so please listen to me when I tell you what to do - I know what you're trying to accomplish here.
[lua] hook.Add("DoPlayerDeath", "CheckForHeadshot", function(ply, killer, dmginfo) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then player.KilledByHeadshot = true end end) [/lua] Just have a check if the player was killed by a headshot or not when they try to revive. Be sure to make player.KilledByHeadshot false at some point. (I would say in a PlayerSpawn hook) On another note, please put [noparse][lua][/lua][/noparse] around your code!
[QUOTE=LauScript;45717637]Dude I told you what to do you just aren't fluent in lua enough to understand what I mean. I can't write it for you because I am on a phone. In the playerscaledamage hook, check if the hitgroup passed to the function is a headshot. If it is, store a variable on the player object IsRevivable and set it to false. When it comes to someone trying to revive them, check if the variable is true and if so, revive them. If it isn't, disallow it. Your mistakes are from you being unexperienced with lua(which is fine!). But ive been doing this for 10 years so please listen to me when I tell you what to do - I know what you're trying to accomplish here.[/QUOTE] Yeah I'm pretty new. I'm not completely inexperienced. I'll do that now and let you know how it goes. [editline]17th August 2014[/editline] [QUOTE=Author.;45717680][lua] hook.Add("DoPlayerDeath", "CheckForHeadshot", function(ply, killer, dmginfo) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then player.KilledByHeadshot = true end end) [/lua] Just have a check if the player was killed by a headshot or not when they try to revive. Be sure to make player.KilledByHeadshot false at some point. (I would say in a PlayerSpawn hook) On another note, please put [noparse][lua][/lua][/noparse] around your code![/QUOTE] Yeah I put in your code but it still didn't detect the headshot. I made it print a message to console to see if it detected it but still no.
Oh, right, I forgot something. Full code: [lua] hook.Add("DoPlayerDeath", "CheckForHeadshot", function(ply, killer, dmginfo) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then player.KilledByHeadshot = true end end) hook.Add("ScalePlayerDamage", "CheckHeadshot", function(ply, hitGroup) ply.lastHitGroup = hitGroup end) [/lua]
[Author.;45718342]Oh, right, I forgot something. Full code: [lua] hook.Add("DoPlayerDeath", "CheckForHeadshot", function(ply, killer, dmginfo) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then player.KilledByHeadshot = true end end) hook.Add("ScalePlayerDamage", "CheckHeadshot", function(ply, hitGroup) ply.lastHitGroup = hitGroup end) hook.Add("ScalePlayerDamage", "CheckHeadshot", function(ply, hitGroup) ply.lastHitGroup = hitGroup end) [/lua][/QUOTE] Terrible terrible way to do that. Sorry I can't just write it for you :/ For example. What if you don't want Poisoned players or something to be unrevivable, are you going to write an entirely different system for that two? Its 2-10 variables that change every time they take damage compared to one only when they die.
[QUOTE=Author.;45718342]Oh, right, I forgot something. Full code: [lua] hook.Add("DoPlayerDeath", "CheckForHeadshot", function(ply, killer, dmginfo) if ply.lastHitGroup && ply.lastHitGroup == HITGROUP_HEAD then player.KilledByHeadshot = true end end) hook.Add("ScalePlayerDamage", "CheckHeadshot", function(ply, hitGroup) ply.lastHitGroup = hitGroup end) hook.Add("ScalePlayerDamage", "CheckHeadshot", function(ply, hitGroup) ply.lastHitGroup = hitGroup end) [/lua][/QUOTE] You duplicated the last part of your code.
[QUOTE=Chimpanzee;45718367]You duplicated the last part of your code.[/QUOTE] I realised that. I took this from an old script I made a few months ago, and I can't remember why I duplicated that, and it's most likely not needed. But I just wanted to make sure.
[QUOTE=Author.;45718406]I realised that. I took this from an old script I made a few months ago, and I can't remember why I duplicated that, and it's most likely not needed. But I just wanted to make sure.[/QUOTE] It is not needed. Why would it be.
The headshot detection works but player.KilledByHeadshot is still a global value :(
Sorry, you need to Log In to post a reply to this thread.