Hey I'm trying to make a ability script. Pretty simple, player clicks button, stuff happens. But the stuff has to be serverside, thus the net library.
I'm completely new to this, so be patient with the idiocy.
Here's the error.
[code]
[ERROR] addons/abilities/lua/autorun/sh_abilities.lua:56: Calling net.Start with unpooled message name
[/code]
Here's the code
[code]
if SERVER then
util.AddNetworkString( "set_armor" )
util.AddNetworkString( "set_health" )
net.Receive( "set_health", function( _, ply )
ply:SetHealth( net.ReadInt( 32 ) )
end )
net.Receive( "set_armor", function( _, ply )
ply:SetArmor( net.ReadInt( 32 ) )
end )
else --Client
local function set_health_from_client( health )
net.Start("set_health")
net.WriteInt(health, 32)
net.SendToServer()
end
local function set_armor_from_client( armor )
net.Start( "set_armor" )
net.WriteInt( armor, 32 )
net.SendToServer()
end
ply = LocalPlayer()
--[Key Listening]--
hook.Add( "Think", "KeyDown_Test", function()
ply = LocalPlayer()
if input.IsKeyDown(38) then
if ability1_triggered == false then
set_health_from_client(ply:Health() + 25)
ability1_timer = 1
ability1_triggered = true
end
end
end)
end
[/code]
Please help! Thanks in advance facepunch!
Post the full code, I don't see a line 56 because there are only 45 lines.
Sorry, the error specified is on this codes line 14, or the net.Start("set_health") ,,, the full code.
I think that the issue of the Client telling the server how much health they should have is more pressing.
Don't worry about that digusnin, it's a ability thing with a timer set up so it can only be called every hour or so. I'm a okay coder just never diddled with the net library.
But srsly doe dis err doe.
My next move would be to create the hook inside a timer with interval 0 (running once only), as to create the hook the next frame.
The error. I need wtf is going on within the error at
net.Start("set_health")
please help.
[editline]22nd January 2014[/editline]
-bump-
-snip-
I need to learn to read :v
I need to learn why this bug exists.
[editline]22nd January 2014[/editline]
*confusion intensifies*
-bumping intensifies-
-Being voted dumb but not helped intensifies-
Yeah I saw that shit Jeezy XD
[sp] I check that util.AddNetworkString was only available server-side, sorry.[/sp]
I don't see the issue. You're not posting something.
[lua]util.AddNetworkString( "set_armor" )
util.AddNetworkString( "set_health" )[/lua]
means you can only use:
[lua]net.Start( "set_armor" )
net.Start( "set_health" )[/lua]
You're calling something else, somewhere. You're using a net.Start with a message which was never pooled using util.AddNetworkString; which is SERVER-side only as pointed out.
Without posting the entire script, we can't help you further.
Alright, here is the full code.
[code]
ply = LocalPlayer()
ability1_triggered = false
ability1_timer = 0
ability2_triggered = false
ability2_timer = 0
function sv_ability1(ply)
//if ply:GetNWInt('LVL') >= 1 then
if ability1_triggered == false then
ply:SetHealth(1)
ability1_timer = 1
ability1_triggered = true
end
//end
end
function sv_ability2(ply)
//if ply:GetNWInt('LVL') >= 3 then
if ability2_triggered == false then
ply:SetArmor(ply:Armor() + 25)
ply:SetRunSpeed(2000)
ability2_timer = 1
ability2_triggered = true
timer.Create("walkspeedtimer", 15, 1, function() ply:SetWalkSpeed(250) ply:SetRunSpeed(500) Msg("Walk speed increase over.") end)
end
//end
end
--[Resetting Abilities]--
function sv_ability1_timer()
if ability1_timer > 0 then
timer.Create("ability1_regen", 60, 1, function() ability1_timer = ability1_timer - 1 end)
else
ability1_triggered = false
ability1_timer = 0
end
end
function sv_ability2_timer()
if ability2_timer > 0 then
timer.Create("ability2_regen", 60, 1, function() ability2_timer = ability2_timer - 1 end)
else
ability2_triggered = false
ability2_timer = 0
end
end
sv_ability1_timer()
sv_ability2_timer()
if SERVER then
util.AddNetworkString( "set_armor" )
util.AddNetworkString( "set_health" )
net.Receive( "set_health", function( _, ply )
ply:SetHealth( net.ReadInt( 32 ) )
end )
net.Receive( "set_armor", function( _, ply )
ply:SetArmor( net.ReadInt( 32 ) )
end )
else --Client
local function set_health_from_client( health )
net.Start("set_health")
net.WriteInt(health, 32)
net.SendToServer()
end
local function set_armor_from_client( armor )
net.Start( "set_armor" )
net.WriteInt( armor, 32 )
net.SendToServer()
end
ply = LocalPlayer()
--[Key Listening]--
hook.Add( "Think", "KeyDown_Test", function()
ply = LocalPlayer()
if input.IsKeyDown(38) then
//if ply:GetNWInt('LVL') >= 1 then
if ability1_triggered == false then
set_health_from_client(ply:Health() + 25)
ability1_timer = 1
ability1_triggered = true
end
//end
end
end)
function abilityHUD()
--[Background]--
local bgcolor = Color(0, 0, 0, 100)
local bgforecolor = Color(75, 75, 75, 150)
local y = ScrH()/2 - 207
local x = ScrW() - 60
draw.RoundedBox(0, ScrW() - 65, ScrH()/2 - 210, 145, 420, bgcolor)
draw.RoundedBox(2, x, y+5, 55, 55, bgforecolor)
draw.RoundedBox(2, x, y+95, 55, 55, bgforecolor)
draw.RoundedBox(2, x, y+185, 55, 55, bgforecolor)
draw.RoundedBox(2, x, y+275, 55, 55, bgforecolor)
draw.RoundedBox(2, x, y+355, 55, 55, bgforecolor)
draw.SimpleText("1", "TargetID", x, y + 5, Color(255, 255, 255, 255))
draw.SimpleText("2", "TargetID", x, y + 95, Color(255, 255, 255, 255))
draw.SimpleText("3", "TargetID", x, y + 185, Color(255, 255, 255, 255))
draw.SimpleText("4", "TargetID", x, y + 275, Color(255, 255, 255, 255))
draw.SimpleText("5", "TargetID", x, y + 355, Color(255, 255, 255, 255))
local img_hp = Material("icon16/heart_add.png")
local img_arm = Material("icon16/shield_add.png")
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(img_hp)
surface.DrawTexturedRect( x + 19, y + 25, 16, 16)
surface.SetMaterial(img_arm)
surface.DrawTexturedRect( x + 19, y + 115, 16, 16)
hp = LocalPlayer():Health()
arm = LocalPlayer():Armor()
draw.SimpleText("HP : "..hp, "TargetID", 10, 10, Color(255, 255, 255, 255))
draw.SimpleText("Armor : "..arm, "TargetID", 10, 25, Color(255, 255, 255, 255))
end
hook.Add("HUDPaint", "AbilityHUD", abilityHUD)
end
[/code]
I hope you guys can find the error now. im stumped :P
I've had this odd error my self some time ago. Your code seems to be fine but I haven't really looked it through. I solved this problems by restarting my game, and dont know if it help's but try splitting your file up ex. sv_abilities and cl_abilities instead og sh (I know that includes server and client but just try) It may help or may not. Anyway good luck!
So, line 56 is pointing to: util.AddNetworkString( "set_health" ) which makes absolutely no sense, because it doesn't contain net.Start there. It still doesn't appear to be the full code??
If it is, there have been issues in the past where characters have been corrupted yet have appeared fine. Delete the ""s and everything between them in the 6 locations where the Network strings are called.
set_health and set_armor; re-type that text. That's all I can say if that's the script, and that's the correct line for the error; that or your server is out-dated / corrupted. Something is missing from this puzzle.
I fixedit by splitting it into a client and shared, changed nothing about the code. Still having issues but the important thing is, the messages are being sent, thanks facepunch! SOLVED.
Sorry, you need to Log In to post a reply to this thread.