• Print

Author Topic: Collection popup and command  (Read 9961 times)

0 Members and 1 Guest are viewing this topic.

Offline stanhelman

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Collection popup and command
« on: March 24, 2016, 05:24:19 pm »
I created a lua script that automatically opens the collection page by opening it up in steam overlay after 20 seconds of spawning I also added the !collection command to the script as well

the script is as follows feel free to modifying  it like adding stuff and removing stuff as needed

Code: Lua
  1. function PlayerInitialSpawn( ply )
  2. end
  3.  
  4. local function spawn( ply )
  5.     if ply:IsAdmin() or ply:IsUserGroup( "regular" ) or ply:IsUserGroup( "respected" ) or ply:IsUserGroup( "sit" )  or ply:IsUserGroup( "moderator" ) then return end
  6.        timer.Simple( 19, function() print( "The collection will load in 1 second" ) end )
  7.        timer.Simple( 20, function() ply:SendLua([[gui.OpenURL("Your Collection URL")]]) end )
  8. end
  9. hook.Add( "PlayerInitialSpawn", "collection", spawn )
  10.  
  11. local function CollectionCommand( pl, text, teamonly )
  12.                     if (text == "!collection") then
  13.                             pl:SendLua([[gui.OpenURL("Your Collection URL")]]) -- Change ADDRESS to your chosen page.
  14.                             for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has considered getting the addons so he/she can see everything!" )
  15.  
  16.                 end
  17.         end
  18. end
  19. hook.Add( "PlayerSay", "Collection", CollectionCommand )


Script goes into lua/autorun/server
« Last Edit: March 25, 2016, 11:52:11 am by stanhelman »

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Collection popup and command
« Reply #1 on: March 24, 2016, 09:38:26 pm »
Pretty good work, but I feel like I should drop these tips:
  • Check your indentation. It looks like you're using spaces for indents... but they look hand-typed. If you're using any modern editor (Notepad++, Sublime Text...), pressing Tab should insert (and sustain) a constant indentation level, and adjust it correctly. For example, typing an if-statement and pressing enter will shift the indent in one line, and typing "end' to close it should shift it back, assuming you're using Lua syntax. Right now, your indentation is all over the place, and it makes things harder to read for smaller monitors.
  • Try and make things more configurable. Right now, your code is written for a very specific use case, in which "regular," "respected," "sit," "moderator," and any group above "admin" shouldn't see the collection on spawn. But what if a server doesn't conform to a rank structure like that?
    For this, I propose, at the very least, a table containing all groups that shouldn't be shown the collection, and run a linear search over that for the player's current user group. If the group is there in that table, do nothing, else show the collection. Alternatively, and probably the better option, is to set some sort of ULib permission that, if granted to a group, will grant them immunity form seeing the collection on spawn (this has the added benefit of inheritance).
  • Try and make things less sudden. So, I join a server with this on, and suddenly, about 19 seconds after I spawn, I see this little chat message. SOmething about a collec—woah what's this window? Is this a virus? What's happening?!
    It's just a little spontaneous, that window opening. There's a very short interval between it warning a user about it opening and it actually opening. Maybe, instead of a chat message and auto-opening it, set a dialog box up to open on spawn prompting the user to check out the collection?
  • Returning users not in the immune groups will still see the collection. For that, you could use some sort of persistent player data (ie sqlite) to remember the player's decision to view the collection details. Perhaps you could have a command to reset this data if you make an important change to the collection, too.
  • (pet peeve) Your hook names aren't that unique. Hook names should be distinct and hard to accidentally override, so you won't have to worry about a careless addon developer overriding one of your hooks. Instead of "collection," try something like "[addon name]_[event name]_[short hook description]" (eg "pp2_ttt_killer_stats_PlayerDeath_show_info," or something to that degree). That example may be a little extreme, but just try to go for something a little more specific than "colection."
  • Since you seem to be relying on UL(X|ib){1} already, use ULX to register your command. It just makes things so much easier, especially with PlayerSay, which can screw things up royally if someone handles it sloppily.
« Last Edit: March 24, 2016, 09:42:09 pm by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline stanhelman

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Collection popup and command
« Reply #2 on: March 25, 2016, 11:20:27 am »
Check your indentation.
I will do that as soon as I can I was using another pc at the time and notepad really annoys me with its indentions I like notepad++ better

Try and make things more configurable.
This is very true and I will be working on it  and I like the ulib idea only problem is idk how to do it yet still learning

Try and make things less sudden.

As for this I believe I should have it do the message 40 seconds after spawn and 20 seconds after the message popup receive the collection link

Returning users not in the immune groups will still see the collection

Working on it

Your hook names aren't that unique

They will be soon as I am able

Since you seem to be relying on UL(X|ib){1} already, use ULX to register your command.

This is a Work in Progress

So pretty much the finished product will show up later as for the current script you can fool around with yourself and use it as a temp means to get guests to see your collection

This script is still a Work In Progress

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Collection popup and command
« Reply #3 on: March 25, 2016, 03:01:55 pm »
@Bytewave, I didn't see any ULib specific code, so didn't suggest this -

Stanhelman, however, if you're going to make it rely on ULib, you're going to want to add checks or place it in a better file path to ensure ULib is loaded.
As it stands now though, it should run on any server, ULib or not.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline stanhelman

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Collection popup and command
« Reply #4 on: March 25, 2016, 04:28:34 pm »
yes the way I first set it up it didnt use ulib at all but thats going to change I made this post now but I think I should of waited until I was done

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Collection popup and command
« Reply #5 on: April 01, 2016, 01:20:14 am »
It would be a waste of time to make it a "ulx" command. Just leave it as is.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Collection popup and command
« Reply #6 on: April 01, 2016, 03:32:10 pm »
It would be a waste of time to make it a "ulx" command. Just leave it as is.
I wouldn't say waste of time.
Unneeded, for what it does, perhaps. But definitely not wasteful.
If I'd never used ULib API before, starting with ways to incorporate ULib functionality into 'small' items like this are a good start of learning.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print