Code:
[CODE] local DermaSlider = vgui.Create( "DNumSlider", base )
DermaSlider:SetPos( 0, 65 )
DermaSlider:SetWide( 250 )
DermaSlider:SetMin( 0 )
DermaSlider:SetSize( 300,20 )
DermaSlider:SetMax( 1000 )
DermaSlider:SetValue( v:GetJumpPower() )
DermaSlider:SetDecimals( 0 )
DermaSlider.OnValueChanged = function( panel, value )
local data = math.Round(value)
print(v:GetJumpPower().." -> "..tostring( data ) )
print(v:GetJumpPower())
v:SetJumpPower( tonumber(data) )
v:PrintMessage( HUD_PRINTTALK, "Stats edited." )
end[/CODE]
debug messages:
[CODE]
Stats edited.
705 -> 705
705
Stats edited.[/CODE]
v does return the correct player as i do recieve the message: "Stats edited." however my jump power does not change, also the slider will often set its self to 500 when my jump is not that. Please help.
I feel as if this is a problem with not being able to edit the player in client side files,
if so, how would i send a message to trigger a function in init.lua?
if not, what is the problem?
You're calling a server-side function client-side.
You need to send that data to the server, and let the server set the jump-power.
use something like
[lua]// client
net.Start( "NetMessage" );
net.WriteLong( _jump_power );
net.SendToServer( );
// Server
util.AddNetworkString( "NetMessage" );
net.Receive( "NetMessage", function( bytes, Player )
local _jump_power = net.ReadLong( );
print( "Before: " .. Player:GetJumpPower( ) );
Player:SetJumpPower( _jump_power );
print( "After: " .. Player:GetJumpPower( ) );
end );[/lua]
[QUOTE=Acecool;43900613]You're calling a server-side function client-side.
You need to send that data to the server, and let the server set the jump-power.
use something like
[lua]// client
net.Start( "NetMessage" );
net.WriteLong( _jump_power );
net.SendToServer( );
// Server
util.AddNetworkString( "NetMessage" );
net.Receive( "NetMessage", function( bytes, Player )
local _jump_power = net.ReadLong( );
print( "Before: " .. Player:GetJumpPower( ) );
Player:SetJumpPower( _jump_power );
print( "After: " .. Player:GetJumpPower( ) );
end );[/lua][/QUOTE]
I have tried this before but only got the same type of error as i am recieveing now:
[ERROR] gamemodes/example/gamemode/cl_init.lua:41: attempt to call field 'WriteLong' (a nil value)
with the code:
net.WriteLong( data )
data: local data = math.Round(value)
value: DermaSlider.OnValueChanged = function( panel, value )
Full error log: [CODE]
[ERROR] gamemodes/example/gamemode/cl_init.lua:41: attempt to call field 'WriteLong' (a nil value)
1. OnValueChanged - gamemodes/example/gamemode/cl_init.lua:41
2. ValueChanged - lua/vgui/dnumslider.lua:195
3. OnValueChanged - lua/vgui/dnumslider.lua:42
4. SetValue - lua/vgui/dnumberscratch.lua:47
5. SetValue - lua/vgui/dnumslider.lua:126
6. OnChange - lua/vgui/dnumslider.lua:24
7. unknown - lua/vgui/dtextentry.lua:205
[/CODE]
WriteLong must've been changed for something else... Try WriteDouble and ReadDouble -- Int goes to 255, and you have to write the number of bytes going out, and know what's coming in. So, replace those and it should be fine.
[url]http://wiki.garrysmod.com/page/net/WriteDouble[/url]
[QUOTE=Acecool;43900918]WriteLong must've been changed for something else... Try WriteDouble and ReadDouble -- Int goes to 255, and you have to write the number of bytes going out, and know what's coming in. So, replace those and it should be fine.
[url]http://wiki.garrysmod.com/page/net/WriteDouble[/url][/QUOTE]
Thanks, the message was received however i now get this:
[ERROR] gamemodes/example/gamemode/init.lua:80: attempt to call method 'SetJumpPower' (a nil value)
1. func - gamemodes/example/gamemode/init.lua:80
code:
local ply = net.ReadEntity()
local data = net.ReadDouble()
ply:SetJumpPower(tonumber(data))
net.ReadEntity() = ply from : hook.Add( 'ShowSpare2', 'openf4menu', function( ply ) ... end)
How does it get this:
net.ReadEntity() = v
v = net.ReadEntity()
net.ReadEntity() = net.WriteEntity( ply )
ply = ply from : hook.Add( 'ShowSpare2', 'openf4menu', function( ply ) ... end)
[url]http://wiki.garrysmod.com/page/Player/SetJumpPower[/url]
Meaning your ply entity is null. You don't need to write entity if it's coming from the player you're changing. I showed you in the code, on net receive there is bytes and Player passed in automatically... Use that Player..
[QUOTE=Acecool;43901271][url]http://wiki.garrysmod.com/page/Player/SetJumpPower[/url]
Meaning your ply entity is null. You don't need to write entity if it's coming from the player you're changing. I showed you in the code, on net receive there is bytes and Player passed in automatically... Use that Player..[/QUOTE]
Thank you, you have helped me do something hard for my level of lua.
I notice you are active and formal which i enjoy, thank you again for helping me. I can continue in my newbie quest. Thanks.
Sorry, you need to Log In to post a reply to this thread.