Anyone know why LocalPlayer():GetVelocity() is so jittery (not updated smoothly) at higher pings when checked clientside? Is there some kind of alternative?
[QUOTE=VIoxtar;52622388]Anyone know why LocalPlayer():GetVelocity() is so jittery (not updated smoothly) at higher pings when checked clientside? Is there some kind of alternative?[/QUOTE]
It's an approximation until the server sends an update. There isn't an alternative.
[QUOTE=code_gs;52622433]It's an approximation until the server sends an update. There isn't an alternative.[/QUOTE]
Thought so. Shit. I guess I can try and create a smoother velocity vector based on EyePos or something. Welp
so I'm making a SWEP using weapon_base, but even though [url]http://wiki.garrysmod.com/page/Structures/SWEP[/url] says that SWEP has a field for drawing the hud ammo counter:
[img]http://i.imgur.com/TekP1EV.png[/img]
but, even if I put it as false it's still drawn on my hud, whether I make it only run on the client or not. every other field that gets modified has their changes reflected, but DrawAmmo seemingly not.
[code]CreateConVar("labelgun_adminonly", 0, FCVAR_REPLICATED, "Sets whether the Label Gun can be spawned by clients")
--forgot what the fuck the variables are?
-- refer to https://wiki.garrysmod.com/page/Structures/SWEP
if CLIENT then
end
SWEP.Base = "weapon_base"
SWEP.Category = "Other"
SWEP.Spawnable = true;
SWEP.AdminOnly = false;
SWEP.PrintName = "Label Gun"
SWEP.Author = "343N"
SWEP.Contact = "no one, you creep"
SWEP.UseHands = true
SWEP.ViewModelFOV = 54
SWEP.ViewModel = "models/weapons/c_crossbow.mdl"
SWEP.WorldModel = "models/weapons/w_crossbow.mdl"
SWEP.Zoomed = false
SWEP.BounceWeaponIcon = false
SWEP.DrawAmmo = false -- this here does nothing
SWEP.Primary.ClipSize = 0
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Delay = 2
SWEP.Primary.TakeAmmo = 0
SWEP.Secondary.ClipSize = 0
SWEP.Animations = {
melee_attack = ACT_VM_HITCENTER;
melee_miss = ACT_VM_MISSCENTER;
primaryattack = PLAYER_ATTACK1;
vmprimaryattack = ACT_VM_PRIMARYATTACK;
reload = PLAYER_RELOAD;
vmreload = ACT_VM_RELOAD;
};[/code]
still being drawn though
[img]http://i.imgur.com/oxDW49G.png[/img]
Not really a solution but I guess you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDShouldDraw]GM:HUDShouldDraw[/url] and check if the currently held weapon by LocalPlayer is your SWEP and hide the ammo counters.
alright, cool thanks, but would anyone know why it's not working? Is DrawAmmo just deprecated now?
I didn't know it ever existed. I always thought you were supposed to hide it with [url]http://wiki.garrysmod.com/page/WEAPON/CustomAmmoDisplay[/url]
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDShouldDraw]GM:HUDShouldDraw[/url] instead
[CODE]function SWEP:Think()
local aoe = self.Owner:GetPos()
local kek = {
start = aoe,
endpos = aoe,
mins = Vector( -20, -20, 0 ),
maxs = Vector( 0, 0, 71 ),
ignoreworld = true
}
local hullTrace = util.TraceHull( kek )
if ( hullTrace.Hit ) then
if ( SERVER ) then
self.Owner:Kill()
end
end
end
[/CODE]
"if (hullTrace.Hit) then" always returns true and kills me instantly despite being in the air and not touching anything. Any help is greatly appreciated~
[QUOTE=Asian Aimbot;52623013][CODE]function SWEP:Think()
local aoe = self.Owner:GetPos()
local kek = {
start = aoe,
endpos = aoe,
mins = Vector( -20, -20, 0 ),
maxs = Vector( 0, 0, 71 ),
ignoreworld = true
}
local hullTrace = util.TraceHull( kek )
if ( hullTrace.Hit ) then
if ( SERVER ) then
self.Owner:Kill()
end
end
end
[/CODE]
"if (hullTrace.Hit) then" always returns true and kills me instantly despite being in the air and not touching anything. Any help is greatly appreciated~[/QUOTE]
It's probably hitting the owner since you're not adding it to the filter.
You can use the Entity value of the trace result if you're unsure what the trace is hitting.
[QUOTE=Gmod4phun;52622630]Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDShouldDraw]GM:HUDShouldDraw[/url] instead[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/HUDShouldDraw]SWEP:HUDShouldDraw[/url]
There is a weapon specific hook for this, however, the ammo display has its own hook.
[QUOTE=AwfulRanger;52623620]It's probably hitting the owner since you're not adding it to the filter.
You can use the Entity value of the trace result if you're unsure what the trace is hitting.[/QUOTE]
I'll check for that, thanks mate
Edit: It was indeed hitting me. I'll adjust it accordingly, thanks a lot!
Hey, i'm trying to return a query data using coroutine but it doesn't work. This is my code :
[code]
function PLY:GetInventory()
local getData
getData = coroutine.create(function(steamid)
local q = IS.db:prepare("SELECT inventory FROM inventory_system WHERE steamid = ?")
q:setString(1, steamid)
function q:onSuccess(data)
coroutine.resume(getData, data)
end
q:start()
return coroutine.yield()
end)
coroutine.resume(getData, self:SteamID())
end
[/code]
why it doesn't work?
[QUOTE=Swarzox;52626402]Hey, i'm trying to return a query data using coroutine but it doesn't work. This is my code :
:snip:
why it doesn't work?[/QUOTE]
Because returning from a coroutine returns the data to whatever resumed it. So here the data is being returned to the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/coroutine/resume]coroutine.resume[/url] in the onSuccess function. To do what you're wanting you'll have to create the coroutine a few levels deeper, such as on whatever function is calling `PLY:GetInventory`
[QUOTE=Swarzox;52626402]Hey, i'm trying to return a query data using coroutine but it doesn't work. This is my code :
why it doesn't work?[/QUOTE]
[b]tl;dr:[/b] You probably don't need coroutines for this; just do your work in the onSuccess function.
Because MySQLOO queries run outside of Lua, in their own C++ threads. Your callback is run by a Think hook in Lua that constantly checks for finished queries, so it won't be run until after your code finishes -- so your function cannot return anything. You can see this for yourself:
[lua]
function RunQuery()
local q = db:query("SELECT 1 + 1 AS sum")
function q:onSuccess()
print("onSuccess: " .. tostring(self:getData()))
end
q:start()
print("Data: " .. tostring(q:getData()))
end
print("--- Calling RunQuery: ---")
RunQuery()
print("---")
[/lua]
[img]http://i.imgur.com/N4W1l8h.png[/img]
As you can see, q:onSuccess() is called when the query finishes -- outside of your function. Now, you could force the server to wait for it with query:wait():
[lua]
function RunQuery()
local q = db:query("SELECT 1 + 1 AS sum")
function q:onSuccess()
print("onSuccess: " .. tostring(self:getData()))
end
q:start()
q:wait()
print("Data: " .. tostring(q:getData()))
return q:getData()
end
print("--- Calling RunQuery: ---")
local data = RunQuery()
print("---")
[/lua]
[img]http://i.imgur.com/12c9kWk.png[/img]
but this will [b]freeze the entire server[/b], possibly for a very long time, until the query finishes. This is bad and you should avoid it at all costs.
So the best solution is to just do your work in the onSuccess callback. You generally won't need coroutines for this except in special cases.
I'm currently trying to get all the props around a center point to move towards that center point relative to their position, if anyone can provide details on how to do this it would be much appreciated.
Sorry for the shitty sketch, but you get the idea.
[URL="https://gyazo.com/b500c19b80ad96911f2522cc7b59cbdf"]https://gyazo.com/b500c19b80ad96911f2522cc7b59cbdf[/URL]
Does someone have a script for stamina? That works!
I found a old one but that doesnt work!
[QUOTE=Scepto;52629985]Does someone have a script for stamina? That works!
I found a old one but that doesnt work![/QUOTE]
This thread is for coding questions, not requests.
[QUOTE=Luni;52628034][b]tl;dr:[/b] You probably don't need coroutines for this; just do your work in the onSuccess function.
Because MySQLOO queries run outside of Lua, in their own C++ threads. Your callback is run by a Think hook in Lua that constantly checks for finished queries, so it won't be run until after your code finishes -- so your function cannot return anything. You can see this for yourself:
[lua]
function RunQuery()
local q = db:query("SELECT 1 + 1 AS sum")
function q:onSuccess()
print("onSuccess: " .. tostring(self:getData()))
end
q:start()
print("Data: " .. tostring(q:getData()))
end
print("--- Calling RunQuery: ---")
RunQuery()
print("---")
[/lua]
[img]http://i.imgur.com/N4W1l8h.png[/img]
As you can see, q:onSuccess() is called when the query finishes -- outside of your function. Now, you could force the server to wait for it with query:wait():
[lua]
function RunQuery()
local q = db:query("SELECT 1 + 1 AS sum")
function q:onSuccess()
print("onSuccess: " .. tostring(self:getData()))
end
q:start()
q:wait()
print("Data: " .. tostring(q:getData()))
return q:getData()
end
print("--- Calling RunQuery: ---")
local data = RunQuery()
print("---")
[/lua]
[img]http://i.imgur.com/12c9kWk.png[/img]
but this will [b]freeze the entire server[/b], possibly for a very long time, until the query finishes. This is bad and you should avoid it at all costs.
So the best solution is to just do your work in the onSuccess callback. You generally won't need coroutines for this except in special cases.[/QUOTE]
I don't want to use query:wait() and I need to return the data from the onSuccess callback... I can't do that?
[QUOTE=Swarzox;52630024]I don't want to use query:wait() and I need to return the data from the onSuccess callback... I can't do that?[/QUOTE]
No, change your function to include a callback, or get the data from the beginning and cache it.
[QUOTE=Swarzox;52630024]I don't want to use query:wait() and I need to return the data from the onSuccess callback... I can't do that?[/QUOTE]
Consider this: an SQL query [b]can[/b] take an hour, if it's complex enough.
For the purpose of this explanation, let's say a single query takes 10 seconds. You can't know what the result of the query are, until the 10 seconds have passed.
The Lua code, however, [i]must[/i] continue running. Since the query takes so long, what we do is start the query and let it run, and just say to it: "give me a call when you're done" (this is OnSuccess). But after we say this, we have to keep moving. We don't know what data we'll get after 10 seconds because our time machine is in the shops today. We simply have [b]no data to return.[/b] We will have the data 10 seconds into the future, but by then, the opportunity to return it to whoever called us has long passed.
This whole concept, of starting a process and letting it run while you do other things, is called [url=https://en.wikipedia.org/wiki/Asynchrony_(computer_programming)]Asynchronous Programming[/url] and can - and does - cause lots of issues to unsuspecting programmers.
[b]The short version is, you can't return data you don't have[/b] and you don't have the data.
[editline]30th August 2017[/editline]
As code_gs said, you should cache the data in a player variable (ply.inventory = whatever), grab it from SQL as soon as the player connects, and keep track of it. You can sync it to/from SQL every so often if you want.
Is it possible to use variables defined in a SWEP base in a derived SWEP? i.e in the SWEP I'm using for my base I have a table variable yet I'm unable to use it in any other SWEPs even when I set SWEP.Base.
[QUOTE=G4MB!T;52632566]Is it possible to use variables defined in a SWEP base in a derived SWEP? i.e in the SWEP I'm using for my base I have a table variable yet I'm unable to use it in any other SWEPs even when I set SWEP.Base.[/QUOTE]
You should be -- could you post code?
[QUOTE=G4MB!T;52634036][B]weapon_rrp_base[/B]
[code]
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.Spawnable = false
SWEP.rrpWeapons = {
attachments = {}
}
[/code]
[B]weapon_rrp_test[/B]
[code]
SWEP.Base = "weapon_rrp_base"
SWEP.rrpWeapons.test = 1337
[/code]
[B]Error[/B]
[code]
weapon_test.lua:3: attempt to index field 'rrpWeapons' (a nil value)
[/code][/QUOTE]
SWEP isn't inherited from its parent at that point, because you've only just set SWEP.Base and it might not have even loaded the specified parent yet
Ye I found that out after posting. I have resorted to putting the `rrpWeapons` base stuff into a separate file which returns that table and I just include it in each weapons. Not ideal but it works.
[QUOTE=G4MB!T;52634336]Ye I found that out after posting. I have resorted to putting the `rrpWeapons` base stuff into a separate file which returns that table and I just include it in each weapons. Not ideal but it works.[/QUOTE]
You can just define the table every time and it will recursively inherit when the weapon is made
So define the table on each weapon (as empty), mutate it like normal and it will be corrected when the inheritance happens?
[QUOTE=G4MB!T;52634555]So define the table on each weapon (as empty), mutate it like normal and it will be corrected when the inheritance happens?[/QUOTE]
No, only define the tables in the base weapon, and whenever you need to put something in them in child weapons. Don't just define a bunch of empty tables unless you need to use them.
Well ye I get that, but each weapon uses it so..
Sorry, you need to Log In to post a reply to this thread.