• What do you need help with V4
    639 replies, posted
I'm new to this SQL stuff, and have no clue what I'm doing wrong. I've been trying a lot, and sadly I don't know what you're trying to point out :/ [editline]11th March 2012[/editline] Oh wait, I see what I did wrong. [editline]11th March 2012[/editline] Hm, that didn't even work. [lua]sql.Query("UPDATE Wanted SET Crime = '" .. Crime .. "', Stage = '" .. Stage .. "' WHERE SuspectID = " .. tonumber(ID) .. "") [/lua] [editline]11th March 2012[/editline] Stebbzor told me to use print(sql.LastError()) and it gave me this near "s": syntax error
[QUOTE=Persious;35095695]I'm new to this SQL stuff, and have no clue what I'm doing wrong. I've been trying a lot, and sadly I don't know what you're trying to point out :/ [editline]11th March 2012[/editline] Oh wait, I see what I did wrong. [editline]11th March 2012[/editline] Hm, that didn't even work. [lua]sql.Query("UPDATE Wanted SET Crime = '" .. Crime .. "', Stage = '" .. Stage .. "' WHERE SuspectID = " .. tonumber(ID) .. "") [/lua] [editline]11th March 2012[/editline] Stebbzor told me to use print(sql.LastError()) and it gave me this near "s": syntax error[/QUOTE] The hint was you weren't using quotes for the id. [editline]...[/editline] I guess I was wrong..
Did I have to? As the ID is a int?
No, you don't. Assuming ID is defined somewhere.
Yeah, ID is defined as argument 3, which definetly gets recieved. [editline]11th March 2012[/editline] Might it be because the "Crime" and "Stage" have spaces?
[QUOTE=Persious;35095695]I'm new to this SQL stuff, and have no clue what I'm doing wrong. I've been trying a lot, and sadly I don't know what you're trying to point out :/ [editline]11th March 2012[/editline] Oh wait, I see what I did wrong. [editline]11th March 2012[/editline] Hm, that didn't even work. [lua]sql.Query("UPDATE Wanted SET Crime = '" .. Crime .. "', Stage = '" .. Stage .. "' WHERE SuspectID = " .. tonumber(ID) .. "") [/lua] [editline]11th March 2012[/editline] Stebbzor told me to use print(sql.LastError()) and it gave me this near "s": syntax error[/QUOTE] Did you escape your strings? An unescaped string with a quote can mess up your query (along with leaving you vulnerable to sql injection).
Some kind of detection for an entity to detect if another entity is within x radius to it.
[QUOTE=_nonSENSE;35099596]Did you escape your strings? An unescaped string with a quote can mess up your query (along with leaving you vulnerable to sql injection).[/QUOTE] Could you explain more about escaping a string? I don't think I did that.
[QUOTE=Persious;35100797]Could you explain more about escaping a string? I don't think I did that.[/QUOTE] [lua]sql.Query("UPDATE Wanted SET Crime = '" .. sql.SQLStr( Crime ) .. "', Stage = '" .. sql.SQLStr( Stage ) .. "' WHERE SuspectID = " .. tonumber(ID) .. "")[/lua]
Okay, still haven't tested it as I'm going to sleep. But if I updated it, and got it back to the DTextEntry, wouldn't it show up as "Some random text here" (With the quotes)
If you are using sql.SQLStr you don not need a '. [lua]sql.Query("UPDATE Wanted SET Crime = " .. sql.SQLStr( Crime ) .. ", Stage = " .. sql.SQLStr( Stage ) .. " WHERE SuspectID = " .. tonumber(ID) .. ")[/lua] This will work.
[QUOTE=mil0001;35100258]Some kind of detection for an entity to detect if another entity is within x radius to it.[/QUOTE] [lua] local function IsInRadius( ent ) local cDist = math.huge; local cTarg = nil; if( ValidEntity( ent ) && ent != LocalPlayer() ) then if( (LocalPlayer():GetPos() - ent:GetPos()):Length() < cDist ) then cDist = (LocalPlayer():GetPos() - ent:GetPos()):Length(); cTarg = ent; end end return {cDist, cTarg}; end [/lua]
[QUOTE=mil0001;35100258]Some kind of detection for an entity to detect if another entity is within x radius to it.[/QUOTE] [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf7e1-2.html?title=Ents.FindInSphere]Ents.FindInSphere [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Uh, this is getting confusing. Now, for a odd reason, everything turns nil when I use print(sql.LastError())
Print the query. You should have done this in the first place. If there are no obvious errors in the query, then we can go from there and check what else could be wrong.
Hello, I am currently running AppleJack Cider gamemode, and I have quite the predicament..the doors will not lock if anyone has a solution please post it, can't seem to figure it out Even the doors on the DoorsToolv2 won't lock, except the lab elevator door
Not really explicitly Lua-related, but, I'll ask here for lack of anywhere else to ask. If I recall correctly, the env_fire entity can no longer be resized with the SetKeyValue control (it doesn't register the changes), meaning that I need a Lua fire entity to take its place. Does anyone happen to have a fire entity I can utilize? I'm not that great with sprite/effect design, and would prefer not having to make one if I don't have to. All I really need is the actual effect - the functionality I can do myself. If not, that's okay, too. I'd just prefer this, if it's possible. :v:
I'm getting a [B]"[lua\test.lua:25] attempt to index global 'SWEP' (a nil value)"[/B] error from this block. Can anyone figure out wtf I'm doing wrong other than the obvious everything? [lua] function SWEP:PrimaryAttack() <---------- Line 25 if !self:CanPrimaryAttack() then return end local eyetrace = self.Owner:GetEyeTrace(); if !eyetrace.Entity:IsPlayer() then return end local distx = eyetrace.Entity:GetPos().x - self.Owner:GetPos().x local disty = eyetrace.Entity:GetPos().y - self.Owner:GetPos().y local distz = eyetrace.Entity:GetPos().z - self.Owner:GetPos().z local distLong = (distx*distx)+(disty*disty)+(distz*distz) local dist = math.sqrt(distLong) if dist > 200 then self.Owner:PrintMessage(HUD_PRINTCENTER, "Too Far Away!") return end if eyetrace.Entity:IsPlayer() then self.Weapon:EmitSound("Weapon_StunStick.Activate") self:tasePlayer(eyetrace.Entity) SetGlobalInt("mReloadTimer",CurTime()+10) SetGlobalInt("tazedTimer",CurTime()+3) end end [/lua]
[QUOTE=NnyAskC;35118550]I'm getting a [B]"[lua\test.lua:25] attempt to index global 'SWEP' (a nil value)"[/B] error from this block. Can anyone figure out wtf I'm doing wrong other than the obvious everything? [lua] function SWEP:PrimaryAttack() <---------- Line 25 if !self:CanPrimaryAttack() then return end local eyetrace = self.Owner:GetEyeTrace(); if !eyetrace.Entity:IsPlayer() then return end local distx = eyetrace.Entity:GetPos().x - self.Owner:GetPos().x local disty = eyetrace.Entity:GetPos().y - self.Owner:GetPos().y local distz = eyetrace.Entity:GetPos().z - self.Owner:GetPos().z local distLong = (distx*distx)+(disty*disty)+(distz*distz) local dist = math.sqrt(distLong) if dist > 200 then self.Owner:PrintMessage(HUD_PRINTCENTER, "Too Far Away!") return end if eyetrace.Entity:IsPlayer() then self.Weapon:EmitSound("Weapon_StunStick.Activate") self:tasePlayer(eyetrace.Entity) SetGlobalInt("mReloadTimer",CurTime()+10) SetGlobalInt("tazedTimer",CurTime()+3) end end [/lua][/QUOTE] The Lua file wants to be in lua/weapons/<name>/init.lua
Okay, apperantly the only thing that works now is inserting. Deleting and updating does not update after doing so. [editline]13th March 2012[/editline] Ah, got it all working now. I have no clue what caused it, but somehow I fixed it.
What code gets all props count in server?
[QUOTE=airidas338;35120994]What code gets all props count in server?[/QUOTE] [lua]print(#ents.FindByClass("prop_physics"))[/lua]
How would one go about making a color flash from a set color to red and back when the player is low on health? Maybe one blink every second or two. I always have a rough time with transitions like this...
What's a better MySQL module to use? tmysql or mysqloo?
[lua] local f = 0.5+0.5*math.sin(math.pi*2*CurTime()*BlinksPerSec) local color = color1*f+color2*(1-f) [/lua] Something along those lines
Is there a way to make player invisible? Like only 25% visibility.
Find the player entity on the client and use SetColor(255,255,255,25)? (or in beta: SetColor(Color(255,255,255,25)).
[QUOTE=ralle105;35122495][lua] local f = 0.5+0.5*math.sin(math.pi*2*CurTime()*BlinksPerSec) local color = color1*f+color2*(1-f) [/lua] Something along those lines[/QUOTE] Thank you sir. For those who are interested this is what the example translates to: [lua] local col1, col2, newCol, curHP col1 = Color(155,155,155, 255) col2 = Color(225, 225, 225, 255) curHP = ply:Health() if (curHP < 25) then local f = .5+.5*math.sin(math.pi*2*CurTime()) newCol = Color(col1.r*f + col2.r*(1-f), col1.g*f + col2.g*(1-f), col1.b*f + col2.b*(1-f), 255) else newCol = col1 end [/lua]
[QUOTE=Drakehawke;35122494]What's a better MySQL module to use? tmysql or mysqloo?[/QUOTE] Personal preference.
[QUOTE=_nonSENSE;35122673]Find the player entity on the client and use SetColor(255,255,255,25)? (or in beta: SetColor(Color(255,255,255,25)).[/QUOTE] If it were %25 visibility then he would want SetColor(255, 255, 255, 65). Since ~63 is a 4rth of 255 (255 being maximum alpha)
Sorry, you need to Log In to post a reply to this thread.