Certain functions in fretta's init.lua run both clientside and serverside. Is there a way of performing different logic for the client and the server when that event occurs?
The one in particular I'm curious about is GM:KeyPress
[lua]
function GM:KeyPress()
if CLIENT then
print"CLIENT"
else -- if SERVER then
print"SERVER"
end
end[/lua]
This works because in the server lua the variable CLIENT is not defined therefore it will return false, and vice versa.
If it's in "gamemodes/fretta13/gamemode/init.lua" then it's serverside. The init file is purely serverside (sv_init would be a better name, but gmod searches for init.lua as the serverside load file)
If it truly is a shared file you're working with (usually shared.lua or sh_init.lua, or some fucked up person who did make init.lua shared even though they shouldn't ever do that) then as Ozy said, that's the best way to make a shared file run. Though the following would be better:
[lua]function GM:KeyPress(player,iKey)
if SERVER then --Serverside only code. Runs only on the server.
print("[SV]"..player:Nick().." pressed key index "..iKey)
elseif CLIENT then --Clientside only code. Runs on the client.
print("[CL]"..player:Nick().." pressed key index "..iKey)
else --Shared code, runs both client and serverside.
print("[SH]"..player:Nick().." pressed key index "..iKey)
end
end[/lua]
It would appear that this didn't fix my issue, anyway. The command is only being run serverside, so I have the same problem I initially had, thanks.
[QUOTE=hubbazoot;42805509]It would appear that this didn't fix my issue, anyway. The command is only being run serverside, so I have the same problem I initially had, thanks.[/QUOTE]
Are you sure you're running the code on both domains?
It would appear the code is NOT running on both domains.
Ultimately, I'm trying to get a prop so it will rotate with the player it's parented with (kinda like hats do, but only rotating around one axis) and I'm having trouble getting the rotation to be triggerable at all. My latest attempts have the prop rotating (relative to the camera) on the player's view, as well as the server's view, which is not what I want. I want the prop to stay facing towards the camera on the player's view, but to rotate with the player on the server's view.
Sorry, you need to Log In to post a reply to this thread.