General > Developers Corner
Trying to learn lua a little
Desimay:
--- Quote from: JamminR on February 13, 2014, 07:58:15 AM ---1) As I originally asked, where are you putting this code?
It's possible, depending on where it is, that it's loading before the functions it uses are created by the gamemode or addon.
2) Try a print command inside the function too, to see if it's working right when it runs, if the hook is even running.
--- Code: ---function AddHpToLevel(ply)
print ( ply:Nick() .. " level is ".. ply:getDarkRPVar('level') )
if ( ply:getDarkRPVar('level') >= 60 ) then
--- End code ---
--- End quote ---
I did some testing and I ran this on my dev server
--- Code: --- lua_run_cl for k,v in pairs(player.GetAll() ) do local lvl = v:getDarkRPVar('level') print(lvl) end
--- End code ---
and that seems to work. So getting the level is client side but I need to set the health.
JamminR:
Does the darkrp level var or getlevel function exist on server?
Seems silly the info like that would be client only.
Desimay:
--- Quote from: JamminR on February 13, 2014, 08:02:17 AM ---Does the darkrp level var or getlevel function exist on server?
Seems silly the info like that would be client only.
--- End quote ---
The getDarkRPVar('level') is client side.
JamminR:
Right, seeing 'self' in the actual function indicates that the function itself is client.
You'd need to find out if the DarkRP variable 'level' exists on the server side.
If it's on the server, a server side function could be written (if not already exist) to get the value for players on server side.
(return ply:getDarkRPVar('level') instead of self:)
EDIT: According to DarkRP WIKI - GetDarkRPVar is shared.
http://wiki.darkrp.com/index.php/Functions/player/shared/getdarkrpvar
You just need to make sure your code is running on server side only.
Desimay:
--- Quote from: JamminR on February 13, 2014, 08:40:46 AM ---Right, seeing 'self' in the actual function indicates that the function itself is client.
You'd need to find out if the DarkRP variable 'level' exists on the server side.
If it's on the server, a server side function could be written (if not already exist) to get the value for players on server side.
(return ply:getDarkRPVar('level') instead of self:)
EDIT: According to DarkRP WIKI - GetDarkRPVar is shared.
http://wiki.darkrp.com/index.php/Functions/player/shared/getdarkrpvar
You just need to make sure your code is running on server side only.
--- End quote ---
Ok I think I found something that might work.
Client Side:
--- Code: ---if ( SERVER ) then return; end
function PlayerCheck()
for k,v in pairs( player.GetAll() ) do
if ( v:getDarkRPVar('level') >= 70 ) then
net.Start("Send_HP_70")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 60 ) then
net.Start("Send_HP_60")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 50 ) then
net.Start("Send_HP_50")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 40 ) then
net.Start("Send_HP_40")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 30 ) then
net.Start("Send_HP_30")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 20 ) then
net.Start("Send_HP_20")
net.SendToServer()
elseif ( v:getDarkRPVar('level') >= 10 ) then
net.Start("Send_HP_10")
net.SendToServer()
end
end
end
hook.Add( "PlayerSpawn", "PlayerCheck", PlayerCheck);
--- End code ---
Server Side:
--- Code: ---if ( CLIENT ) then return; end
util.AddNetworkString( "Send_HP_70" );
util.AddNetworkString( "Send_HP_60" );
util.AddNetworkString( "Send_HP_50" );
util.AddNetworkString( "Send_HP_40" );
util.AddNetworkString( "Send_HP_20" );
util.AddNetworkString( "Send_HP_10" );
net.Receive( "Send_HP_70", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_60", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_50", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_40", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_30", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_20", function(ply)
ply:SetHealth(700);
end )
net.Receive( "Send_HP_10", function(ply)
ply:SetHealth(700);
end )
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version