Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax and logic fixes #8

Merged
merged 8 commits into from
Mar 10, 2020
Merged

Syntax and logic fixes #8

merged 8 commits into from
Mar 10, 2020

Conversation

justinmuskopf
Copy link
Member

Resolves Issue #7

local customSpawnsForMap = cfcRandomSpawn.config.CUSTOM_SPAWNS[game.GetMap()]
local mapHasCustomSpawns = customSpawnsForMap ~= nil

hook.Remove( "PlayerSpawn", "CFC_PlayerSpawning" )

if mapHasCustomSpawns then
cfcRandomSpawn.spawnPointRankings = cfcRandomSpawn.spawnPointRankings or {}
if not mapHasCustomSpawns then return end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short-circuit Instead of blanketing the entire file in a condition

-- This is operating on a model of spawn points and players as electrons putting a force on each other
-- The best spawn point is the spawn point under the smallest sum of forces then. This is why we use physics terms here
local distSqr = 900 --(30^2)
local randMin, randMax = 1, 4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract these houdini bois

if not (ply && IsValid( ply )) then return end
if ply.LinkedSpawnPoint then return end
function cfcRandomSpawn.handlePlayerSpawn( ply )
if not ( ply && IsValid( ply ) ) then return end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When CFCLib is official, this will be CFCLib.isValidPlayer( ply )

{ "spawn" = Vector( 425.38064575195, 1636.2911376953, 64.968605041504 ), "pvp" = true },
{ "spawn" = Vector( -974.1875, 130.53991699219, 128.03125 ), "pvp" = true },
{ "spawn" = Vector( -1357.5144042969, 1473.0662841797, 128.03125 ), "pvp" = true },
{ "spawn" = Vector( -1000.3621826172, 1044.5682373047, 464.03125 ) "pvp" = true }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to know if this much precision is necessary...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"too much precision"

said no one ever.

Copy link
Member Author

@justinmuskopf justinmuskopf Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay frick you

Copy link
Member

@brandonsturgeon brandonsturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

Let's change these keys and then give it a test and we'll merge it

Vector( -1357.5144042969, 1473.0662841797, 128.03125 ),
Vector( -1000.3621826172, 1044.5682373047, 464.03125 )

{ "spawn" = Vector( 1104.6744384766, 131.18112182617, 64.03125 ), "pvp" = true },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like these keys. Could we do:

{ "spawn_pos" = Vector( ), "isPvpSpawn" = true }

Something like that.

Mostly this helps the other file read better.

Copy link
Member

@brandonsturgeon brandonsturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, pending testing.

@TechnichalDoge
Copy link
Contributor

`[ERROR] addons/cfc_random_spawn/lua/cfc_random_spawn/sh_config.lua:7: '}' expected near '='

  1. unknown - addons/cfc_random_spawn/lua/cfc_random_spawn/sh_config.lua:0
    `

@TechnichalDoge
Copy link
Contributor

@justinmuskopf

@brandonsturgeon
Copy link
Member

Haha, @justinmuskopf got LUA TABLE SYNTAX wrong, what a NERD


return measurablePlayers
local function getMeasurablePlayers()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do something stupid here, and maintain a cache of alive players and only invalidate it when a player dies or spawns - that way it'd be slightly more efficient

Vector( -1357.5144042969, 1473.0662841797, 128.03125 ),
Vector( -1000.3621826172, 1044.5682373047, 464.03125 )

{ "spawn_pos" = Vector( 1104.6744384766, 131.18112182617, 64.03125 ), "isPvpSpawn" = true },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @TechnichalDoge 's report, we may have to do this a different way. Something like this maybe:

local bluehills = {}
table.insert( bluehills, { "spawn_pos" = Vec(), "isPvpSpawn" = true } )
table.insert( bluehills, etc.)

cfcRandomSpawn.config.CUSTOM_SPAWNS["gm_bluehills_test3"] = bluehills

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plally reminded us that we're just as stupid as lua is. proper syntax is like such:

{ ["spawn_pos"] = Vector(), ["isPvpSpawn"] = true }
etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandonsturgeon
Copy link
Member

retest this please

@brandonsturgeon
Copy link
Member

retest this please

@brandonsturgeon brandonsturgeon merged commit 6a9b375 into master Mar 10, 2020
@brandonsturgeon brandonsturgeon deleted the master_syntax_fixes branch March 10, 2020 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants