General > Developers Corner

Leave Message on Server that Displays to a joining Steam ID?

(1/4) > >>

Storm:
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.

Decicus:
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?

Storm:
Yes exactly! Or even setting it from RCON would be fine.

Decicus:
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: ---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 )

--- End code ---

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)

Cobalt:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version