Nutscript - Setting a player's body group with a chat command
10 replies, posted
Hello everyone! I'm developing a gamemode for Nutscript, and I'm trying to make a chat command that when entered will set a bodygroup on a player's model. Ideally, I'd like it to be toggleable, but right now I have two separate commands.
Example:
The player enters "/gear" in chat, and their playermodel will then be adorned with all sorts of combat gear. The player then enters "/gear" again, and their playermodel is then stripped of gear.
Here's what I have right now:
[code]nut.command.add("gearon", {
syntax = "",
onRun = function(client, arguments)
client:SetBodygroup("1","2")
end
})
nut.command.add("gearoff", {
syntax = "",
onRun = function(client, arguments)
client:SetBodygroup("1","0")
end
})
[/code]
So the problem is, whenever I run the command, I get this error back:
[code]
[ERROR] gamemodes/ww3/plugins/sh_gear.lua:5: attempt to call method 'SetBodyGroup' (a nil value)
1. onRun - gamemodes/ww3/plugins/sh_gear.lua:5
2. run - gamemodes/nutscript/gamemode/core/libs/sh_command.lua:145
3. parse - gamemodes/nutscript/gamemode/core/libs/sh_command.lua:180
4. Run - gamemodes/nutscript/gamemode/core/hooks/sv_hooks.lua:248
5. unknown - gamemodes/nutscript/plugins/chatbox/sh_plugin.lua:69
6. func - gamemodes/nutscript/gamemode/core/libs/thirdparty/sh_netstream2.lua:117
7. unknown - lua/includes/extensions/net.lua:32
[/code]
I'll be honest, I have no idea what I'm doing here, I have very little knowledge or experience with Lua, let alone GMod Lua, so if anyone who could help could explain to me what's what like I'm a god damn five year old, that would be ideal. Or, you could just write the command for me and I'd learn nothing, it's up to you, beggars can't be choosers right?
Any help would be greatly appreciated, many thanks.
[QUOTE=Blazer232;51202874]Hello everyone! I'm developing a gamemode for Nutscript, and I'm trying to make a chat command that when entered will set a bodygroup on a player's model. Ideally, I'd like it to be toggleable, but right now I have two separate commands.
Example:
The player enters "/gear" in chat, and their playermodel will then be adorned with all sorts of combat gear. The player then enters "/gear" again, and their playermodel is then stripped of gear.
Here's what I have right now:
[code]nut.command.add("gearon", {
syntax = "",
onRun = function(client, arguments)
client:SetBodygroup("1","2")
end
})
nut.command.add("gearoff", {
syntax = "",
onRun = function(client, arguments)
client:SetBodygroup("1","0")
end
})
[/code]
So the problem is, whenever I run the command, I get this error back:
[code]
[ERROR] gamemodes/ww3/plugins/sh_gear.lua:5: attempt to call method 'SetBodyGroup' (a nil value)
1. onRun - gamemodes/ww3/plugins/sh_gear.lua:5
2. run - gamemodes/nutscript/gamemode/core/libs/sh_command.lua:145
3. parse - gamemodes/nutscript/gamemode/core/libs/sh_command.lua:180
4. Run - gamemodes/nutscript/gamemode/core/hooks/sv_hooks.lua:248
5. unknown - gamemodes/nutscript/plugins/chatbox/sh_plugin.lua:69
6. func - gamemodes/nutscript/gamemode/core/libs/thirdparty/sh_netstream2.lua:117
7. unknown - lua/includes/extensions/net.lua:32
[/code]
I'll be honest, I have no idea what I'm doing here, I have very little knowledge or experience with Lua, let alone GMod Lua, so if anyone who could help could explain to me what's what like I'm a god damn five year old, that would be ideal. Or, you could just write the command for me and I'd learn nothing, it's up to you, beggars can't be choosers right?
Any help would be greatly appreciated, many thanks.[/QUOTE]
Make sure it's called on the server, for nutscript I would put it in your sh_commands file and it will sort all that out for you.
[url]https://github.com/Chessnut/hl2rp/blob/1.1/schema/sh_commands.lua[/url]
it is in the sh_commands file.
[QUOTE=Blazer232;51205191]it is in the sh_commands file.[/QUOTE]
What's this?
[CODE]
1. onRun - gamemodes/ww3/plugins/sh_gear.lua:5
[/CODE]
I forgot that I put it in originally as a plugin. However, in the sh_commands.lua file it returns "that command doesn't exist."
e: would you mind adding me on steam so we can chat this out?
Sure
You need to include sh_commands.lua or any other file that you add to your schema in your sv_schema.lua or sh_schema.lua.
Edit: I don't know if I'm right but when you check the wiki it says number bodygroup and value so it wouldn't be a string.
Try
[CODE]client:SetBodygroup( 1, 2 ) [/CODE]
[QUOTE=orc;51206317]You need to include sh_commands.lua or any other file that you add to your schema in your sv_schema.lua or sh_schema.lua.[/QUOTE]
what's the code for that? i can't seem to find it, but i know i've seen it before.
Dude...include
You could search in google "How to include files in gmod lua"...
i found it right after i posted that.
[QUOTE=Blazer232;51217744]i found it right after i posted that.[/QUOTE]
Been there... isn't it annoying when that happens?
Sorry, you need to Log In to post a reply to this thread.