• Print

Author Topic: "Player Spawned" Message  (Read 6511 times)

0 Members and 1 Guest are viewing this topic.

Offline ThatBum

  • Newbie
  • *
  • Posts: 14
  • Karma: 2
"Player Spawned" Message
« on: June 11, 2011, 09:07:54 pm »
Greetings. I just removed Evolve and put ULX up on my server. I got tired of Evolve's instability and lack of development. Still, I miss some of Evolve's features. I miss the nametags, chat indicator, and AFK indicator, but the first two sorted out already. What I would like to have back is the "player spawned" message in chat. It may not seem like much, but it's the little things, you know? It's nice to see if a player connected stuck around long enough to come in game. It would also be cool to integrate it with Utime, for last joined time. I know Utime already does this, but from what I observed, it only does it for the spawned player. It would probably be trivial to change this, but sadly I am not a programmer and know nothing of Lua. I would put this in the Utime topic, but I got the old topic warning and didn't want to get a bad start. Thanks!

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: "Player Spawned" Message
« Reply #1 on: June 12, 2011, 01:54:33 am »
Hi and welcome to the forums. Do you at least know how to edit a lua file?

Go into utime/lua/autorun/sv_utime.lua and find this block of code...

Code: Lua
  1. function onJoin( ply )
  2.         local uid = ply:UniqueID()
  3.         local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" )
  4.         local time = 0
  5.        
  6.         if row then
  7.                 ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
  8.                 sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";" )
  9.                 time = row.totaltime
  10.         else
  11.                 ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" )
  12.                 sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );" )
  13.         end
  14.         ply:SetUTime( time )
  15.         ply:SetUTimeStart( CurTime() )
  16. end
  17. hook.Add( "PlayerInitialSpawn", "UTimeInitialSpawn", onJoin )
  18.  

replace with...

Code: Lua
  1. function onJoin( ply )
  2.         local uid = ply:UniqueID()
  3.         local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" )
  4.         local time = 0
  5.        
  6.         if row then
  7.                 ULib.tsay( _, "[UTime]We welcome back " .. ply:Nick() .. ", last played on this server " .. os.date( "%c", row.lastvisit ) )
  8.                 sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";" )
  9.                 time = row.totaltime
  10.         else
  11.                 ULib.tsay( _, "[UTime]Welcomes" .. ply:Nick().. " to our server for the first time!" )
  12.                 sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );" )
  13.         end
  14.         ply:SetUTime( time )
  15.         ply:SetUTimeStart( CurTime() )
  16. end
  17. hook.Add( "PlayerInitialSpawn", "UTimeInitialSpawn", onJoin )
  18.  




That will do exactly what you requested. It will announce to the server whenever a player spawns for the first time with their UTime data. I assume you didn't want it to show every time they respawn and only the first spawn right?
« Last Edit: June 12, 2011, 01:59:09 am by MrPresident »

Offline ThatBum

  • Newbie
  • *
  • Posts: 14
  • Karma: 2
Re: "Player Spawned" Message
« Reply #2 on: June 12, 2011, 02:22:42 am »
I do know some stuff, I know TI-BASIC, bash scripting from Linux, and some HTML. Also, that's about right, thanks. Though, as it's visible to all users, it would sound better to not address the player. I can just edit the message in there, bu i would like to have the dynamic Nick field first. I guess I cam just do something like

Code: [Select]
if row then
ULib.tsay( ply, "" .. ply:Nick() .. " has spawned, last joined " .. os.date( "%c", row.lastvisit ) )
sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";" )
time = row.totaltime
else
ULib.tsay( ply, "" .. ply:Nick() .. " has spawned for the first time." )
sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );" )

But this seems kind of hacky.

Also, off-topic, but to you know the name of the nametag addon where you can make a sub-text below your name?I saw it running in quite a few servers, and I want it on mine, but I don't know the name.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: "Player Spawned" Message
« Reply #3 on: June 12, 2011, 02:28:55 am »
/index.php/topic,4799.0.html



also in my example you aren't addressing the player.
Lets assume a player named John joins..


"[UTime]We welcome back John, last played on this server June 11th, 2011"

or

"[UTime]Welcomes John to our server for the first time"

Offline ThatBum

  • Newbie
  • *
  • Posts: 14
  • Karma: 2
Re: "Player Spawned" Message
« Reply #4 on: June 12, 2011, 02:48:47 am »
Thanks very much! I've been hunting for that for awhile now.

Also that's kind of hokey, I like the anonymous take on mine.

  • Print