Hi all,
New to Lua coding here. I'm making a SWep that increases in power as the owner loses health. I want the damage of the weapon to be equal to 100 minus the player's current health. Currently, I have this coded as 100 - Entity:Health(). When I do this, I get the following error:
attempt to index global 'Entity' (a function value)
Does anyone know how to fix this to make it work as intended? I'd be very grateful.
Thanks in advance.
EDIT: Wanted to add that pl:Health() does not work for me either.
Post the full function.
I can help you
add me on [URL="http://steamcommunity.com/id/RCT_Games/"]steam[/URL]
added
[QUOTE=poopfest;50773697]Hi all,
New to Lua coding here. I'm making a SWep that increases in power as the owner loses health. I want the damage of the weapon to be equal to 100 minus the player's current health. Currently, I have this coded as 100 - Entity:Health(). When I do this, I get the following error:
attempt to index global 'Entity' (a function value)
Does anyone know how to fix this to make it work as intended? I'd be very grateful.
Thanks in advance.
EDIT: Wanted to add that pl:Health() does not work for me either.[/QUOTE]
Welcome to the forums, we have [ code ] tags to help separate your code.
You haven't specified what entity is, in this case you want it to the the player that's holding the weapon.
You need to put the code in a function that begins with [B]SWEP:[/B] ([I]self[/I] is a variable that exists in a function called with [I]:[/I])
[code]
local damage = 100 - self.owner:Health()
print("I'll do " .. damage .. " damage!")
[/code]
self is the weapon, owner is a field of weapon, for other fields a weapon has, see [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]the wiki[/URL].
Sorry, you need to Log In to post a reply to this thread.