• RP Command help.
    5 replies, posted
Hi, My name is PIXX and I am trying to make a addon that adds a salute command, or rather, makes it easier to salute, I am using DarkRP on a server, that is why it uses "/me" (if you wondered). If you can help me, please, I would be so thankful! init: [code] AddCSLuaFile("pixx/server/server.lua") include("pixx/server/server.lua") AddCSLuaFile("client/client.lua") include("client/client.lua") concommand.Add( "pixx_commands") local version = "1.6.2" print( "Thanks for using PIXX Commands! Version: " ..version ) end function SaluteCommand( pl, text, teamonly ) if (text == "/salute") then RunConsoleCommand("say test") end end return TRUE end hook.Add( "PlayerSay", "Chat", SaluteCommand ) [/code] (It returns: <eof> at line 18) I would think the same thing happens in server.lua and client.lua Server.lua: [code] include("pixx/client/client.lua") concommand.Add( "pixx_commands") local version = "1.6.2" print( "Thanks for using PIXX Commands! Version: " ..version ) end function SaluteCommand( pl, text, teamonly ) if (text == "/salute") then RunConsoleCommand("say test") end end return TRUE end hook.Add( "PlayerSay", "Chat", SaluteCommand ) [/code] Client.lua: [code] include("pixx/server/server.lua") concommand.Add( "pixx_commands") local version = "1.6.2" print( "Thanks for using PIXX Commands! Version: " ..version ) end function SaluteCommand( pl, text, teamonly ) if (text == "/salute") then RunConsoleCommand("say test") end end return TRUE end hook.Add( "PlayerSay", "Chat", SaluteCommand ) [/code] -------------- If you could help me, please comment something!
Use code tags or pastebin, nobody wants to read that :/
PlayerSay hook is a serversided hook. Also why init? Shouldn't scripts that aren't sents start with sh_(shared) cl_(clientside) It's not like I like to do it all in one file using if SERVER or CLIENT statements anyways, makes stuff faster for me, but the script is harder to read. [code]hook.Add("PlayerSay","Komenda",function(send,text,teamchat) if send:IsSuperAdmin() and string.Left(text,8) == "/advert " then text = string.TrimLeft(text,"/advert ") text = string.Explode("/n",text) if #text>4 then for i=5,#text do text[i] = nil end end net.Start("Advert") net.WriteTable(text) net.Broadcast() file.Write("advert.txt",util.TableToJSON(text)) return false elseif send:IsSuperAdmin() and text == "/removeadvert" then if file.Exists("advert.txt","DATA") then file.Delete("advert.txt") net.Start("Com") net.WriteString(send:Nick()) net.Broadcast() else net.Start("Com") net.WriteString("") net.Send(send) end return false elseif text == "!forum" then net.Start("Com") net.WriteString("r4urlopen") net.Send(send) end end)[/code] That's my code for my advert display, everything is done on server side and ofc the data is sent to the client only once, at Preinitialization. All checks are on server side to improve security (I wouldn't like anyone to change the advert, just the superadmins) The table contains up to 3 lines of text, it explodes the strings at /n into the new line. !forum commands send an user message to the client that it should open my URL, network message "Com" is used to give either notifications to the chat or pass the admins name. If I pass blank string, it will tell the user that there was an error removing advert, if I pass someone's name, then it will display it like [NOTIFY] Admin <name> removed the advert, and if I pass "r4urlopen" then it will open my URL on the client executing the !forum command (I know it could be done WAY WAY better [Think what if admin names himself "r4urlopen"] - It would open the web for him anyways) but it works, I saved up on code lenght and resources and I am happy with it. What I am trying to say - You need to communicate on both server and client, server receives the command, who sent it and exectra, then it broadcasts the message to whole server that the client executing the command should do an animation on his playermodel. In the current state, you're not telling the script to execute anything on serverside, clientside or shared. It is just as it is - Server tries to run it on both clientside and serverside. Add IF statements around the code like if SERVER then --code end to tell the script to execute the code clientside or serverside - Eventually, add those pesky sh_, sv_ or cl_ prefixes to the filename, it might be the best option for you.
[QUOTE=John Reese;50279922]Use code tags or pastebin, nobody wants to read that :/[/QUOTE] sorry, I am new to this :_: [editline]9th May 2016[/editline] [QUOTE=RaKo;50286515]PlayerSay hook is a serversided hook. Also why init? Shouldn't scripts that aren't sents start with sh_(shared) cl_(clientside) It's not like I like to do it all in one file using if SERVER or CLIENT statements anyways, makes stuff faster for me, but the script is harder to read. [code]hook.Add("PlayerSay","Komenda",function(send,text,teamchat) if send:IsSuperAdmin() and string.Left(text,8) == "/advert " then text = string.TrimLeft(text,"/advert ") text = string.Explode("/n",text) if #text>4 then for i=5,#text do text[i] = nil end end net.Start("Advert") net.WriteTable(text) net.Broadcast() file.Write("advert.txt",util.TableToJSON(text)) return false elseif send:IsSuperAdmin() and text == "/removeadvert" then if file.Exists("advert.txt","DATA") then file.Delete("advert.txt") net.Start("Com") net.WriteString(send:Nick()) net.Broadcast() else net.Start("Com") net.WriteString("") net.Send(send) end return false elseif text == "!forum" then net.Start("Com") net.WriteString("r4urlopen") net.Send(send) end end)[/code] That's my code for my advert display, everything is done on server side and ofc the data is sent to the client only once, at Preinitialization. All checks are on server side to improve security (I wouldn't like anyone to change the advert, just the superadmins) The table contains up to 3 lines of text, it explodes the strings at /n into the new line. !forum commands send an user message to the client that it should open my URL, network message "Com" is used to give either notifications to the chat or pass the admins name. If I pass blank string, it will tell the user that there was an error removing advert, if I pass someone's name, then it will display it like [NOTIFY] Admin <name> removed the advert, and if I pass "r4urlopen" then it will open my URL on the client executing the !forum command (I know it could be done WAY WAY better [Think what if admin names himself "r4urlopen"] - It would open the web for him anyways) but it works, I saved up on code lenght and resources and I am happy with it. What I am trying to say - You need to communicate on both server and client, server receives the command, who sent it and exectra, then it broadcasts the message to whole server that the client executing the command should do an animation on his playermodel. In the current state, you're not telling the script to execute anything on serverside, clientside or shared. It is just as it is - Server tries to run it on both clientside and serverside. Add IF statements around the code like if SERVER then --code end to tell the script to execute the code clientside or serverside - Eventually, add those pesky sh_, sv_ or cl_ prefixes to the filename, it might be the best option for you.[/QUOTE] I am really new to coding... I just made this for fun. But thanks for telling me :D. So, it should be like this sh_salute.lua [code] function SaluteCommand( pl, text, teamonly ) if (text == "/salute") then RunConsoleCommand("say test") PrintMessage( HUD_PRINTTALK, ply:GetNick().. " salutes his higher ups" ) end end return TRUE end hook.Add( "PlayerSay", "Chat", SaluteCommand ) [/code] init.lua: [code] AddCSLuaFile("server/sh_salute.lua") include("server/sh_salute.lua") [/code] And a script in cl_salute.lua that says: "I am the player who saluted" and sends it to the server? Plz reply :D - PIXX out (for now)
true not TRUE
[QUOTE=Invule;50287172]true not TRUE[/QUOTE] Of course... :I
Sorry, you need to Log In to post a reply to this thread.