[QUOTE=thejjokerr;39472771]He wasn't talking to you. Look at who he quoted.[/QUOTE]
Oh. But still can someone help me ?
R@R, use file.Read
Can anyone help me with my problem
[QUOTE=Persious;39472980]R@R, use file.Read[/QUOTE]
Ok, thanks I will try it.
Another question, I start learning LUA from here (today) is this right or is to old ??
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7a06.html[/url]
[QUOTE=hellguy;39467267]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]
Line 198 is
[code]end[/code]
so if you changed spacing I can't help you. Also it would be helpful for the entire (exact) error.
If you are talking about
[code]
self.Beam:Remove()
self.Beam = nil
[/code]
then it should be an entity (the rope you see) not a string.
[editline]4th February 2013[/editline]
-Snip- My problem made me feel like a dumb ass when I looked at the error >.>
[QUOTE=Pandaman09;39473798]Line 198 is
[code]end[/code]
so if you changed spacing I can't help you. Also it would be helpful for the entire (exact) error.
If you are talking about
[code]
self.Beam:Remove()
self.Beam = nil
[/code]
then it should be an entity (the rope you see) not a string.
[editline]4th February 2013[/editline]
I am trying to fix an addon from 2009 yeah!
Does anyone know what:
[code]module( "dhradar", package.seeall )[/code]
does?
From what i understand couldn't you just create a global table called dhradar?[/QUOTE]
how do I turn it into an entity?
[QUOTE=hellguy;39474741]how do I turn it into an entity?[/QUOTE]
What do you mean how did it turn into an entity? self.Beam is an entity created
[code]
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
[/code]
I would also suggest you change:
SWEP.Author = "Hellguy"
back to the original author since this is not your swep and that you haven't changed a thing.
[QUOTE=Pandaman09;39474866]What do you mean how did it turn into an entity? self.Beam is an entity created
[code]
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
[/code]
I would also suggest you change:
SWEP.Author = "Hellguy"
back to the original author since this is not your swep and that you haven't changed a thing.[/QUOTE]
Changed it to Darkfortune got it from ([url]http://www.garrysmod.org/downloads/?a=view&id=63573[/url]), my sincere apologizes. Now, how do I get it to work?.. I think we need to implement "function SWEP:PrimaryAttack()" to make the beam grab at what you're looking at and "function SWEP:SecondaryAttack()" to make it pull you, but I don't know how.
Here's the code again[CODE]if SERVER then
resource.AddFile("materials/vgui/ttt/icon_zeph_ghook.vmt")
resource.AddFile("materials/vgui/ttt/icon_zeph_gook.vtf")
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Grappling Hook"
SWEP.Author = "Darkfortune"
SWEP.Slot = 6
SWEP.IconLetter = "w"
SWEP.Icon = "VGUI/ttt/icon_zeph_ghook"
end
SWEP.LimitedStock = true
SWEP.Primary.Automatic = false
SWEP.InLoadoutFor = { ROLE_DETECTIVE }
SWEP.CanBuy = { ROLE_TRAITOR,ROLE_DETECTIVE }
SWEP.Base = "weapon_tttbase"
SWEP.AllowDrop = true
SWEP.IsSilent = false
SWEP.NoSights = true
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.Primary.Sound = Sound("rope_hit.wav")
SWEP.EquipMenuData = {
type = "Grappling hook",
desc = "Fly bitch, fly."
};
SWEP.Kind = WEAPON_EQUIP
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]
Got a MySQL Proplem with this lua script
[LUA]
function DB.QueryValue(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
query.onData = function(Q, D)
data = D
end
query.onSuccess = function()
for k,v in pairs(data or {}) do
callback(v)
return
end
callback()
end
query.onError = function(Q, E) callback() DB.Log("MySQL Error: ".. E) ErrorNoHalt(E) end
query:start()
return
end
local val = sql.QueryValue(query)
if callback then callback(val) end
return val
end
[/LUA]
Heres the function that calls it
[LUA]
function DB.StoreSalary(ply, amount)
ply:SetSelfDarkRPVar("salary", math.floor(amount))
DB.Query([[REPLACE INTO darkrp_player VALUES(]] ..
ply:UniqueID() .. [[, ]] ..
(ply.DarkRPVars.rpname and sql.SQLStr(ply.DarkRPVars.rpname) or "NULL") .. [[, ]] ..
amount .. [[, ]] ..
(ply.DarkRPVars.money or GAMEMODE.Config.startingmoney) .. [[);]])
return amount
end
function DB.RetrieveSalary(ply, callback)
if not IsValid(ply) then return 0 end
if ply.DarkRPVars.salary then return callback and callback(ply.DarkRPVars.salary) end -- First check the cache.
DB.QueryValue("SELECT `salary` FROM darkrp_player WHERE uid = '" .. ply:UniqueID() .. "';", function(r)
local normal = GAMEMODE.Config.normalsalary
if not r then
ply:SetSelfDarkRPVar("salary", normal)
callback(normal)
else
callback(r)
end
end)
end
[/LUA]
I get this error in return "gamemode/server/data.lua:73: attempt to index local 'query' (a nil value)"
and it will work with bots no proplem, its the players that the proplem is......
[QUOTE=havejack;39475190]Got a MySQL Proplem with this lua script
I get this error in return "gamemode/server/data.lua:73: attempt to index local 'query' (a nil value)"
and it will work with bots no proplem, its the players that the proplem is......[/QUOTE]
[code]
local query = DB.MySQLDB:query(query)
[/code]
Read that line... does it make sense to you?
[code]
local querySend = DB.MySQLDB:query(query)
[/code]
[Lua]
function DB.QueryValue(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 querySend = DB.MySQLDB:query(query)
local data
querySend.onData = function(Q, D)
data = D
end
querySend.onSuccess = function()
for k,v in pairs(data or {}) do
callback(v)
return
end
callback()
end
querySend.onError = function(Q, E) callback() DB.Log("MySQL Error: ".. E) ErrorNoHalt(E) end
querySend:start()
return
end
local val = sql.QueryValue(query)
if callback then callback(val) end
return val
end
[/Lua]
That should fix your error. If not then it might be that your calling a "nil" query so you would have to say:
if not IsValid(query) then return end
Ok I replaced function SWEP:StartAttack() with
function SWEP:PrimaryAttack()
Now when I shot 1 it gives me the error on line 57, attempt to call method "Secondary2" a nil value.
Changing StartAttack With PrimaryAttack is pointless since
[code]
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
[/code]
checks to see if a player uses the weapon (primary attack)
Got it to work! Thank you very much... now another question.. I put this at a golden deagle shared.lua [CODE]function SWEP:PrimaryAttack()
if ply:IsActiveTraitor() then ply:TakeDamage()
end[/CODE]
So it should give damage to traitors, but how do I make it not give damage to detective and innos?
I am looking for a better way of making DPropertySheet elements.
Instead of using panels, maybe some custom tabs, so I don't have to put everything onto panel ?
Any ideas ?
Alright so basically I created a 3d2d drawing framework: [url]http://paste.ee/p/HueVC[/url]
Then I started work on a sand game using it: [url]http://paste.ee/p/jEdUD[/url]
However the issue is that it seems like every other object collides and I can't seem to figure out why.
[QUOTE=Netheous;39477834]I am looking for a better way of making DPropertySheet elements.
Instead of using panels, maybe some custom tabs, so I don't have to put everything onto panel ?
Any ideas ?[/QUOTE]
Can you please explain?
I'm trying to create a new entity in a player's pockets for DarkRP. Here's the code I'm using:
local water = ents.Create( "water_bottle" ) water:SetNoDraw(true) water:SetPos(ply:GetPos()) water:Spawn() water:GetPhysicsObject():EnableMotion(false) water:SetCollisionGroup(COLLISION_GROUP_WORLD) water.PhysgunPickup = false water.PlayerUse = false umsg.Start( "Pocket_AddItem", ply ) umsg.Short( water:EntIndex() ) umsg.End() table.insert( ply:GetTable().Pocket, water )
The problem is that by the time the client calls the "Pocket_AddItem" hook, the entity doesn't exist on the client yet. How can I either force the server to send the entity to the client or do this in a better way?
[QUOTE=Agent766;39480270]I'm trying to create a new entity in a player's pockets for DarkRP. Here's the code I'm using:
local water = ents.Create( "water_bottle" ) water:SetNoDraw(true) water:SetPos(ply:GetPos()) water:Spawn() water:GetPhysicsObject():EnableMotion(false) water:SetCollisionGroup(COLLISION_GROUP_WORLD) water.PhysgunPickup = false water.PlayerUse = false umsg.Start( "Pocket_AddItem", ply ) umsg.Short( water:EntIndex() ) umsg.End() table.insert( ply:GetTable().Pocket, water )
The problem is that by the time the client calls the "Pocket_AddItem" hook, the entity doesn't exist on the client yet. How can I either force the server to send the entity to the client or do this in a better way?[/QUOTE]
You need to wait upto two ticks before expecting the client to have fully networked the entity. If an entity fails to get networked to the client after two ticks [or becomes unnetworked], then the client will get kicked.
After waiting two ticks on the server, then send the usermessage to the client.
If any one knows about TTT, would anyone know how to make a specific group get a specific weapon (E.G.) i want my donator group to spawn with lightsabers, anyone know?
I already have the Lightsaber code, i am looking for the code to give it to donors only, and are there anythings in the lightsaber code that i need to add/remove to make it work?
[QUOTE=zzaacckk;39481349]You need to wait upto two ticks before expecting the client to have fully networked the entity. If an entity fails to get networked to the client after two ticks [or becomes unnetworked], then the client will get kicked.
After waiting two ticks on the server, then send the usermessage to the client.[/QUOTE]
wrapped the usermessage in a timer.Simple and it worked perfectly. Thanks!
I try using ply:IsSpec and ply:TakeDamage , but garry'smod keep saying "attempt to call global 'ply' a nill value" here's what I'm trying to do:
[CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "ply", function()
if ply:IsSpec() then return end
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end)[/CODE]
[QUOTE=hellguy;39482402]I try using ply:IsSpec and ply:TakeDamage , but garry'smod keep saying "attempt to call global 'ply' a nill value" here's what I'm trying to do:
[CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "ply", function()
if ply:IsSpec() then return end
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end)[/CODE][/QUOTE]
change
[code]hook.Add("TTTBeginRound", "ply", function()[/code]
to
[code]hook.Add("TTTBeginRound", "my unique name", function( ply )[/code]
where "my unique name" should be a unique name for this specific hook. A name which no other hook has.
That is assuming that TTTBeginRound has a ply argument. It looks like it doesn't, but I've never coded for TTT so I don't know. If it doesn't have a ply argument, you'd need to do this
[code]hook.Add("TTTBeginRound", "my unique name", function()
for k,ply in pairs( player.GetAll() ) do
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end[/code]
[QUOTE=Divran;39482414]change
[code]hook.Add("TTTBeginRound", "ply", function()[/code]
to
[code]hook.Add("TTTBeginRound", "my unique name", function( ply )[/code]
where "my unique name" should be a unique name for this specific hook. A name which no other hook has.
That is assuming that TTTBeginRound has a ply argument. It looks like it doesn't, but I've never coded for TTT so I don't know. If it doesn't have a ply argument, you'd need to do this
[code]hook.Add("TTTBeginRound", "my unique name", function()
for k,v in pairs( player.GetAll() ) do
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end[/code][/QUOTE]
The error : [ERROR] addons/vipspawn/lua/autorun/client/vipspawn.lua:7: attempt to index local 'ply' (a nil value)
1. fn - addons/vipspawn/lua/autorun/client/vipspawn.lua:7
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:139
4. Function - gamemodes/terrortown/gamemode/cl_init.lua:215
5. unknown - lua/includes/modules/usermessage.lua:87
Code I'm using:
[CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "vipspawnwep", function( ply )
for k,v in pairs( player.GetAll() ) do
if ply:IsSpec() then return end
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end)[/CODE]
I'm having trouble getting sounds to play for the Jihad bomb on my TTT server. It downloads the sounds properly. Here's my shared.lua
[code]
if SERVER then
AddCSLuaFile("shared.lua")
resource.AddFile("sound/siegeplucky/jihad.wav")
resource.AddFile("sound/siegeplucky/big_explosion.wav")
resource.AddFile("materials/vgui/ttt/icon_plucky_c4.vmt")
resource.AddFile("materials/vgui/ttt/icon_plucky_c4_vtf")
resource.AddFile("models/weapons/v_pluckygaming_jb.mdl")
resource.AddFile("models/weapons/w_pluckygaming_jb.mdl")
util.PrecacheSound("siegeplucky/jihad.wav")
util.PrecacheSound("siegeplucky/big_explosion.wav")
end
if CLIENT then
SWEP.PrintName = "Jihad"
SWEP.Slot = 7
SWEP.EquipMenuData = {
type = "item_weapon",
name = "Jihad Bomb",
desc = "Left click goes boom!\n\nONLY USABLE AT 20 HP OR BELOW"
};
SWEP.Icon = "vgui/ttt/icon_plucky_c4"
end
SWEP.Base = "weapon_tttbase"
SWEP.HoldType = "slam"
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR}
SWEP.WeaponID = AMMO_C4
SWEP.ViewModel = Model("models/weapons/v_pluckygaming_jb.mdl")
SWEP.WorldModel = Model("models/weapons/w_pluckygaming_jb.mdl")
SWEP.DrawCrosshair = false
SWEP.ViewModelFlip = false
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 5.0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.NoSights = true
function SWEP:Reload()
end
function SWEP:Think()
end
function SWEP:Initialize()
util.PrecacheSound("siegeplucky/jihad.wav")
util.PrecacheSound("siegeplucky/big_explosion.wav")
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 3)
local effectdata = EffectData()
effectdata:SetOrigin(self.Owner:GetPos())
effectdata:SetNormal(self.Owner:GetPos())
effectdata:SetMagnitude(8)
effectdata:SetScale(1)
effectdata:SetRadius(76)
util.Effect("Sparks", effectdata)
self.BaseClass.ShootEffects(self)
if (SERVER) then
timer.Simple(2, function() self:Asplode() end)
self.Owner:EmitSound("siegeplucky/jihad.wav")
end
end
function SWEP:Asplode()
local k, v
local ent = ents.Create("env_explosion")
ent.SetPos(self.Owner:GetPos())
ent:SetOwner(self.Owner)
ent:SetKeyValue("iMagnitude", "150")
ent:Spawn()
ent:Fire("Explode", 0, 0)
ent:EmitSound("siegeplucky/big_explosion.wav", 200, 100)
self:Remove()
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + 3)
local TauntSound = Sound("siegeplucky/jihad.wav")
self.Weapon:EmitSound(TauntSound)
end
[/code]
The weirdest part? big_explosion.wav plays just fine. It's only jihad.wav that gives me this error:
[code]Failed to load sound "siegeplucky\jihad.wav", file probably missing from disk/repository[/code]
Also of note is that the bomb doesn't explode anymore. It arms and beeps, but then never Asplodes.
[QUOTE=hellguy;39482453]The error : [ERROR] addons/vipspawn/lua/autorun/client/vipspawn.lua:7: attempt to index local 'ply' (a nil value)
1. fn - addons/vipspawn/lua/autorun/client/vipspawn.lua:7
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:139
4. Function - gamemodes/terrortown/gamemode/cl_init.lua:215
5. unknown - lua/includes/modules/usermessage.lua:87
Code I'm using:
[CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "vipspawnwep", function( ply )
for k,v in pairs( player.GetAll() ) do
if ply:IsSpec() then return end
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end)[/CODE][/QUOTE]
He did the same mistake you did.
At the loop, you declared the value to be called v but you are trying to call it as ply.
Basically: instead of for k, v type for k, ply
[QUOTE=Leystryku;39483066]He did the same mistake you did.
At the loop, you declared the value to be called v but you are trying to call it as ply.
Basically: instead of for k, v type for k, ply[/QUOTE]
awesome, now the last step, it says the method "Give" is a nil value.
By the way, is this function right? (should only hurt traitors)
[CODE]function SWEP:PrimaryAttack()
for k, ply in pairs( player.GetAll() ) do
if ( !self:CanPrimaryAttack() ) then return end
self:TakePrimaryAmmo( 1 )
self.Owner:ViewPunch( Angle( -1, 0, 0 ) )
if not ply:IsActiveTraitor() then return end
if ply:IsActiveTraitor() then self:ShootBullet( 150, 1, 0.01 )
end[/CODE]
[QUOTE=hellguy;39482453]The error : [ERROR] addons/vipspawn/lua/autorun/client/vipspawn.lua:7: attempt to index local 'ply' (a nil value)
1. fn - addons/vipspawn/lua/autorun/client/vipspawn.lua:7
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:139
4. Function - gamemodes/terrortown/gamemode/cl_init.lua:215
5. unknown - lua/includes/modules/usermessage.lua:87
Code I'm using:
[CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "vipspawnwep", function( ply )
for k,v in pairs( player.GetAll() ) do
if ply:IsSpec() then return end
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end)[/CODE][/QUOTE]
Sorry, I made a small mistake. Here's the fixed code
[code]hook.Add("TTTBeginRound", "my unique name", function()
for k,ply in pairs( player.GetAll() ) do
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end[/code]
EDIT: Ninja'd
[QUOTE=Divran;39483150]Sorry, I made a small mistake. Here's the fixed code
[code]hook.Add("TTTBeginRound", "my unique name", function()
for k,ply in pairs( player.GetAll() ) do
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end[/code]
EDIT: Ninja'd[/QUOTE]
It doesn't give me any errors, but I don't receive my weapons either!
Here's my actual code [CODE]if SERVER then
resource.AddFile("lua/autorun/client/vipspawn.lua")
AddCSLuaFile("autorun/client/vipspawn.lua")
end
hook.Add("TTTBeginRound", "my unique name", function()
for k,ply in pairs( player.GetAll() ) do
if ply:IsUserGroup("vip") or ply:IsUserGroup("admin") or ply:IsUserGroup("superadmin") or ply:IsUserGroup("vip mod") then
ply:Give("weapon_ttt_goldengun")
end
end
end)[/CODE]
Edit:
Thanks matt, for showing us how to rate people randomly
Regular expressions are annoying the shit out of me. I'm trying to add a DTextEntry that only allows you to enter a number, else it'll disable a button.
local textmatch = string.match( text, "%d" )
Whenever I enter a number, it still lets me type a character.
Anyone? I need help, I don't receive any errors, but still doesn't receive my weapons
Sorry, you need to Log In to post a reply to this thread.