[TTT]
I have a code that tells who left the server and their steamid (made by science), how do I make it also tell the player's karma?
[CODE]util.AddNetworkString("PlyDis")
hook.Add("PlayerDisconnected","playerdisconnected", function(ply)
net.Start("PlyDis")
net.WriteString(ply:Name())
net.WriteString(ply:SteamID())
net.Broadcast()
end)
else
net.Receive("PlyDis", function(len)
local name, id = net.ReadString(), net.ReadString()
chat.AddText( Color(255,0,0), name or "nil", Color(255,255,255)," Has Left The Server. SteamID: ", Color(255,0,0),id or "nil")
end)
end[/CODE]
I'm trying to do [lua]local data = ply:GetPData( "autokick", {} )[/lua] but I'm getting an error saying [lua]bad key to string index (number expected, got string)
[/lua]
What am I doing wrong?
Post an exact error, don't paraphrase your errors.
[QUOTE=RobyYe;39461638]So I need some help with the TTT prep round sound. His code is
[code]resource.AddFile("sound/selected_b01.wav")
local function PlaySounds()
BroadcastLua('surface.PlaySound("selected_b01.wav")')
end
hook.Add("TTTPrepareRound", "Sounds", PlaySounds)[/code]
But for some reason it's not working so we need a little help. Thanks in advance.
[editline]3rd February 2013[/editline]
I am also very new to LUA so I don't know much.[/QUOTE]
Where are you putting this file
Can someone give me a download link to libmysql.dll
I Cannot find it on the SVN's
Question, were can I find gmod wiki but compatible for gmod 13 ??
I found this but it doesn't help me to much.
[url]http://wiki.garrysmod.com/page/Lua/Tutorials[/url]
[editline]3rd February 2013[/editline]
[QUOTE=Cookie Monster!;39464096]Can someone give me a download link to libmysql.dll
I Cannot find it on the SVN's[/QUOTE]
Here: [url]https://dl.dropbox.com/u/16648713/libmysql.zip[/url]
[QUOTE=Matt-;39463826]Post an exact error, don't paraphrase your errors.[/QUOTE]
That's the whole error.
[img]http://puu.sh/1X49u[/img]
Do you need the rest of my script? It's not affected by any other lines though.
[QUOTE=Agent766;39464296]Do you need the rest of my script? It's not affected by any other lines though.[/QUOTE]
Yes just post the rest of the script.
-snip-
I added a hook for ULib to call in the kick command.
The problem is ULX related, I'm pretty sure ply isn't actually a player object. Is there any documentation for ULib?
[url]http://ulyssesmod.net/docs/files/ULib_readme-txt.html[/url]
I'll look through it and try to figure it out. Thanks for getting me on the right track.
Does anyone know how to make it where an attack with a SWEP registers on a certain frame of the swing animation?
[lua] local t = ply:GetPData( "autokick", {} )
MsgN("Value: " .. t .. " Type: " .. type(t))[/lua]
[lua]Value: table: 0x2d619438 Type: string[/lua]
What's going on here...?
[editline]3rd February 2013[/editline]
Turns out SetPData converts the tables to strings. I fixed it by converting them to JSON before storing them.
[editline]3rd February 2013[/editline]
[lua] local pdata = ply:GetPData( "autokick", "{}" )
MsgN( "Value: " .. pdata .. " Type: " .. type(pdata) )
local t = util.JSONToTable(pdata)[/lua]
[code]Value: {} Type: string
lua/autoban.lua:23: bad argument #1 to 'JSONToTable' (string expected, got table)[[/code]
Lua hates me.
Trying to make a custom T weapon ( Grappling Hook):
Placed at gamemodes\terrortown\entities\weapons\weapon_ttt_grapphook
Code is:
[CODE]if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Grappling Hook"
SWEP.Author = "Hellguy"
SWEP.Slot = 2
SWEP.SlotPos = 0
SWEP.IconLetter = "w"
SWEP.Icon = "VGUI/ttt/icon_mp5"
end
SWEP.LimitedStock = true
SWEP.InLoadoutFor = { ROLE_DETECTIVE }
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.CanBuy = { ROLE_DETECTIVE }
SWEP.Base = "weapon_tttbase"
SWEP.AllowDrop = true
SWEP.IsSilent = false
SWEP.NoSights = true
SWEP.WeaponID = ttt_weapon_grapphook
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.EquipMenuData = {
type = "Grappling hook",
desc = "Fly bitch, fly."
};
SWEP.Kind = WEAPON_PISTOL
local sndPowerUp = Sound("rope_hit.wav")
local sndPowerDown = Sound ("shoot_rope.wav")
local sndTooFar = Sound ("to_far.wav")
function SWEP:Initialize()
nextshottime = CurTime()
self:SetWeaponHoldType( "pistol" )
end
function SWEP:Think()
if (!self.Owner || self.Owner == NULL) then return end
if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
self:StartAttack()
elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
self:UpdateAttack()
elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
self:EndAttack( true )
end
if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
self:Attack2()
end
end
function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }
self.Tr = nil
self.Tr = util.TraceLine( trace )
end
function SWEP:StartAttack()
local gunPos = self.Owner:GetShootPos()
local disTrace = self.Owner:GetEyeTrace()
local hitPos = disTrace.HitPos
local x = (gunPos.x - hitPos.x)^2;
local y = (gunPos.y - hitPos.y)^2;
local z = (gunPos.z - hitPos.z)^2;
local distance = math.sqrt(x + y + z);
local distanceCvar = GetConVarNumber("rope_distance")
inRange = false
if distance <= distanceCvar then
inRange = true
end
if inRange then
if (SERVER) then
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
self.Beam:SetParent( self.Owner )
self.Beam:SetOwner( self.Owner )
end
self:DoTrace()
self.speed = 10000
self.startTime = CurTime()
self.endTime = CurTime() + self.speed
self.dt = -1
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
end
self:UpdateAttack()
self.Weapon:EmitSound( sndPowerDown )
else
self.Weapon:EmitSound( sndTooFar )
end
end
function SWEP:UpdateAttack()
self.Owner:LagCompensation( true )
if (!endpos) then endpos = self.Tr.HitPos end
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( endpos )
end
lastpos = endpos
if ( self.Tr.Entity:IsValid() ) then
endpos = self.Tr.Entity:GetPos()
if ( SERVER ) then
self.Beam:GetTable():SetEndPos( endpos )
end
end
local vVel = (endpos - self.Owner:GetPos())
local Distance = endpos:Distance(self.Owner:GetPos())
local et = (self.startTime + (Distance/self.speed))
if(self.dt != 0) then
self.dt = (et - CurTime()) / (et - self.startTime)
end
if(self.dt < 0) then
self.Weapon:EmitSound( sndPowerUp )
self.dt = 0
end
if(self.dt == 0) then
zVel = self.Owner:GetVelocity().z
vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
if( SERVER ) then
local gravity = GetConVarNumber("sv_Gravity")
vVel:Add(Vector(0,0,(gravity/100)*1.5))
if(zVel < 0) then
vVel:Sub(Vector(0,0,zVel/100))
end
self.Owner:SetVelocity(vVel)
end
end
endpos = nil
self.Owner:LagCompensation( false )
end
function SWEP:EndAttack( shutdownsound )
if ( shutdownsound ) then
self.Weapon:EmitSound( sndPowerDown )
end
if ( CLIENT ) then return end
if ( !self.Beam ) then return end
self.Beam:Remove()
self.Beam = nil
end
function SWEP:Attack2()
if (CLIENT) then return end
local CF = self.Owner:GetFOV()
if CF == 90 then
self.Owner:SetFOV(30,.3)
elseif CF == 30 then
self.Owner:SetFOV(90,.3)
end
end
function SWEP:Holster()
self:EndAttack( false )
return true
end
function SWEP:OnRemove()
self:EndAttack( false )
return true
end
function SWEP:PrimaryAttack()
end
function SWEP:SecondaryAttack()
end
[/CODE]
Why is it not showing on buy menu.
[QUOTE=hellguy;39466892]Trying to make a custom T weapon ( Grappling Hook):
Placed at gamemodes\terrortown\entities\weapons\weapon_ttt_grapphook
Code is:
[CODE]if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Grappling Hook"
SWEP.Author = "Hellguy"
SWEP.Slot = 2
SWEP.SlotPos = 0
SWEP.IconLetter = "w"
SWEP.Icon = "VGUI/ttt/icon_mp5"
end
SWEP.LimitedStock = true
SWEP.InLoadoutFor = { ROLE_DETECTIVE }
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.CanBuy = { ROLE_DETECTIVE }
SWEP.Base = "weapon_tttbase"
SWEP.AllowDrop = true
SWEP.IsSilent = false
SWEP.NoSights = true
SWEP.WeaponID = ttt_weapon_grapphook
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.EquipMenuData = {
type = "Grappling hook",
desc = "Fly bitch, fly."
};
SWEP.Kind = WEAPON_PISTOL
local sndPowerUp = Sound("rope_hit.wav")
local sndPowerDown = Sound ("shoot_rope.wav")
local sndTooFar = Sound ("to_far.wav")
function SWEP:Initialize()
nextshottime = CurTime()
self:SetWeaponHoldType( "pistol" )
end
function SWEP:Think()
if (!self.Owner || self.Owner == NULL) then return end
if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
self:StartAttack()
elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
self:UpdateAttack()
elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
self:EndAttack( true )
end
if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
self:Attack2()
end
end
function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }
self.Tr = nil
self.Tr = util.TraceLine( trace )
end
function SWEP:StartAttack()
local gunPos = self.Owner:GetShootPos()
local disTrace = self.Owner:GetEyeTrace()
local hitPos = disTrace.HitPos
local x = (gunPos.x - hitPos.x)^2;
local y = (gunPos.y - hitPos.y)^2;
local z = (gunPos.z - hitPos.z)^2;
local distance = math.sqrt(x + y + z);
local distanceCvar = GetConVarNumber("rope_distance")
inRange = false
if distance <= distanceCvar then
inRange = true
end
if inRange then
if (SERVER) then
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
self.Beam:SetParent( self.Owner )
self.Beam:SetOwner( self.Owner )
end
self:DoTrace()
self.speed = 10000
self.startTime = CurTime()
self.endTime = CurTime() + self.speed
self.dt = -1
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
end
self:UpdateAttack()
self.Weapon:EmitSound( sndPowerDown )
else
self.Weapon:EmitSound( sndTooFar )
end
end
function SWEP:UpdateAttack()
self.Owner:LagCompensation( true )
if (!endpos) then endpos = self.Tr.HitPos end
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( endpos )
end
lastpos = endpos
if ( self.Tr.Entity:IsValid() ) then
endpos = self.Tr.Entity:GetPos()
if ( SERVER ) then
self.Beam:GetTable():SetEndPos( endpos )
end
end
local vVel = (endpos - self.Owner:GetPos())
local Distance = endpos:Distance(self.Owner:GetPos())
local et = (self.startTime + (Distance/self.speed))
if(self.dt != 0) then
self.dt = (et - CurTime()) / (et - self.startTime)
end
if(self.dt < 0) then
self.Weapon:EmitSound( sndPowerUp )
self.dt = 0
end
if(self.dt == 0) then
zVel = self.Owner:GetVelocity().z
vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
if( SERVER ) then
local gravity = GetConVarNumber("sv_Gravity")
vVel:Add(Vector(0,0,(gravity/100)*1.5))
if(zVel < 0) then
vVel:Sub(Vector(0,0,zVel/100))
end
self.Owner:SetVelocity(vVel)
end
end
endpos = nil
self.Owner:LagCompensation( false )
end
function SWEP:EndAttack( shutdownsound )
if ( shutdownsound ) then
self.Weapon:EmitSound( sndPowerDown )
end
if ( CLIENT ) then return end
if ( !self.Beam ) then return end
self.Beam:Remove()
self.Beam = nil
end
function SWEP:Attack2()
if (CLIENT) then return end
local CF = self.Owner:GetFOV()
if CF == 90 then
self.Owner:SetFOV(30,.3)
elseif CF == 30 then
self.Owner:SetFOV(90,.3)
end
end
function SWEP:Holster()
self:EndAttack( false )
return true
end
function SWEP:OnRemove()
self:EndAttack( false )
return true
end
function SWEP:PrimaryAttack()
end
function SWEP:SecondaryAttack()
end
[/CODE]
Why is it not showing on buy menu.[/QUOTE]
replace
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.CanBuy = { ROLE_DETECTIVE }
with
SWEP.CanBuy = { ROLE_TRAITOR,ROLE_DETECTIVE }
Having a proplem with a mysql function
[LUA]
function DB.Query(query, callback)
if CONNECTED_TO_MYSQL then
if DB.MySQLDB and DB.MySQLDB:status() == mysqloo.DATABASE_NOT_CONNECTED then
DB.ConnectToMySQL(RP_MySQLConfig.Host, RP_MySQLConfig.Username, RP_MySQLConfig.Password, RP_MySQLConfig.Database_name, RP_MySQLConfig.Database_port)
end
local query = DB.MySQLDB:query(query)
local data = data or {}
query.onData = function(Q, D)
data = data or {}
data[#data + 1] = D
end
query.onError = function(Q, E)
ErrorNoHalt(E)
if callback then
callback()
end
DB.Log("MySQL Error: ".. E)
end
query.onSuccess = function()
if callback then callback(data) end
end
query:start()
return
end
local Result = sql.Query(query)
if callback then callback(Result) end
return Result
end
[/LUA]
Gives me this error when attempting to use this function
gamemode/server/data.lua:40: attempt to index local 'query' (a nil value)
[QUOTE=skullorz;39466904]replace
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.CanBuy = { ROLE_DETECTIVE }
with
SWEP.CanBuy = { ROLE_TRAITOR,ROLE_DETECTIVE }[/QUOTE]
Great! but now it doesn't work, the weapon spawn, but can't fly around, it gives me
error at line 198, as if Beam is not a value string.
[QUOTE=havejack;39466943]gamemode/server/data.lua:40: attempt to index local 'query' (a nil value)[/QUOTE]
Which line?
[QUOTE=havejack;39466943]Having a proplem with a mysql function
[LUA]
-snip-
[/LUA]
Gives me this error when attempting to use this function
gamemode/server/data.lua:40: attempt to index local 'query' (a nil value)[/QUOTE]
You need to define 'query' before 'if CONNECTED_TO_MYSQL then', as when it's used on the line with 'local Result', it doesn't exist.
[lua]function DB.Query(query, callback)
local query
if CONNECTED_TO_MYSQL then
if DB.MySQLDB and DB.MySQLDB:status() == mysqloo.DATABASE_NOT_CONNECTED then
DB.ConnectToMySQL(RP_MySQLConfig.Host, RP_MySQLConfig.Username, RP_MySQLConfig.Password, RP_MySQLConfig.Database_name, RP_MySQLConfig.Database_port)
end
query = DB.MySQLDB:query(query)
local data = data or {}
query.onData = function(Q, D)
data = data or {}
data[#data + 1] = D
end
query.onError = function(Q, E)
ErrorNoHalt(E)
if callback then
callback()
end
DB.Log("MySQL Error: ".. E)
end
query.onSuccess = function()
if callback then callback(data) end
end
query:start()
return
end
local Result = sql.Query(query)
if callback then callback(Result) end
return Result
end[/lua]
That should fix it.
-snip-
-snip-
Is it possible to have a hidden column or another way to store more data than's visible with just a row in a DListView? I'd like to display players' names without needing to display their Steam IDs too. I can't guarantee that the displayed names will be unique.
Q: If I create a MOTD using Derma Panel can I assign a text file to it? The text file contain all the rules and to don't have to write them in the code, to can just assign the file. I am asking not just because I save lines of code, I ask because I know how to do that using C++.
Why don't you look at how ULX does it?
[QUOTE=Banana Lord.;39464065]Where are you putting this file[/QUOTE]lua/autorun/server
In my thread, I asked about changing a HUD Box if a text is wider than the box and got my answer.
I fixed it and it worked finally..
But somehow it didn't work on a Multiplayer Server..
This is the error:
[code]
[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:190: bad argument #1 to 'GetTextSize' (string expected, got nil)
1. GetTextSize - [C]:-1
2. DoActualHUD - gamemodes/darkrp/gamemode/client/hud.lua:190
3. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:279
4. unknown - gamemodes/darkrp/gamemode/client/hud.lua:394
[/code]
Line 189 and 190:
[lua]
local job2 = LocalPlayer().DarkRPVars.job
Width, Height = surface.GetTextSize(job2)
[/lua]
Answer please. :D
Try:
[lua]
local job2 = LocalPlayer().DarkRPVars.job or ""
Width, Height = surface.GetTextSize(job2)
[/lua]
- snip -
[QUOTE=R@Rdeathmatch;39472337]You diden't understand my question.
[u]Example[/u]
I create a rules.txt file, inside the file are 30 rules. Then I create a MOTD and I want to include the rules.txt file so all the rules from the files will show up on the MOTD.[/QUOTE]what
[QUOTE=RobyYe;39472514]what[/QUOTE]
Basiccally you create 2 files, a Lua and a text. Inside the text file is just text and all that text to be pasted inside the MOTD.
Sorry, you need to Log In to post a reply to this thread.