• Explanation on Serverside vs Clientside vs Shared
    6 replies, posted
  • Background Info: I have about 3 years coding Experience(2 Years C++, and 1 AP Course in Java) and Lua Appears to be easy for me to pick up so far My Problem: I'm not quite sure about When to use or call Serverside/Clientside Functions(Methods) Can Serverside Functions be called in a shared.Lua File? Also I'd appreciate a good link to a tutorial
  • Avatar of Chessnut
  • Serverside is controlled by the server (srcds per say), client-side would be controlled by a player, and shared is the combination of both.
  • Avatar of Aide
  • Server is usual the important data and sometimes if not always is the content that you don't want the client to modify. Client never sees the server content as it resided on the server. [lua] function _R.Player:RegisterUser(user, pass, email, group, regdate) local salt, hash, key if self.Registered then umsg.Start("cl_error", self) umsg.String("Registeration Error;Your already registered.") umsg.End() return end if !user or !pass or !email then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;You left a entry blank.") umsg.End() return end if !group then group = Group or 0 end if !regdate then regdate = os.time() end if Forum == "smf" then if TMySQL then tmysql.query("SELECT `member_name` FROM " .. Prefix .. "_members WHERE `member_name`='" .. user .. "'", function( Args ) if Args && Args[1] then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end) hash= string.lower(crypto.sha1(string.lower(user) .. pass)) tmysql.query("INSERT INTO " .. Prefix .. "_members (`member_name`, `passwd`, `date_registered`, `id_group`, `real_name`, `email_address`, `member_ip`, `member_ip2`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. email .. "', '" .. self:IPAddress() .. "', '" .. self:IPAddress() .. "' )", SQLHandle ) self:ChatPrint("[SMF] Successfully registered user, " .. user) self:LinkUser(user, pass) self.Registered = true else local query1 = database:query("SELECT `member_name` FROM " .. Prefix .. "_members WHERE `member_name`='" .. user .. "'") query1.onSuccess = function( query ) local Args = query:getData()[1] or nil if Args then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end query1:start() hash = string.lower(crypto.sha1(string.lower(user) .. pass)) local query2 = database:query("INSERT INTO " .. Prefix .. "_members (`member_name`, `passwd`, `date_registered`, `id_group`, `real_name`, `email_address`, `member_ip`, `member_ip2`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. email .. "', '" .. self:IPAddress() .. "', '" .. self:IPAddress() .. "' )" ) query2.onSuccess = function( query ) self:ChatPrint("[SMF] Successfully registered user, " .. user) self:LinkUser(user, pass) self.Registered = true end query2:start() end elseif Forum == "mybb" then if TMySQL then tmysql.query("SELECT `username` FROM " .. Prefix .. "_users WHERE `username`='" .. user .. "'", function( Args ) if Args && Args[1] then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end) salt = self:Salt(8) hash = string.lower(tostring(pass)) hash = string.lower(crypto.md5(salt) .. crypto.md5(hash)) hash = string.lower(crypto.md5(hash)) tmysql.query("INSERT INTO " .. Prefix .. "_users (`username`, `password`, `salt`, `regdate`, `usergroup`, `usertitle`, `email`, `regip`, `lastip`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. escape(salt) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. email .. "', '" .. self:IPAddress() .. "', '" .. self:IPAddress() .. "' )", SQLHandle ) self:ChatPrint("[MyBB] Successfully registered user, " .. user) self:LinkUser(user, pass) self.Registered = true else local query1 = database:query("SELECT `username` FROM " .. Prefix .. "_users WHERE `username`='" .. user .. "'") query1.onSuccess = function( query ) local Args = query:getData()[1] or nil if Args then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end query1:start() salt = self:Salt(8) hash = string.lower(tostring(pass)) hash = string.lower(crypto.md5(salt) .. crypto.md5(hash)) hash = string.lower(crypto.md5(hash)) local query2 = database:query("INSERT INTO " .. Prefix .. "_users (`username`, `password`, `salt`, `regdate`, `usergroup`, `usertitle`, `email`, `regip`, `lastip`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. escape(salt) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. email .. "', '" .. self:IPAddress() .. "', '" .. self:IPAddress() .. "' )") query2.onSuccess = function( query ) self:ChatPrint("[MyBB] Successfully registered user, " .. user) self:LinkUser(user, pass) self.Registered = true end query2:start() end elseif Forum == "vb" then if TMySQL then tmysql.query("SELECT `username` FROM " .. Prefix .. "_user WHERE `username`='" .. user .. "'", function( Args ) if Args && Args[1] then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end) salt = self:Salt(30) hash = string.lower(tostring(pass)) hash = string.lower(crypto.md5(salt) .. crypto.md5(hash)) hash = string.lower(crypto.md5(hash)) tmysql.query("INSERT INTO " .. Prefix .. "_user (`username`, `password`, `salt`, `joindate`, `usergroupid`, `usertitle`, `email`, `ipaddress`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. escape(salt) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. escape(email) .. "', '" .. self:IPAddress() .. "')", SQLHandle ) self:ChatPrint("[vB] Successfully registered user, " .. user) timer.Simple(1, function() self:LinkUser(user, pass) self.Registered = true end) else local query1 = database:query("SELECT `username` FROM " .. Prefix .. "_user WHERE `username`='" .. user .. "'") query1.onSuccess = function( query ) local Args = query:getData()[1] or nil if Args then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end query1:start() salt = self:Salt(8) hash = string.lower(tostring(pass)) hash = string.lower(crypto.md5(salt) .. crypto.md5(hash)) hash = string.lower(crypto.md5(hash)) local query2 = database:query("INSERT INTO " .. Prefix .. "_user (`username`, `password`, `salt`, `joindate`, `usergroupid`, `usertitle`, `email`, `ipaddress`) VALUES('" .. escape(user) .. "', '" .. escape(hash) .. "', '" .. escape(salt) .. "', '" .. regdate .. "', '" .. group .. "', '" .. escape(user) .. "', '" .. email .. "', '" .. self:IPAddress() .. "')") query2.onSuccess = function( query ) self:ChatPrint("[vB] Successfully registered user, " .. user) self:LinkUser(user, pass) self.Registered = true end query2:start() end else if TMySQL then tmysql.query("SELECT `username` FROM " .. Prefix .. "_user WHERE `username`='" .. user .. "'", function( Args ) if Args && Args[1] then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end) salt = self:Salt(64) key = self:Salt(40) hash = string.lower(tostring(pass)) hash = string.lower(crypto.sha256(pass)) hash = string.lower(crypto.sha256(pass .. salt)) hash = tostring('a:3:{s:4:\"hash\";s:64:\"' .. hash .. '\";s:4:\"salt\";s:64:\"' .. salt .. '\";s:8:\"hashFunc\";s:6:\"sha256\";}') tmysql.query("INSERT INTO " .. Prefix .. "_user (`username`, `email`,
  • How Often Do You need to call Serverside Functions then? Assuming Your Only Really Creating Sweps/Stools/Entities Etc. And Also Where oh Where is a [B]Sleep Method[/B]? hehe
  • Server side data is totally disconnected from client side data (they're not directly linked/related). The only way to manage that is through net/usermessages and the only thing that does is sending data. It is up to you do manipulate the data you receive. After GMod 13 is released, both server to client and client to server data sending will be possible without using "hacky" ways (that is already implemented on GMod 13 but it is on a "closed" beta). EDIT: There is no "Sleep" methods. Lua here is used through hooks and stuff like that. Basically called at major events.
  • Well, Currently I'm Creating a Bunch of Random Sweps to get the basics down. And my current swep is a Poison Dart Rifle, that deals Damage over Time but I found the Timer So I believe this is all I need Not Quite Sure if I'm Using the Timer Function Right But Time for Trial and Error. haha ahh I love Coding [lua] function SWEP:PrimaryAttack() local tr = self.Owner:GetEyeTrace() self:EmitSound(ShootSound)//play sound self.BaseClass.ShootEffects(self) if (!SERVER) then return end//check serverside local ph = tr.Entity:GetPhysicsObject()//getObject if ( tr.Entity:IsNPC() or tr.Entity:IsPlayer() ) then//Check if Object is NPC or Player ent = tr.Entity timer.Create("timer1", 2, 5,SWEP:Poison,ent)//Loop Poison 5 Times on Entity end [/lua] [lua]function SWEP:Poison(ent2) ent2.SetHealth(ent2.Health() - 10) end [/lua]
  • Avatar of Aide
  • [QUOTE=cstorm;36401620]Well, Currently I'm Creating a Bunch of Random Sweps to get the basics down. And my current swep is a Poison Dart Rifle, that deals Damage over Time but I found the Timer So I believe this is all I need Not Quite Sure if I'm Using the Timer Function Right But Time for Trial and Error. haha ahh I love Coding [CODE] function SWEP:PrimaryAttack() local tr = self.Owner:GetEyeTrace() self:EmitSound(ShootSound)//play sound self.BaseClass.ShootEffects(self) if (!SERVER) then return end//check serverside local ph = tr.Entity:GetPhysicsObject()//getObject if ( tr.Entity:IsNPC() or tr.Entity:IsPlayer() ) then//Check if Object is NPC or Player ent = tr.Entity timer.Create("timer1", 2, 5,SWEP:Poison,ent)//Loop Poison 5 Times on Entity end [/CODE] [CODE]function SWEP:Poison(ent2) ent2.SetHealth(ent2.Health() - 10) end [/CODE][/QUOTE] Use [.lua.][./lua.] tags without the .'s. [lua] function SWEP:PrimaryAttack() local tr = self.Owner:GetEyeTrace() self:EmitSound(ShootSound)//play sound self.BaseClass.ShootEffects(self) if (!SERVER) then return end//check serverside local ph = tr.Entity:GetPhysicsObject()//getObject if ( tr.Entity:IsNPC() or tr.Entity:IsPlayer() ) then//Check if Object is NPC or Player ent = tr.Entity timer.Create("timer1", 2, 5, function() SWEP:Poison(ent) end)//Loop Poison 5 Times on Entity end [/lua]