• coding my first addon
    24 replies, posted
hello so i am trying to make a addon that prints a welcome message when u join the server but... i have no clue how and when i cant find out how to do something i just quit and i never learn.. so instead of just quitting ill see if any one can help me? i know how to code and use hooks and functions but when i hit a wall such as not knowing what file i should code in or what keywords to use i just give up idk how to keep my self from stopping the second i hit a wall. so i was thinking if any one has the same problem how do they got past it and make the addons of their dreams? lol and how can i make this welcome message addon?
[url]http://wiki.garrysmod.com/page/Main_Page[/url]
and giving me a link helps how.
[QUOTE=TrippleT;46100011]and giving me a link helps how.[/QUOTE] Here's the hooks/functions you'll need: [url]http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn[/url] [url]http://wiki.garrysmod.com/page/Player/PrintMessage[/url] or [url]http://wiki.garrysmod.com/page/chat/AddText[/url] with [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
thank you [editline]28th September 2014[/editline] GM:PlayerInitialSpawn(ply) keeps saying the same error that i tryed to make gm a nill value? [editline]28th September 2014[/editline] ok so i got it with no errors but nothing happens when i join the server? int file [CODE]AddCSLuaFile( "cl_init.lua" ) function GAMEMODE:PlayerInitialSpawn( ply ) umsg.Start("welsome", ply) umsg.End() end [/CODE] cl_init [CODE] function _wmsg() local ply = LocalPlayer() chat.AddText(Color(255, 0, 0), "[ADMIN] ", Color(255, 255, 255), "Welcome to the server ", ply) end usermessage.Hook("welcome", _wmsg) [/CODE]
umsg.Start("welsome", ply) and usermessage.Hook("welcome", _wmsg) They're spelled differently.
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html[/url] [lua] function FirstSpawn( ply ) ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!") end hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn ) [/lua] or even [url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0d60.html[/url] [lua] function GM:PlayerConnect( name, address ) print( "Player " .. name .. " has joined from ip " .. address ) end [/lua]
[QUOTE=CertifiedCode;46102196] print( "Player " .. name .. " has joined from ip " .. address ) [/lua][/QUOTE] address is not a real thing, [lua]IPAddress()[/lua] Nor, in name... [lua]Name --or use Nick [/lua] You're using [lua] print --It should be PrintMessage --or v:ChatPrint [/lua]
yep i just got that as an example from wiki.
[CODE] hook.Add( "PlayerInitialSpawn", "MessageOnJoin", function( ply ) ply:ChatPrint( "Welcome to the server!" ) end ) [/CODE] put this in lua/autorun/server/somefilename.lua
[editline]edit[/editline] Ninja'd... on second thought, I was just blind.
I THINK i was drunk or very sleepy when i posted this lol
[QUOTE=CertifiedCode;46102837]ACTUALLY U KNOW WHAT instead of giving him the whole frieken code so he does not learn why not just give him a source with information about it... [editline]29th September 2014[/editline] he will never learn and u just did his whole addon.. so he didn't make it. [editline]29th September 2014[/editline] i even did it myself for him..[/QUOTE] You need sleep. Or help.
And you're contributing how Certified? OP, when creating things do not overwrite gamemode functions (doing GAMEMODE:PlayerInitialSpawn() for example), instead use hook.Add. It will be called when the hook is called and won't overwrite any special functions that need to occur. So for example [lua]hook.Add("PlayerInitialSpawn", "example", function(ply) ply:ChatPrint("TEST"); end); [/lua] Works just as well as... [lua]function TestFunction(ply) end hook.Add("PlayerInitialSpawn", "example", TestFunction) [/lua] It all depends on your coding style.
Oops i do need sleep i never even knew i sent that... im going to get some sleep
Could also use a net message and send the message clientside with chat.AddText for better formatting.
Just to clarify for OP, networking is when you use [lua]net.Start("uniquename")[/lua] And [lua]net.Send(player) -- Sends to one player[/lua] slash [lua]net.Broadcast() -- Sends to everyone[/lua] Then, to receive it (like a hook, it's called when you call the send! Does this seem to be all relying on calling and receiving yet?) you use this [lua]net.Receive("sameuniquename_asnetstart", function(len, CLIENT) -- do stuff here end);[/lua] Then, to make sure it networks properly in a server file do [lua]util.AddNetworkString("againsamename")[/lua] And that's how you would do something clientside that happened serverside! Not the best explanation or examples, but I hope you get the point. Most of Gmod Lua coding is done through a series of events that you create reactions to, for example putting in chat "Nookyava has joined the server!" when I am authenticated or "Nookyava has rekt Bot01" when I kill another plyaer. My suggestion is this: Take the time to jot down some ideas you think you can do (although make sure it has features you are not sure how to do, push yourself! The harder it is and longer it takes, the better it feels when you get it working!) But don't make it too difficult. For example don't strive to make a full fledged gamemode right off the bat, start off instead with a simple addon that makes you fly really high when you use voice chat. If you do this and push yourself you'll know what to do next time and you increase your knowledge (as well as chances of remembering since you spent so much time) Apologies for the huge post!
[code] //we create a function. hook.Add ( "PlayerInitialSpawn", function ( ply ) // we print a message in the chat, "words"..hisname.."words" ply:ChatPrint( "Welcome"..ply:Nick().."and have a great time!" ) //Now, let's add a sound to it. //we send him the usermessage umsg.Start ( "BEEP", ply ) umsg.End end ) //cl_init.lua //We recieve whatvwe send, usermessage.Hook ("nameofusermessage", function () end) usermessage.Hook ( "BEEP", function ( um ) //we play the sound, can be anything, defaulded in Gmod or a custom one - make sure you have the correct path to the sound! surface.PlaySound ( "path/to/sound" ) end ) [/code] I'm on my phone so it might not work.. hope it helped!
omg thank you so much every one!!! [editline]29th September 2014[/editline] [QUOTE=robbert^^;46103799][code] //we create a function. hook.Add ( "PlayerInitialSpawn", function ( ply ) // we print a message in the chat, "words"..hisname.."words" ply:ChatPrint( "Welcome"..ply:Nick().."and have a great time!" ) //Now, let's add a sound to it. //we send him the usermessage umsg.Start ( "BEEP", ply ) umsg.End end ) //cl_init.lua //We recieve whatvwe send, usermessage.Hook ("nameofusermessage", function () end) usermessage.Hook ( "BEEP", function ( um ) //we play the sound, can be anything, defaulded in Gmod or a custom one - make sure you have the correct path to the sound! surface.PlaySound ( "path/to/sound" ) end ) [/code] I'm on my phone so it might not work.. hope it helped![/QUOTE] thank you, on the path to the sound or any path to anything what is the start folder? i see people with just addon/file.mp3 or randomfolder/model.mdl? some times i don't know where to place things
i keep trying everything every one has said and nothing works.
Show some code. Where are you putting it, what errors (if any)?
no errors and i keep trying many different things and im putting my .lua in the autorun/server [CODE]hook.Add( "PlayerInitialSpawn", "MessageOnJoin", function( ply ) ply:ChatPrint( "Welcome to the server!" ) end ) [/CODE] [editline]30th September 2014[/editline] i am also running this on a sandbox server just for testing
Pretty certain PIS is called when the user is still on the loading screen
You could use timer.Simple to delay it for example.
[CODE]timer.Simple(10, hook.Add( "PlayerInitialSpawn", "MessageOnJoin", function( ply ) ply:ChatPrint( "Welcome to the server!" ) end ))[/CODE] i tryed this and still nothing and [CODE]hook.Add( "PlayerInitialSpawn", "MessageOnJoin", function( ply ) timer.Simple(10, function() ply:ChatPrint( "Welcome to the server!" ) end) end )[/CODE]
Sorry, you need to Log In to post a reply to this thread.