• Print

Author Topic: Assistance needed |Prophunt|  (Read 7690 times)

0 Members and 1 Guest are viewing this topic.

Offline Dillan Clair

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Assistance needed |Prophunt|
« on: February 19, 2016, 07:12:12 am »
Hellos everyone, im trying to constantly track player scores for the Hunter team, in order so that those with the highest score each round will get a certain 'perk' so to speak, I know in order to do this I need to store the scores in a table and track them with a hook, but I have no idea how to do this, would some of you be kind enough to provide and example perhaps?
(The scores would be tracked every round aside from the first)
Thank you in advance!!


Edit: I always get this shred of disappointment where I see you guys view, but yet no comments..
« Last Edit: February 19, 2016, 11:32:26 am by Dillan Clair »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Assistance needed |Prophunt|
« Reply #1 on: February 19, 2016, 02:45:16 pm »
Edit: I always get this shred of disappointment where I see you guys view, but yet no comments..

Probably because you come to the ULX forums and ask about PropHunt. Most of us here probably have never even played PropHunt and therefor wouldn't be able to help you even if we wanted to.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Assistance needed |Prophunt|
« Reply #2 on: February 22, 2016, 04:39:01 am »
Probably because you come to the ULX forums and ask about PropHunt. Most of us here probably have never even played PropHunt and therefor wouldn't be able to help you even if we wanted to.

Savage. I want to laugh...

Offline Dillan Clair

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Assistance needed |Prophunt|
« Reply #3 on: February 22, 2016, 06:14:46 am »
I mean, considering this is distinctly labeled 'off topic'
usuallt would make me assume that it doesnt mean it has to do with ulx, pardon if that isnt necessarily the case

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Assistance needed |Prophunt|
« Reply #4 on: February 22, 2016, 07:45:09 am »
I mean, considering this is distinctly labeled 'off topic'
usuallt would make me assume that it doesnt mean it has to do with ulx, pardon if that isnt necessarily the case

Mr. President isn't saying you're posting in the wrong section; he's just saying that because your request has nothing to do with ULX/ULib you're unlikely to find help here, the forums for Ulysses Projects. If you want help with prophunt, you'll have better lcuk if you ask the creator of the PropHunt addon or go to facepunch.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Assistance needed |Prophunt|
« Reply #5 on: February 22, 2016, 07:45:55 am »
It doesn't have to be, you are right, but your audience is limited. I was just answering your question as to why you keep seeing people read but not reply to your post.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Assistance needed |Prophunt|
« Reply #6 on: February 23, 2016, 07:44:04 am »
Lightly documented example below:

Code: Lua
  1. -- Create a table "scores" that will store the amount of kills each hunter has.
  2. local scores = {}
  3.  
  4. -- Every time a hunter kills someone, we increase their score by 1.
  5. hook.Add( "PlayerDeath", "UpdateScore", function( victim, inflictor, attacker )
  6.     if attacker:Team() == TEAM_HUNTERS then
  7.         local steamid = attacker:SteamID()
  8.         scores[steamid] = (scores[steamid] or 0) + 1
  9.     end
  10. end )
  11.  
  12. -- Determine best hunter and reward them. Reset scores.
  13. hook.Add( "RoundOver", "RewardBestHunter", function()
  14.     local winningScore = 0 -- The highest score.
  15.     local winners = {} -- Allow for multiple winners in case of a tie.
  16.    
  17.     for steamid, score in pairs( scores ) do
  18.         local v = player.GetBySteamID( steamid )
  19.  
  20.         if v then
  21.             if score > winningScore then
  22.                 winners = { v }
  23.                 winningScore = score
  24.             elseif score == winningScore then
  25.                 table.insert( winners, v )
  26.             end
  27.         end
  28.     end
  29.  
  30.     if winningScore > 0 and winners[1] then
  31.         ULib.tsayColor( winners, false, Color( 241, 196, 15 ), "You've received a reward for your outstanding performance as a Hunter last round!" )
  32.         -- Todo: give actual reward
  33.     end
  34.  
  35.     score = {}
  36. end )
  37.  
  38. -- Create a custom hook "RoundOver" that gets called whenever a round has ended.
  39. local inRoundBefore = nil
  40. local inRoundNow = nil
  41. hook.Add( "Think", "CheckRoundEnd", function()
  42.     inRoundNow = hook.Call( "InRound", GAMEMODE )
  43.  
  44.     if inRoundBefore and not inRoundNow then
  45.         hook.Call( "RoundOver", GAMEMODE )
  46.     end
  47.  
  48.     inRoundBefore = inRoundNow
  49. end )
« Last Edit: February 23, 2016, 07:48:23 am by Timmy »

  • Print