My problem is when I open my addon and click on the button, it sends the messages through the network, when they arrive they won't use the commands given, they'll just print them in the console.
CLIENT
[Lua]
net.Start( "DOAMESS" )
net.WriteString( play )
net.WriteBool( unwanted )
net.WriteBool( wanted )
net.WriteBool( Deadoralive )
net.WriteBool( Dead )
net.WriteBool( Alived )
net.WriteFloat( Pricealive )
net.WriteFloat( Pricedead )
net.SendToServer()
net.SendToServer()
[/Lua]
SERVER
[Lua]
util.AddNetworkString( "DOAMESS" )
net.Receive( "DOAMESS", function(len, ply)
MsgN("DOAMESS: Contains "..len.." bits")
--MsgN("Player: "..ply)
MsgN(play)
MsgN(net.ReadString())
MsgN(unwanted)
MsgN(net.ReadBool())
MsgN(wanted)
MsgN(net.ReadBool())
MsgN(doa)
MsgN(net.ReadBool())
MsgN(dead)
MsgN(net.ReadBool())
MsgN(alive)
MsgN(net.ReadBool())
MsgN(pricealive)
MsgN(net.ReadFloat())
MsgN(pricedead)
MsgN(net.ReadFloat())
end)
if doa == true then
reason = "Dead or Alive"
end
if dead == true then
reason = "Dead"
end
if alive == true then
reason = "Alive"
end
print(play .. " is wanted by the police! Bring him " .. reason " to the pd and you will get " .. pricealive " if he is alive and " .. pricedead " if he is dead!")
if wanted == true then
if play:isWanted() then return end
play:wanted( "Goverment", play:Nick() .. " is wanted by the police! " .. reason .. pricedead .. pricealive, 120 )
end
if unwanted == true then
if not play:isWanted() then return end
play:unWanted("Goverment")
end
[/Lua]
Values printet in the console
[Lua]
DOAMESS: Contains 301 bits
nil
♥ Dagun | kickback.com ♥
nil
false
nil
true
nil
false
nil
true
nil
true
nil
10000000000
nil
1
[/Lua]
Help, I want it that when I send the message to the network that it uses the commands below! Thanks!
Everything looks in order for me, you never assign anything to those variables you print out, so naturally they will be nil on the server.
[code]
MsgN(play)
MsgN(net.ReadString()) [/code]
Must be
[code]
local play = net.ReadString()
MsgN(play)
[/code]
So from my understanding you want this server side
[LUA]
util.AddNetworkString( "DOAMESS" )
net.Receive( "DOAMESS", function(len, ply)
MsgN("DOAMESS: Contains "..len.." bits")
--MsgN("Player: "..ply)
local play = net.ReadString()
local unwanted = net.ReadBool()
local wanted = net.ReadBool()
local doa = net.ReadBool()
local dead = net.ReadBool()
local alive = net.ReadBool()
local pricealive = net.ReadFloat()
local pricedead = net.ReadFloat()
if doa == true then
reason = "Dead or Alive"
end
if dead == true then
reason = "Dead"
end
if alive == true then
reason = "Alive"
end
print(play .. " is wanted by the police! Bring him " .. reason " to the pd and you will get " .. pricealive " if he is alive and " .. pricedead " if he is dead!")
if wanted == true then
if play:isWanted() then return end
play:wanted( "Goverment", play:Nick() .. " is wanted by the police! " .. reason .. pricedead .. pricealive, 120 )
end
if unwanted == true then
if not play:isWanted() then return end
play:unWanted("Goverment")
end
end)
[/LUA]
Also, from optimization standpoint, I don't see any point in hading "wanted" and "unwanted", just have 1 bool that is true when the player is wanted, and false when they are not wanted.
Same goes for "deadoralive", "dead" and "alived", you only need 1 boolean for this: true = dead or alive, false = alive only ( Or vice versa ).
Alternatively you could send an integer, where 0 = deadoralive, 1 = dead, 2 = alive if you really must have that.
[editline]28th March 2016[/editline]
My automerge :c
Also, just like in the post above, you want to move the code outside of net.Receive into the net receive, so it is actually called when you receive the net message on the server. ( And can access local variables in the net.Receive )
[editline]28th March 2016[/editline]
Oh, and instead of sending player name, send the player object with net.WriteEntity()
[ERROR] addons/dead or alive/lua/autorun/server/doa.lua:34: attempt to call global 'reason' (a string value)
1. func - addons/dead or alive/lua/autorun/server/doa.lua:34
2. unknown - lua/includes/extensions/net.lua:32
DOAMESS: Contains 301 bits
[ERROR] addons/dead or alive/lua/autorun/server/doa.lua:36: attempt to index a string value with bad key ('isWanted' is not part of the string library)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:310
3. func - addons/dead or alive/lua/autorun/server/doa.lua:36
4. unknown - lua/includes/extensions/net.lua:32
[editline]28th March 2016[/editline]
DOAMESS: Contains 301 bits
DOAMESS: Contains 301 bits
DOAMESS: Contains 301 bits
DOAMESS: Contains 301 bits
DOAMESS: Contains 301 bits
I moved them outside but now nothing happens, it only prints this code above.
Uh, post the new code? How are we supposed to know what you did wrong?
CLIENT
[Lua]
hook.Add( "OnPlayerChat", "HelloCommand", function( ply, strText, bTeam, bDead )
strText = string.lower( strText )
if ( strText == "!wanted" ) then
DOAP = vgui.Create( "DFrame" )
DOAP:SetSize( 1000, 500 )
DOAP:SetText( "" )
DOAP:Center()
DOAP:SetTitle("")
DOAP:SetVisible( true )
DOAP:SetDraggable( false )
DOAP:ShowCloseButton( false )
DOAP:MakePopup()
DOAP.Paint = function(s, w, h)
draw.RoundedBox(5, 0, 0, w, h, Color(0,0,0))
draw.RoundedBox(5, 2, 2, w-4, h-4, Color(50, 50, 50))
end
local DOAB5 = vgui.Create( "DButton" , DOAP )
DOAB5:SetPos( 615, 361)
DOAB5:SetText( "Update" )
DOAB5:SetTextColor(Color(255,255,255))
DOAB5:SetSize( 100, 18 )
DOAB5:SetTextColor( Color(255,255,255))
DOAB5.Paint = function(s, w, h)
draw.RoundedBox(3,0,0,w,h,Color(50, 50, 255))
end
DOAB5.DoClick = function()
DOATEXTE:OnChange()
DOATEXTE:OnTextChanged( true )
Pricedead = tonumber( DOATEXTE:GetValue() )
end
local DOAB6 = vgui.Create( "DButton" , DOAP )
DOAB6:SetPos( 615, 421)
DOAB6:SetText( "Update" )
DOAB6:SetTextColor(Color(255,255,255))
DOAB6:SetSize( 100, 18 )
DOAB6:SetTextColor( Color(255,255,255))
DOAB6.Paint = function(s, w, h)
draw.RoundedBox(3,0,0,w,h,Color(50, 50, 255))
end
DOAB6.DoClick = function()
DOATEXTE2:OnChange()
DOATEXTE2:OnTextChanged( true )
Pricealive = tonumber( DOATEXTE2:GetValue() )
end
local DOAT2 = vgui.Create( "DLabel" , DOAP )
DOAT2:SetPos( 465, 20 )
DOAT2:SetText( "Dead or Alive" )
DOAT2:SetSize(200, 20)
local DOAB = vgui.Create( "DButton" , DOAP )
DOAB:SetPos( 977, 3)
DOAB:SetText( "X" )
DOAB:SetSize( 20, 20 )
DOAB:SetTextColor( Color(255,255,255))
DOAB.Paint = function(s, w, h)
draw.RoundedBox(3,0,0,w,h,Color(255, 50, 50))
end
DOAB.DoClick = function()
DOAP:Close()
end
local DOAC = vgui.Create( "DComboBox" , DOAP )
DOAC:SetPos( 400, 150 )
DOAC:SetSize( 200, 20 )
DOAC:SetValue( "Player" )
for k, v in pairs( player.GetAll() ) do
DOAC:AddChoice ( tostring( v:Name() ) )
DOAC:GetSelected(v:Name())
play = v:Name()
end
local DOAT = vgui.Create( "DLabel" , DOAP )
DOAT:SetPos( 460, 35 )
DOAT:SetText( "Wanted menu" )
DOAT:SetSize(200,200)
local DOAB2 = vgui.Create( "DButton" , DOAP )
DOAB2:SetPos( 390, 180)
DOAB2:SetText( "Wanted" )
DOAB2:SetSize( 100, 20 )
DOAB2:SetTextColor( Color(255,255,255))
DOAB2.Paint = function(s, w, h)
draw.RoundedBox(3,0,0,w,h,Color(255, 50, 50))
end
DOAB2.DoClick = function()
wanted = true
unwanted = false
net.Start( "DOAMESS" )
net.WriteString( play )
net.WriteBool( unwanted )
net.WriteBool( wanted )
net.WriteBool( Deadoralive )
net.WriteBool( Dead )
net.WriteBool( Alived )
net.WriteFloat( Pricealive )
net.WriteFloat( Pricedead )
net.SendToServer()
end
local DOAB3 = vgui.Create( "DButton" , DOAP )
DOAB3:SetPos( 510, 180)
DOAB3:SetText( "Unwanted" )
DOAB3:SetTextColor(Color(255,255,255))
DOAB3:SetSize( 100, 20 )
DOAB3:SetTextColor( Color(255,255,255))
DOAB3.Paint = function(s, w, h)
draw.RoundedBox(3,0,0,w,h,Color(50, 180, 50))
end
DOAB3.DoClick = function()
unwanted = true
wanted = false
net.Start( "DOAMESS" )
net.WriteString( play )
net.WriteBool( unwanted )
net.WriteBool( wanted )
net.WriteBool( Deadoralive )
net.WriteBool( Dead )
net.WriteBool( Alived )
net.WriteFloat( Pricealive )
net.WriteFloat( Pricedead )
net.SendToServer()
end
DOACH = vgui.Create("DCheckBox", DOAP)
DOACH:SetPos(495,250)
DOACH:Toggle()
function DOACH:OnChange( bVal )
if ( bVal ) then
DOACH2:SetValue()
DOACH3:SetValue()
Deadoralive = true
end
end
DOACH2 = vgui.Create("DCheckBox", DOAP)
DOACH2:SetPos(145,250)
function DOACH2:OnChange( bVal )
if ( bVal ) then
DOACH:SetValue()
DOACH3:SetValue()
Dead = true
end
end
DOACH3 = vgui.Create("DCheckBox", DOAP)
DOACH3:SetPos(845,250)
function DOACH3:OnChange( bVal )
if ( bVal ) then
DOACH2:SetValue()
DOACH:SetValue()
Alived = true
end
end
local DOAT3 = vgui.Create( "DLabel" , DOAP )
DOAT3:SetPos( 140, 230 )
DOAT3:SetText( "Dead" )
DOAT3:SetSize(200, 20)
local DOAT4 = vgui.Create( "DLabel" , DOAP )
DOAT4:SetPos(475, 230)
DOAT4:SetText( "Dead or Alive" )
DOAT4:SetSize(200, 20)
local DOAT5 = vgui.Create( "DLabel" , DOAP )
DOAT5:SetPos( 840, 230 )
DOAT5:SetText( "Alive" )
DOAT5:SetSize(200, 20)
DOATEXTE = vgui.Create( "DTextEntry", DOAP )
DOATEXTE:SetPos( 410, 360 )
DOATEXTE:SetSize( 200, 20 )
DOATEXTE:SetText( 5000 )
DOATEXTE.OnEnter = function( self )
Pricedead = tonumber( self:GetValue() )
end
DOATEXTE2 = vgui.Create( "DTextEntry", DOAP )
DOATEXTE2:SetPos( 410, 420 )
DOATEXTE2:SetSize( 200, 20 )
DOATEXTE2:SetText( 5000 )
DOATEXTE2.OnEnter = function( self )
Pricealive = tonumber( self:GetValue() )
end
--local DOAB4 = vgui.Create( "DButton" , DOAP )
--DOAB4:SetPos( 460, 460)
--DOAB4:SetText( "Done" )
--DOAB4:SetTextColor(Color(255,255,255))
--DOAB4:SetSize( 100, 20 )
--DOAB4:SetTextColor( Color(255,255,255))
--DOAB4.Paint = function(s, w, h)
--draw.RoundedBox(3,0,0,w,h,Color(50, 50, 255))
--end
--DOAB3.DoClick = function()
-- net.Start( "DOAMESS" )
-- net.WriteString( play )
-- net.WriteBool( unwanted )
-- net.WriteBool( wanted )
-- net.WriteBool( Deadoralive )
-- net.WriteBool( Dead )
-- net.WriteBool( Alived )
-- net.WriteFloat( Pricealive )
-- net.WriteFloat( Pricedead )
-- net.SendToServer()
--end
local DOAT6 = vgui.Create( "DLabel" , DOAP )
DOAT6:SetPos( 485, 340 )
DOAT6:SetText( "Price dead" )
DOAT6:SetSize(200, 20)
local DOAT7 = vgui.Create( "DLabel" , DOAP )
DOAT7:SetPos( 485, 400 )
DOAT7:SetText( "Price alive" )
DOAT7:SetSize(200, 20)
return true
end
end )
[/Lua]
SERVER
[Lua]
util.AddNetworkString( "DOAMESS" )
net.Receive( "DOAMESS", function(len, ply)
MsgN("DOAMESS: Contains "..len.." bits")
--MsgN("Player: "..ply)
local play = net.ReadString()
local unwanted = net.ReadBool()
local wanted = net.ReadBool()
local doa = net.ReadBool()
local dead = net.ReadBool()
local alive = net.ReadBool()
local pricealive = net.ReadFloat()
local pricedead = net.ReadFloat()
end)
if doa == true then
reason = "Dead or Alive"
print("It ")
end
if dead == true then
reason = "Dead"
print("did ")
end
if alive == true then
reason = "Alive"
print("work! ")
end
if wanted == true then
if play:isWanted() then return end
play:wanted( "Goverment", play:Nick() .. " is wanted by the police! " .. reason .. pricedead .. pricealive, 120 )
print("yay 1 ")
end
if unwanted == true then
if not play:isWanted() then return end
play:unWanted("Goverment")
play(" yay 2 ")
end
print("end")
[/Lua]
[QUOTE=Robotboy655;50020307]Also, from optimization standpoint, I don't see any point in hading "wanted" and "unwanted", just have 1 bool that is true when the player is wanted, and false when they are not wanted.
Same goes for "deadoralive", "dead" and "alived", you only need 1 boolean for this: true = dead or alive, false = alive only ( Or vice versa ).
Alternatively you could send an integer, where 0 = deadoralive, 1 = dead, 2 = alive if you really must have that.
[editline]28th March 2016[/editline]
My automerge :c
Also, just like in the post above, you want to move the code outside of net.Receive into the net receive, so it is actually called when you receive the net message on the server. ( And can access local variables in the net.Receive )
[editline]28th March 2016[/editline]
Oh, and instead of sending player name, send the player object with net.WriteEntity()[/QUOTE]
Please for the love of god READ the replies BEFORE posting.
Sorry, you need to Log In to post a reply to this thread.