Hi there, I am trying to make my script use the net library instead of net. I got 90% of my SendLua's Changed over but i am stuck on this one.
I though it was a string but i guess not. Please help?
Client:
[code]
unction jobqueue:BecomeJob(t)
local agreement=false
local time=CurTime()+20
local teamName=RPExtraTeams[t].name
local frame=vgui.Create("DFrame")
frame:SetSize(230,110)
frame:SetPos(ScrW()/2-frame:GetWide()/2,ScrH()/2-frame:GetTall()/2)
frame:SetVisible(true)
frame:SetTitle("Become job")
frame:SetDraggable(false)
frame:MakePopup()
frame:DoModal(true)
function frame:OnClose()
if not agreement then
net.Start("RemoveFromQueue")
net.WriteDouble(t)
net.SendToServer()
end
end
local label=vgui.Create("DLabel",frame)
label:SetPos(15,22)
label:SetText("You are top of the queue of "..teamName..",\nwould you become this job")
label:SizeToContents()
local yesbutton=vgui.Create("DButton",frame)
yesbutton:SetPos(20,60)
yesbutton:SetSize(100,40)
yesbutton:SetText(RPExtraTeams[t]["vote"] and DarkRP.getPhrase("create_vote_for_job") or DarkRP.getPhrase("become_job"))
yesbutton.DoClick=function()
agreement=true
net.Start("BecomeJob")
net.WriteDouble(t)
net.SendToServer()
frame:Close()
end[/code]
Server:
[code]
local function UpdateQueue() --watch for existed players. if player leave the server it will clear the place in queue also main function to submit player if he done to join team
for i=1,#jobqueue.queue do
for j=1,#jobqueue.queue[i] do
if not IsValid(jobqueue.queue[i][j]) then
local qplace=table.RemoveByValue(jobqueue.queue[i],ply)
if #jobqueue.queue[i]==0 and jobqueue.status[i]==1 then jobqueue.status[i]=0 end
if #jobqueue.queue[i]>0 then
for k=qplace,#jobqueue.queue[i] do
DarkRP.notify(jobqueue.queue[i][k], 2, 4, "New position in queue ("..k..") "..RPExtraTeams[t].name)
end
end
end
end
local TEAM = RPExtraTeams[i]
if not TEAM then return false end
local max = TEAM.max
if not (max ~= 0 and -- No limit
(max >= 1 and team.NumPlayers(i) >= max or -- absolute maximum
max < 1 and (team.NumPlayers(i) + 1) / #player.GetAll() > max)) and jobqueue.status[i]==1 then
jobqueue.status[i]=2
local ply=jobqueue.queue[i][1]
ply:SendLua("jobqueue:BecomeJob("..i..")")
timer.Simple(15,function()
if IsValid(jobqueue.queue[i][1]) and jobqueue.queue[i][1]==ply and ply:Team()~=i and jobqueue.status[i]==2 then --player lagging or timeout or something like that
local qplace=table.RemoveByValue(jobqueue.queue[i],ply)
if #jobqueue.queue[i]==0 then jobqueue.status[i]=0 else jobqueue.status[i]=1 end
if #jobqueue.queue[i]>0 then
for j=qplace,#jobqueue.queue[i] do
DarkRP.notify(jobqueue.queue[i][j], 2, 4, "New position in queue ("..j..") "..RPExtraTeams[i].name)
end
end
end
end)
end
end
end
hook.Add("Think","UpdateQueue",UpdateQueue)[/code]
Saw your other thread and figured you had it sorted out?
Did you try anything like this?
Serverside
[code]
-- In the scope of the file
util.AddNetworkString("jobqueue_BecomeJob")
-- When sending to player
net.Start("jobqueue_BecomeJob")
net.WriteUInt(i, 32)
net.Send(ply)
[/code]
Clientside
[code]
net.Receive("jobqueue_BecomeJob", function()
local i = net.ReadUInt(32)
jobqueue:BecomeJob(i)
end)
[/code]
(i is a positive whole number in all cases)
Yeah my other thread i got all the other ones working. But this one. Ill try it
[editline]6th August 2014[/editline]
It worked! Thanks so mush!
Sorry, you need to Log In to post a reply to this thread.