Author Topic: Leave Message on Server that Displays to a joining Steam ID?  (Read 6416 times)

0 Members and 4 Guests are viewing this topic.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Leave Message on Server that Displays to a joining Steam ID?
« on: January 16, 2014, 03:00:25 AM »
Would it even be possible with ULX to write a script so you could set a message by STEAM ID that would display to a player next time he joins the server? For example, you see in the logs that a player has been breaking rule X, so you leave a message for him about rule X and the next time he joins, he gets the notification.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #1 on: January 16, 2014, 03:18:53 AM »
Let me try to understand this my way. You have "Mr. Player", he has the Steam ID "STEAM_0:0:87654321".
He has left the server, what you want to do is to something like: "!message STEAM_0:0:87654321 'Hey, you broke rule #1'" that will display the next time he joins the server?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #2 on: January 16, 2014, 04:49:59 AM »
Yes exactly! Or even setting it from RCON would be fine.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #3 on: January 16, 2014, 05:21:08 AM »
I made a ULX command that should work. I haven't used "PData" with strings before, but you can try and check the file I've attached.
Keep in mind it's untested, I'm in class and unable to test it atm. Just install it into addons/ulx/lua/ulx/modules/sh/ and it should load as any other ULX addon.

Here's the 'raw' code:
Code: [Select]
function ulx.setmessage( calling_ply, steamid, msg )
steamid = string.upper( steamid ) -- Steam ID needs to be uppercase.
if not ULib.isValidSteamID( steamid ) then -- *cough cough* Copied from user.lua in ULX.
ULib.tsayError( calling_ply, "Invalid steamid.", true )
return false
else
util.SetPData( steamid, "ULXSetMessage", msg )
ulx.fancyLogAdmin( calling_ply, true, "#A set a message to print for #s when the player joins.", steamid )
end
end
local setmessage = ulx.command( "Utility", "ulx setmessage", ulx.setmessage, "!setmessage" )
setmessage:addParam{ type=ULib.cmds.StringArg, hint="Player Steam ID" }
setmessage:addParam{ type=ULib.cmds.StringArg, hint="Message to print for the player" }
setmessage:defaultAccess( ULib.ACCESS_ADMIN )
setmessage:help( "Set's a message to a certain Steam ID that will print when they join." )

function SetMessagePrint( ply )
if ply:GetPData( "ULXSetMessage", 0 ) ~= 0 then -- If "ULXSetMessage" is not set to "0" (0 is default).
ply:ChatPrint( ply:GetPData( "ULXSetMessage" ) )
ply:RemovePData( "ULXSetMessage" ) -- Makes sure to remove the message after it's printed. Will only print once.
end
end
hook.Add( "PlayerInitialSpawn", "SetMessagePrint", SetMessagePrint )

Edit: Forgot to tell you something, usage: "ulx setmessage STEAM_0:0:00000000 "You broke the rules!!!!!""
Also added chat usage: "!setmessage STEAM_ID "Message""
Updated the file as well (attachment)
« Last Edit: January 17, 2014, 06:37:39 AM by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #4 on: January 16, 2014, 11:10:17 AM »
Good timing, I am currently making a whole server mail addon that I will probably post here, and you can do exactly what you need with it.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #5 on: January 16, 2014, 11:11:30 AM »
Good timing, I am currently making a whole server mail addon that I will probably post here, and you can do exactly what you need with it.
Server mail? You mean emailing through the server almost like a form?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #6 on: January 16, 2014, 02:15:11 PM »
Hmm. I put it in the folder you said to but I an getting this error when I use the ulx setmessage, etc command:

17:10:07 [ERROR] addons/ulib/lua/ulib/shared/commands.lua:890: attempt to index field 'type' (a nil value)
           1. __fn - addons/ulib/lua/ulib/shared/commands.lua:890
            2. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
             3. unknown - lua/includes/modules/concommand.lua:69
         
         
         
         [ERROR] addons/ulib/lua/ulib/shared/commands.lua:890: attempt to index field 'type' (a nil value)
           1. __fn - addons/ulib/lua/ulib/shared/commands.lua:890
            2. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
             3. unknown - lua/includes/modules/concommand.lua:69

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #7 on: January 16, 2014, 03:24:02 PM »
Server mail? You mean emailing through the server almost like a form?
Yeah pretty much. Send messages to online and offline players, etc. Will post soon, it's almost finished.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #8 on: January 16, 2014, 03:32:04 PM »
Hmm. I put it in the folder you said to but I an getting this error when I use the ulx setmessage, etc command:

17:10:07 [ERROR] addons/ulib/lua/ulib/shared/commands.lua:890: attempt to index field 'type' (a nil value)
           1. __fn - addons/ulib/lua/ulib/shared/commands.lua:890
            2. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
             3. unknown - lua/includes/modules/concommand.lua:69
         
         
         
         [ERROR] addons/ulib/lua/ulib/shared/commands.lua:890: attempt to index field 'type' (a nil value)
           1. __fn - addons/ulib/lua/ulib/shared/commands.lua:890
            2. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
             3. unknown - lua/includes/modules/concommand.lua:69
Hmmm... not sure what could be causing this. If someone else doesn't help you, I'll test it/attempt to fix it tomorrow after school (on my phone atm).

Yeah pretty much. Send messages to online and offline players, etc. Will post soon, it's almost finished.
I didn't know that was even possible. Sounds awesome
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #9 on: January 17, 2014, 06:41:28 AM »
Alright, I fixed the first error, it was a mistake on my end. I've edited the code for that error to not show.
However, I'm having an issue with util.SetPData. I don't know if it's my server, or if it's something else, but apparently that is "a nil value". So for any "GLua professionals", please help me.
« Last Edit: January 17, 2014, 06:43:14 AM by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #10 on: January 17, 2014, 04:59:37 PM »
Alright, I fixed the first error, it was a mistake on my end. I've edited the code for that error to not show.
However, I'm having an issue with util.SetPData. I don't know if it's my server, or if it's something else, but apparently that is "a nil value". So for any "GLua professionals", please help me.

What is the problem exactly?
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #11 on: January 17, 2014, 10:24:53 PM »
What is the problem exactly?
It doesn't save the data at all and errors me out.
I tried making a simple test script where the Steam ID and message were already fixed (static), it still errored me out.
The code is pretty much what I put above.

The error:
Code: [Select]
attempt to call field 'SetPData' (a nil value)
« Last Edit: January 18, 2014, 01:53:48 AM by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #12 on: January 18, 2014, 06:30:57 AM »
Are you calling module() in the file where you're using SetPData?
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #13 on: January 18, 2014, 08:02:44 AM »
Are you calling module() in the file where you're using SetPData?
I didn't know that was necessary.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Leave Message on Server that Displays to a joining Steam ID?
« Reply #14 on: January 18, 2014, 03:17:09 PM »
No, it's not. I was just trying to get an idea of what may be wrong.
Experiencing God's grace one day at a time.