Removing GM: from gamemode functions.

Trying to get rid of GM: from a gamemode but keep gives me “attempted to call method”.
Any idea what is the problem?


function SetupCoolDownWeapon(wep)
	if not wep.WElements and not wep.VElements then
		wep.DrawWorldModel = CDDrawWorldModel
		wep.DrawWorldModelTranslucent = wep.DrawWorldModel
		wep.GetViewModelPosition = CDGetViewModelPosition
	end
end


Why would you want to remove GM: from a gamemode?

Trying to make a separated script.

Why dont you just hook to gamemode functions?

I don’t like using hooks

Just add the GM? It’s not gonna bomb your house or anything.

What’s the exact error? You can use non GM: functions, and I do that for some of my core functions, such as a recoded print function which prints useful information ( Neater custom print table implementation, prints damage information, prints vectors as Vector( … ), angles as Angle( … ), colors as Color( … ), and more – feed it something and it’ll print it).

GM: functions are incredibly useful, because they can be called using hooks. You may not like them, but they are very useful.

hook.Call( “MyGMFunctionName”, GAMEMODE, arg1, arg2, arg3 )

Hooks can be used to broadcast events, which anything can hook into which is incredibly robust for creating things which others can “hook” into and add logic to.

I made some such as “PlayerFullyConnected” which gets called on both the client, and the server when a player fully connects. It enables me to do base logic in the GM:PlayerFullyConnected function, in addition to using hook.Add( “PlayerFullyConnected”, “SomethingElse”, function( ) … end ) if someone wanted to expand my logic, or if I wanted to create an addon which checks something when the player fully connects.

An example of that, is that I made an addon that compares server-side addons to client-side addons when the player fully connects.

I’d really recommend looking into using hooks at specific locations in your code because it makes managing your code a whole lot easier, as well as allowing yourself or others to expand upon your original idea.

“attempted to call method (a nil value)”

[editline]27th May 2013[/editline]

Still gives me error when trying to use “GM:” function or non “GM:” function.T

Can you post the exact code, ie where you’re defining it and how you’re calling it?

Is it a client side function, serverside, or shared? Are you AddCSLua if it’s client or shared? Is the file being included?

GOOD LUCK.

I already posted the code on original post.
It’s running on serverside, and it is included.

GM is used when the gamemode loads.
GAMEMODE is used after the gamemode has loaded.

Therefor you can’t edit the script in “realtime”. You need to restart the gamemode every time you edit it.

This tells us nothing about your GM: problem:


function SetupCoolDownWeapon(wep)
	if not wep.WElements and not wep.VElements then
		wep.DrawWorldModel = CDDrawWorldModel
		wep.DrawWorldModelTranslucent = wep.DrawWorldModel
		wep.GetViewModelPosition = CDGetViewModelPosition
	end
end

If you wan’t us to help you;

  • What is the full script?
  • What are you trying to do?
  • What GM-function are you trying to change?

I agree with everything said by Nak, except autorefresh does support function GM:… changes, if and only if they are placed correctly.

So if you have a server-side only GM function you’re editing, but you make it loaded as a shared file, you will have to restart your game-mode in order for the changes to show ( on official functions ). If you’re creating your own, place them wherever and autorefresh will pick up the changes. My dev-playground fully supports autorefresh, and I use GM functions for most of the stuff that I add in aside from core functions.

That function alone shouldn’t give you the error. We’d need to see the entire code, where it’s being called, etc etc…

I am just trying to change gamemode function into standard function so I can use it without the gamemode.
The function itself is for SWeps.

You’re getting errors because Garry assumes the GM table is there and trying to call functions in it. Because that’s the way he designed his game.

Your question is like:

“Trying to get rid of the sun from our solar system but keep getting cold. Any idea what is the problem?”

If this is some syntactic sugar problem because you don’t like seeing GM: you can do this:

[lua]

local void = function() end

_G.GM = setmetatable(
{},
{
__index = function(self, key)
return _G[key] or void
end
}
)

[/lua]

And it will attempt to call globals instead. Doing weird things like this will make it harder for people to help you out so it’s not recommended.

You could also use the setfenv function, you’d need to add the self argument for every function though.

This whole thread is dumb though, OP could just use what is there already.

You need to give more context for what you are trying to do. There is nothing special about gamemode functions other than the fact that certain function names get called by the engine and the hook library. ‘SetupCoolDownWeapon’ is not a known gamemode hook, so we can only assume that this is a normal function that is called by some other function. Not knowing anything about the function that is supposed to call this prevents us from helping you.