• Print

Author Topic: Getting the current map and current player count isn't working  (Read 4433 times)

0 Members and 1 Guest are viewing this topic.

Offline Rex744

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Hello, I was expecting my code to use the ulx csaycolor command from the ulx custom commands, and I wanted my script to check if the map is pb_z_high_school_g then if there are a certain amount of players to display a specific ulx csay message which veries depending on how many people are on. This is not the case, when I run this file, the only thing showing up is the first EASY message, I've messed around with my alt accounts in-game and by using bots in-game, there is no change. After running the file, it never updates text again, so if I add a bot no other message appears, it is only when I run the file.

Can anyone help me?

Code: [Select]
function AutoDifficultyPatch(ply)
for k,v in pairs (player.GetAll()) do
if game.GetMap() == "pb_z_high_school_g" then do
if v:GetCount(1) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to EASY. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(2) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to EASY. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(3) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to MEDIUM. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(4) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to HARD. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(5) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to HARD. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(6) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to HARD. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(7) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to INSANE. Do !difficulty to vote change to a different one.", "red")
elseif v:GetCount(8) then
RunConsoleCommand("ulx", "csaycolor", "[Someone joined/left] Difficulty automatically changed to INSANE. Do !difficulty to vote change to a different one.", "red")
end
end
end
end
end
hook.Add( PlayerInitialSpawn, "AutoDifficultyPatch()", AutoDifficultyPatch() )

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Getting the current map and current player count isn't working
« Reply #1 on: April 03, 2017, 11:00:35 pm »
First, your hook statement could be fixed:

Code: Lua
  1. hook.Add( "PlayerInitialSpawn", "AutoDifficultyPatch", AutoDifficultyPatch )

(You don't need the empty parenthesis on a hook call)
Also, running v:GetCount() isn't necesary here since you're only checking for amount of players, you can simply check:

Code: Lua
  1. if #player.GetAll() == 1 then
  2.   -- The 1 statement
  3. elseif #player.GetAll() == 2 then
  4.   -- The 2 statement
  5. -- etc.etc.
  6.  


Another side note, one of your if statements:
Code: Lua
  1. if game.GetMap() == "pb_z_high_school_g" then do
is improper, you don't need the 'do' at the end. Surprised that didn't throw an error for you.

So then in the end you'd have something like:

Code: Lua
  1. function AutoDifficultyPatch( ply )
  2.   if game.GetMap() == "pb_z_high_school_g" then
  3.     if #player.GetAll() == 1 then
  4.       -- etc.
  5.     elseif #player.GetAll() == 2 then
  6.       -- etc.
  7.     end
  8.   end
  9. end
  10. hook.Add( "PlayerInitialSpawn", "AutoDifficultyPatch", AutoDifficultyPatch )
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print