[QUOTE=NeatNit;52071386]Could someone explain to me the difference between [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetSolid]Entity:SetSolid[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/PhysicsInit]Entity:PhysicsInit[/url]?
and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetMoveType]Entity:SetMoveType[/url] for that matter.[/QUOTE]
SetSolid marks the entity's collision as dirty and sets the entity's solid type, which is used for collision.
PhysicsInit* sets the solid type and creates a new physics object. In fact, all PhysicsInit* does with the solid type is call SetSolid internally, and prevent physics object creation if it's SOLID_NONE.
SetMoveType controls how often the entity is simulated, animated, and how the physics object shadow should move.
[QUOTE=code_gs;52071444]physics object shadow[/QUOTE]
That's another thing I don't quite understand, what exactly is a physics object shadow?
I have multiple questions for you guys today:
1. When handling events like a player using an object or doing any actions, what is the major difference between using a custom function like GM:PlayerUseItem(ply, objectid) and Player:UseItem(id)? Is there an advantage to using more object oriented code like the second one? My bet is that the first one allows to create hooks for later uses.
2. I'm having trouble having a shared item table between the server and the client. In my shared.lua I set up a function to create an item table:
[code]function GM:LoadItem(tbl)
ITEM_DB[tbl.ID] = tbl
print("Loaded "..tbl.Name)
CL_ITEM_DB[tbl.ID] = tbl
CL_ITEM_DB[tbl.ID].OnUse = nil
end[/code]
and here's a sample item:
[code]local ITEM = {}
ITEM.ID = 1
ITEM.Ref = "item_metalchair"
ITEM.Name = "Metal Chair"
ITEM.Description = "You sit on this."
ITEM.Model = "models/props_c17/chair02a.mdl"
if SERVER then
ITEM.OnUse = function(ply)
ply:SpawnItem(ITEM.ID)
end
end
GM:LoadItem(ITEM)[/code]
Obviously both the tables are initialized higher in the code.
My question is : Why can't I use either ITEM_DB or CL_ITEM_DB on the client side?
Thank you for your help.
Also a bonus one : Should all verification be done on the server side or is it safer to verify things both on clientside and serverside? Example: I have a function that sends a request for a ban on a player to the server from an admin. Should I verify that the localplayer is an admin even if I verify him on the server side?
[QUOTE=thejjokerr;52072828]With validation remember this rule:
- Validate on the client for the convenience of the client
- Validate on the server for security
[editline]7th April 2017[/editline]
So the answer is probably, just test if the localplayer is an admin to give quick feedback to the localplayer. It wont be safer no.[/QUOTE]
Alright thank you for your answers, from what I'm understanding from my first questions is that there isn't really a difference between the two types of functions unless I decide to add hooks.
Thank you for your answers!
So it's probably been asked before, but why are NWInts/NWBools etc. so bad according to FP?
[QUOTE=VeXan;52072876]So it's probably been asked before, but why are NWInts/NWBools etc. so bad according to FP?[/QUOTE]
they aren't
but everyone thinks they are because they sync every few ticks or something they think is bad
[QUOTE=MeepDarknessM;52072890]they aren't
but everyone thinks they are because they sync every few ticks or something they think is bad[/QUOTE]
I really like them because it's more convenient than having to write player data to a file or db.
Small amounts of data, mind you.
-automerge fail-
[QUOTE=MeepDarknessM;52072890]they aren't
but everyone thinks they are because they sync every few ticks or something they think is bad[/QUOTE]
How is that better than just syncing once?
[QUOTE=code_gs;52073026]How is that better than just syncing once?[/QUOTE]
what if something accidentally changes the variable in the client state? it would be forever wronng
however there are some places you don't need to use nwvars
[QUOTE=MeepDarknessM;52073052]what if something accidentally changes the variable in the client state? it would be forever wronng
however there are some places you don't need to use nwvars[/QUOTE]
You can change NWVars from the client?
[QUOTE=VeXan;52073075]You can change NWVars from the client?[/QUOTE]
yes, it will stay different until resync
[QUOTE=MeepDarknessM;52073052]what if something accidentally changes the variable in the client state? it would be forever wronng
however there are some places you don't need to use nwvars[/QUOTE]
Just revert it if a sync update is never received from the server.
[editline]7th April 2017[/editline]
So the server will always send initial sync updates to the client, thus the client will know when it's out of sync.
Is there a reason why the following table is not shared even tho it's created in shared.lua?
[code]function GM:LoadItem(tbl)
ITEM_DB[tbl.ID] = tbl
print("Loaded "..tbl.Name)
CL_ITEM_DB[tbl.ID] = tbl
CL_ITEM_DB[tbl.ID].OnUse = nil
end[/code]
I can't use it on the clientside. Thank you.
[QUOTE=bilbasio;52073137]Is there a reason why the following table is not shared even tho it's created in shared.lua?
:snip:
I can't use it on the clientside. Thank you.[/QUOTE]
Shared only means the code will run on both the client and the server. It's like having 2 separate files, with the exact same code, but one runs on the server, one on the client. Any data you set server side will also have to be networked to the client, likewise for accessing client set data server side.
[QUOTE=bigdogmat;52073166]Shared only means the code will run on both the client and the server. It's like having 2 separate files, with the exact same code, but one runs on the server, one on the client. Any data you set server side will also have to be networked to the client, likewise for accessing client set data server side.[/QUOTE]
So if I create a table in the shared file it won't be accessible by the client unless I network it first?
[QUOTE=bilbasio;52073206]So if I create a table in the shared file it won't be accessible by the client unless I network it first?[/QUOTE]
The table itself will be defined, but any data you set on it in a separate state won't be accessible as it's a completely separate table.
[QUOTE=bigdogmat;52073218]The table itself will be defined, but any data you set on it in a separate state won't be accessible as it's a completely separate table.[/QUOTE]
It's strange that I can't access the table from the clientside then if I load items both on the client and server side.
EDIT: Actually after thinking about it I just think that what I'm trying to is impossible, I need to send the item table to the client everytime he connects, I cannot create a table in a shared file and expect the client to have it when he connects.
[QUOTE=thejjokerr;52073285]Dont be too hasty networking. If you are just loading items they should be loaded shared.
Are you sure the item files are being loaded both on server and client? Maybe thats where your problem is.[/QUOTE]
Yeah this was the issue. I can't believe I overlooked this, including the item files in my cl_init did it. Thank you!
[QUOTE=MeepDarknessM;52073078]yes, it will stay different until resync[/QUOTE]
That seems incredibly ridiculous from a security point of view.
I'm getting a strange error and I've been looking at this file for 30 minutes now trying to find my mistake : [url]https://pastebin.com/pd7U7H3C[/url]
I pasted the error at the end of the file. I'm sure I forgot something somewhere but I can't seem to find it so maybe a fresh pair of eyes will spot it.
[QUOTE=bilbasio;52073504]I'm getting a strange error and I've been looking at this file for 30 minutes now trying to find my mistake : [url]https://pastebin.com/pd7U7H3C[/url]
I pasted the error at the end of the file. I'm sure I forgot something somewhere but I can't seem to find it so maybe a fresh pair of eyes will spot it.[/QUOTE]
You can't make a table entry local. Just do PANEL.Ent = {}.
[QUOTE=bilbasio;52073504]I'm getting a strange error and I've been looking at this file for 30 minutes now trying to find my mistake : [url]https://pastebin.com/pd7U7H3C[/url]
I pasted the error at the end of the file. I'm sure I forgot something somewhere but I can't seem to find it so maybe a fresh pair of eyes will spot it.[/QUOTE]
You can't define a table field as local, remove the local on line 2
You're also going to get this error on the lines inside PANEL:Init
Edit: ninja'd
[editline]7th April 2017[/editline]
You're also going to get a few other errors, such as on line 28 because `daccept` isn't defined until the panel has initialized
Thank you to both of you, I'm cleaning up my old gamemode and it's firing errors left and right for things that I was sure was working before.
[QUOTE=thejjokerr;52073438]The server will always have the right value IIRC. Thus being secure. The client will just be fooled into thinking otherwise.
Basically it's like using cheat engine to change the numbers on your screen while nothing is really changing on the server.[/QUOTE]
Ohhh, okay. I thought the user could actually manipulate the NWVar. I suppose I read something wrong.
How can I make a ClientsideModel change color? (This isn't for use in a DModelPanel)
:SetColor() has no effect from what I can tell, neither on creation nor upon each draw.
I also attempted to use render.SetColorModulation(), however that didn't quite work as intended:
[thumb]http://i.imgur.com/8lRb5Mi.jpg[/thumb]
So yesterday I had trouble with having an item table transfer to clientside which I managed to fix by including all the necessary files to the client. It worked great for a while but now it just stopped working all of the sudden and after spending hours trying to fix it I decided to turn to you guys.
Here's my shared.lua where I create the item database for the client and the server :
[code]function GM:LoadItem(tbl)
ITEM_DB[tbl.ID] = tbl
print("Loaded "..tbl.Name)
end[/code]
ITEM_DB is initialized in shared.lua
In my console, every item loads on the server and on the client, even after putting a PrintTable it outputs the item table like it should. The problem starts when I try to use ITEM_DB on the clientside for example in cl_init.lua :
[code]concommand.Add("testdb", function()
PrintTable(ITEM_DB)
end)[/code]
This outputs nothing so the table doesn't get to cl_init for some reason. I tried initializing ITEM_DB in cl_init instead of shared and it worked only for the host(hosted a listen server for test)
I'm pretty much out of options so any help would be greatly appreciated. I included shared.lua and cl_init.lua just in case you guys wanted to see beyond these lines : [url=https://pastebin.com/DPthvqFz]shared.lua[/url] [url=https://pastebin.com/caZvycBf]cl_init.lua[/url]
Thank you
[editline]8th April 2017[/editline]
I guess at this point I'm just going to forget about a shared file and do everything separately.
So I guess I'm just really good at getting these weird bugs but for some reason this code works half the time : [code]if SERVER then
util.AddNetworkString("rank")
function Player:SetRank(int)
self.Rank = int
net.Start("rank")
net.WriteInt(int, 16)
net.Send(self)
end
end
if CLIENT then
net.Receive("rank", function()
LocalPlayer().Rank = net.ReadInt(16)
end)
end
function Player:IsAdmin()
return self.Rank >= 5
end[/code]
It works except when I load the player profile, on the clientside it just outputs nil. When I manually set my rank with a console command it works. I even put LocalPlayer().Rank = 1 in cl_init but even that outputs rank as nil for some reason. Is the fact that I test from a listen server keeps screwing with clientside stuff?
[QUOTE=bilbasio;52076744]rank stuff[/QUOTE]
for inherent player properties such as rank that need to be accurate and displayed on scoreboards and such on clients, it's much better to use nw/nw2 vars rather than manually networking it every time.
[URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/includes/extensions/player_auth.lua"]see here for example[/URL]
Sorry, you need to Log In to post a reply to this thread.