Pivity

Can't figure out this error

Last read Never
#1

My goal with this addon is to linearly change starting health depending on a players karma. It worked before, but I hadn't yet implemented preventing it from going above the max hp convar or below the min. After adding that I've been getting this error. A friend and I were up trying to figure this out until 2:30 am lmao. Any assistance is greatly appreciated

error:

[ttt-karma-based-health] addons/ttt-karma-based-health/lua/autorun/tttkarmahp.lua:38: unexpected symbol near ')'

code:

if SERVER then

-- Add network

util.AddNetworkString( "KarmaHPText" )

-- ConVars

local KarmaHP = CreateConVar( "ttt_Karma_hp", "1", FCVAR_SERVER_CAN_EXECUTE, "Enables and disables KarmaHP addon.")

local minHealth = CreateConVar( "ttt_karma_hp_min_health", "75", FCVAR_SERVER_CAN_EXECUTE, "Sets the minimum health a player can have (given by this addon). (1-99) Def: 75.")

local maxHealth = CreateConVar( "ttt_karma_hp_max_health", "115", FCVAR_SERVER_CAN_EXECUTE, "Sets the maximum health a player can have (given by this addon). (101+) Def: 115.")

local minKarma = CreateConVar( "ttt_karma_hp_min_karma", "500", FCVAR_SERVER_CAN_EXECUTE, "Sets the karma value for a player to recieve the minimum health value. (0-1000) Def: 500.")

local maxKarma = CreateConVar( "ttt_karma_hp_max_karma", "1200", FCVAR_SERVER_CAN_EXECUTE, "Sets the karma value for a player to recieve the maximum health value. (1000+) Def: 1200.")

-- Hook to edit HP

hook.Add("TTTBeginRound","TTTBeginRound4KarmaHP",function()

local HP

local karma

local defaultMaxhp

-- calculate Health

local KarmaMax = GetConVarNumber("ttt_karma_max")

if KarmaHP:GetBool() then

for k, ply in pairs(player.GetAll()) do

karma = ply:GetBaseKarma()

defaultMaxhp = ply:GetMaxHealth()

if karma < minKarma:GetFloat() then

HP = minHealth:GetFloat()

else if karma > maxKarma:GetFloat() then

HP = maxHealth:GetFloat()

else if karma <= 1000 then

HP = math.floor((100-minHealth:GetFloat())/(1000-minKarma:GetFloat())*(karma-minKarma:GetFloat())+minHealth:GetFloat()+defaultMaxhp-100)

else --if karma > 1000 then

HP = math.floor((maxHealth:GetFloat()-99.5)/(maxKarma:GetFloat()-1000)*(karma-1000)+100+defaultMaxhp-100)

end

ply:SetHealth(HP)

-- info text

net.Start("KarmaHPText")

net.WriteString("Your have received "..HP.." HP because of your Karma.")

net.Send(ply)

end

end

end) --ERROR ON THIS LINE

end

if CLIENT then

-- print text

net.Receive("KarmaHPText", function(len, ply)

local Text = net.ReadString()

chat.AddText("TTT KarmaHP: ", Color( 255, 255, 255 ),Text)

end)

end

#2

Not quite sure if I've found it, can't check in gmod atm... But using glua weblint (https://fptje.github.io/glualint-web/)

You are using else if 2 times, this might be the issue. Writing it like that you are creating a 2nd if statement in the else part and you would need to end this new if statement, which you don't do. What you probably tried to to was to use elseif (no whitespace in between the 'else' and the 'if'!) which solves the issue (at least on the web lint.

I might be off here, I'm no glua expert and rarely used elseif, but I hope this help :)

Agree x 2
#3

Works perfectly now, I don't think I'd ever have caught that lol. Thanks so much

Friendly x 1
Users viewing this thread
Nobody