I wrote a little code for a fretta gamemode making it so a certain class only gets the physgun in certain areas. It works, but I get error spams anyway (Errors on the two lines with HasWeapon). Is something written incorrectly? This is the snippet of code in the script for the class:
function CLASS:Move( pl, mv )
persony = (pl:GetPos()).y
if persony >= 50 then
if (pl:HasWeapon("weapon_physgun")) then
pl:StripWeapon("weapon_physgun")
else return
end
else
if (pl:HasWeapon("weapon_physgun")) == false then
pl:Give("weapon_physgun")
else return
end
end
end
[QUOTE=Farmbot26;36325826]I wrote a little code for a fretta gamemode making it so a certain class only gets the physgun in certain areas. It works, but I get error spams anyway (Errors on the two lines with HasWeapon). Is something written incorrectly? This is the snippet of code in the script for the class:
function CLASS:Move( pl, mv )
persony = (pl:GetPos()).y
if persony >= 50 then
if (pl:HasWeapon("weapon_physgun")) then
pl:StripWeapon("weapon_physgun")
else return
end
else
if (pl:HasWeapon("weapon_physgun")) == false then
pl:Give("weapon_physgun")
else return
end
end
end[/QUOTE]Could you paste the error?
[MelPy\gamemode\player_class\pylon_engineer.lua:51] attempt to call method 'HasWeapon' (a nil value)(Hook: Move)
[
and
[MelPy\gamemode\player_class\pylon_engineer.lua:45] attempt to call method 'HasWeapon' (a nil value)(Hook: Move)
[
[QUOTE=Farmbot26;36325898][MelPy\gamemode\player_class\pylon_engineer.lua:51] attempt to call method 'HasWeapon' (a nil value)(Hook: Move)
[
and
[MelPy\gamemode\player_class\pylon_engineer.lua:45] attempt to call method 'HasWeapon' (a nil value)(Hook: Move)
[[/QUOTE]
Try putting these prints in the front.
[lua]
print(pl:IsValid())
print(pl:HasWeapon("weapon_physgun"))
[/lua]
It got rid of the two errors from before and the code still works, but now it spams an error on the line with the second print. :/
Are you running this clientside or serverside? Bear in mind that pl:HasWeapon only exists serverside. You might also be having a nil player being passed to the function. Make sure you are running it serverside and the player is valid, it should suppress the error.
It is running serverside and I have
if !(pl:IsValid()) then return end
in the front.
[QUOTE=Farmbot26;36326841]It is running serverside and I have
if !(pl:IsValid()) then return end
in the front.[/QUOTE]
Actually..
[lua]function IncludePlayerClasses()
local Folder = string.Replace( GM.Folder, "gamemodes/", "" );
for c,d in pairs(file.FindInLua(Folder.."/gamemode/player_class/*.lua")) do
include( Folder.."/gamemode/player_class/"..d )
AddCSLuaFile( Folder.."/gamemode/player_class/"..d )
end
end[/lua]
Your running both serverside and clientside.
[lua]function CLASS:Move( pl, mv )
if SERVER then
y = pl:GetPos().y
if y >= 50 then
if pl:HasWeapon("weapon_physgun") then
pl:StripWeapon("weapon_physgun")
end
else
if !pl:HasWeapon("weapon_physgun") then
pl:Give("weapon_physgun")
end
end
end
end[/lua]
I put
if !SERVER then return end
in front and it works perfectly. Thanks everyone! :D
Your very welcome.
Sorry, you need to Log In to post a reply to this thread.