How do I give someone pointshop1 points when they close a derma panel with a button that was created.
In your panel close function, network to the server that the player has closed the panel, which you can give them points from there. I believe the function is called PS_GivePoints; it's on their documentation
[code] local DermaButton = vgui.Create("DButton", Advertisements)
DermaButton:Dock(BOTTOM)
DermaButton:SetSize( 150, 50 )
DermaButton:SetDisabled( true ) -- Should have this set to true to have the button disabled.
DermaButton.DoClick = function()
player:PS_GivePoints(10)
Advertisements:Remove()
end
DermaButton:SetText( "Close" )
-- This needs to be set for the time you want the button to be unclickable. It should be local.
-- timer.Create has 4 args: name, duration, reps, and the function that is called. If you want it to decrease by one every second, you need to have the reps set to 30 (30*1 second = 30 seconds) and the duration set to 1.
timer.Create( LocalPlayer():EntIndex().."button", 1, time, function()
time = time - 1
if ( time == 0 ) then
DermaButton:SetDisabled( false )
DermaButton:SetText( "Close" )
else
DermaButton:SetText( "Close in (" .. time ..")" )-- and this set to false to enable the button
end
end)
end)[/code]
This is the closing part
[editline]9th September 2015[/editline]
I have player:PS_GivePoints(10) but it not working.
PS_GivePoints doesn't exist clientside. You have to network it serverside.
How do i do that?
[editline]9th September 2015[/editline]
How do you network, I am very new at lua
ok so looking at this, How do i get it to network a when the DermaButton is click to close the derma panel?
[editline]9th September 2015[/editline]
[code]DermaButton.DoClick = function()
Advertisements:Remove()
end
[/code]
so do i want to add it here, then make it send somthing like true and on the clientside start somthing that like
if true do
In the DoClick function, start an empty netmessage and send it to the server. In the receive code serverside, give the points.
How do you create a empty netmessage? Is is just util.AddNetworkString( "points") and how do i receive it and make it give points?
util.AddNetworkString( "points")
net.Receive( "points" )
Serverside:
[code]util.AddNetworkString( "points" )
net.Receive( "points", function( len, ply )
ply:PS_GivePoints( int )
end )[/code]
DoClick (clientside):
[code]net.Start( "points" )
net.SendToServer()[/code]
Note that this will be insecure and anyone with a nethack can just get the points. I would add a verification method/key.
Is this correct?
Server Side
[code]
local function points()
ply:PS_GivePoints(10)
end
net.Receive( "point", points )
[/code]
Client Side
[code]
local DermaButton = vgui.Create("DButton", Advertisements)
DermaButton:Dock(BOTTOM)
DermaButton:SetSize( 150, 50 )
DermaButton:SetDisabled( true ) -- Should have this set to true to have the button disabled.
DermaButton.DoClick = function()
Advertisements:Remove()
util.AddNetworkString( "point" )
end
DermaButton:SetText( "Close" )
[/code]
No. "points" is the message name, not "point" Also, you have to add the network string serverside, not in the DoClick. You are also missing the net.Start/Send code. Lastly, you have to have arguments to your function: points needs the len and ply arguments.
What you gave me didn't work
[editline]10th September 2015[/editline]
No error or anything just didn't work
[editline]10th September 2015[/editline]
Wait sorry i did somthing wrong
[editline]10th September 2015[/editline]
yea this is not working for some reason
Client Side
[code]
local DermaButton = vgui.Create("DButton", Advertisements)
DermaButton:Dock(BOTTOM)
DermaButton:SetSize( 150, 50 )
DermaButton:SetDisabled( true ) -- Should have this set to true to have the button disabled.
DermaButton.DoClick = function()
Advertisements:Remove()
net.Start( "points" )
net.SendToServer()
end
DermaButton:SetText( "Close" )
[/code]
Server side
[code]
util.AddNetworkString( "points" )
net.Receive( "points", function( len, ply )
ply:PS_GivePoints( int )
end )
[/code]
You need to replace int with a number.. Also make sure the serverside code is actually being ran.
How do i make the serverside code run.
[QUOTE=xMASTERofWARx;48649354]How do i make the serverside code run.[/QUOTE]
lua/autorun/server
[QUOTE=code_gs;48648939]In the DoClick function, start an empty netmessage and send it to the server. In the receive code serverside, give the points.[/QUOTE]
That sounds like an extremely stupid idea, that allows anyone send as many net messages as they want by using clientside scripts getting as much money as they want.
[editline]10th September 2015[/editline]
A better idea would be giving them points by OPENING the panel from a net message sent from the server. This way they can't farm the money since the panel can be only opened from the server and we don't care if they close the panel, they will either have to close it or leave the server.
Sorry, you need to Log In to post a reply to this thread.