• Lua Question(s)
    4 replies, posted
Hey everyone! I am a very junior lua coder and am having an issue with implementing player.Custom functions (V:). How do I implement these so I can call upon them without getting the value nil?
[QUOTE=duggy;50010185]Hey everyone! I am a very junior lua coder and am having an issue with implementing player.Custom functions (V:). How do I implement these so I can call upon them without getting the value nil?[/QUOTE] Can you give me an example of how you are doing this at the moment? EDIT: Well generally you want to use [URL="https://wiki.garrysmod.com/page/Global/FindMetaTable"]FindMetaTable(name)[/URL] Here's how: [lua] local player=FindMetaTable("Player") function player:CustomKill(message) self:ChatPrint(message) self:Kill() end [/lua] Then if you would call the function like [lua] playerEntity:CustomKill("And now, you are dead!") [/lua] It would kill the player and show them the message "And now you are dead!". EDIT2: In theory _R.Player should suffice, like [lua] local playerMeta=_R.Player function playerMeta:CustomKill(message) self:ChatPrint(message) self:Kill() end [/lua]
[QUOTE=Amic;50010286]Can you give me an example of how you are doing this at the moment? EDIT: Well generally you want to use [URL="https://wiki.garrysmod.com/page/Global/FindMetaTable"]FindMetaTable(name)[/URL] Here's how: [lua] local player=FindMetaTable("Player") function player:CustomKill(message) self:ChatPrint(message) self:Kill() end [/lua] Then if you would call the function like [lua] playerEntity:CustomKill("And now, you are dead!") [/lua] It would kill the player and show them the message "And now you are dead!". EDIT2: In theory _R.Player should suffice, like [lua] local playerMeta=_R.Player function playerMeta:CustomKill(message) self:ChatPrint(message) self:Kill() end [/lua][/QUOTE] Hey!thanks for the fast reply! But I was talking about adding a full new function. Like adding the function kill (this is assuming kill never existed).does that make more sense?
[QUOTE=duggy;50010592]Hey!thanks for the fast reply! But I was talking about adding a full new function. Like adding the function kill (this is assuming kill never existed).does that make more sense?[/QUOTE] To be honest you can override any existing function, even the Kill function, it's just a matter of the name. Hit me up on steam or show me your code for it and we can work it out I guess.
Well I dont want to override I want create
Sorry, you need to Log In to post a reply to this thread.