How do i run a client function from server?
You could use SendLua or usermessages. usermessages is recomended but you can use SendLua too
example with SendLua:
ply:SendLua(“MyFunction()”)
example with usermessages wich is more easy:
Server:
[lua]umsg.Start(“MyUsermessage”)
umsg.String(“Hello World!”)
umsg.Long(123456789)
umsg.End()[/lua]
Client:
[lua]usermessage.Hook(“MyUsermessage”, function( um )
MyFunction(umsg:ReadString, umsg:ReadLong())
end)[/lua]
[editline]04:18PM[/editline]
Stupid lua tags dissapearing!!! :argh:
oh sorry ment the other way
Client to server
function look like this.
Client side(from a derma button DoClick =):
function ()
if(Name:GetValue() == nil && Pass:GetValue() == nil)then
else
AddUser(ply,Name:GetValue(),Pass:GetValue())
Print("Username: ".. Name:GetValue().." Password: " .. Pass:GetValue())
DermaPanel:Close()
end
and on the server:
function AddUser(ply,Uname,Pwd)
local db, error2 = mysql.connect("127.0.0.1", "db-username", "db-pass", "db-name")
if (db == 0) then print(tostring(error2) .. "
") return end
insert, isok, error = mysql.query(db, "INSERT INTO users (SteamID,Admin,Nick,Username,Password,Kills,Banmarks) VALUES ('".. ply:SteamID() .."',0,".. Uname ..",".. Pwd ..",0,0)");
if (!isok) then
print(tostring(error) .. "
");
end
local succ, error = mysql.disconnect(db)
if (not succ) then
print( error );
end
end
you will need to use console commands. thats the only way(datastream uses it too. stop saying it dont)
Add some checks so the client cant exploit it
Example:
Client:
[lua]function ()
if(Name:GetValue() == nil && Pass:GetValue() == nil)then
else
RunConsoleCommand(“adduser”, Name:GetValue(), Pass:GetValue())
Print("Username: “… Name:GetValue()…” Password: " … Pass:GetValue())
DermaPanel:Close()
end[/lua]
Server:
[lua]
ConCommand.Add(“adduser”, function(ply, con, args)
– code here. to get username: args[1] and to get pass: args[2]
end)
[/lua]
Thank you very much!