• What do you need help with? V3
    6,419 replies, posted
[QUOTE=Awakened;37684441]Basically, what I've been trying to do is make it so when a player enter's noclip, the script: 1. Saves the starting point where they went into noclip 2. Save their eyeangle point when they went into clip 3. Send them back to the location they first started out at when they exit noclip. Problems: It won't send them back to the location they started off at and it doesnt set the eyeangles correctly. I can't seem to figure out why this is happening -_- [CODE]function AdminNoClip ( ply ) if (ply:GetMoveType() == MOVETYPE_NOCLIP) then print("noclip off") ply:SetPos( Vector(GetStartPos) ) ply:SetEyeAngles( Angle(GetEyeAngles) ) GetStartPos = nil GetEyeAngles = nil else print("noclip on") GetStartPos = ply:GetPos() GetEyeAngles = ply:EyeAngles() end end hook.Add("PlayerNoClip", "AdminNoClip", AdminNoClip)[/CODE][/QUOTE] You're setting global variables serverside. What happens when 2 admins use noclip at the same time? When you're trying to send them back to their start position, you're getting the vector of a vector. GetPos() returns a vector, and you're trying to get the vector of that vector. Same with the angle. [lua]local function AdminNoClip( ply ) if ply:GetMoveType() == MOVETYPE_NOCLIP then ply:SetPos( ply.LastNoclipPos ) ply:SetEyeAngles( ply.LastEyeAng ) else ply.LastNoclipPos = ply:GetPos() ply.LastEyeAng = ply:EyeAngles() end end hook.Add( "PlayerNoClip", "AdminNoClip", AdminNoClip )[/lua] Untested, but should work.
[QUOTE=Trumple;37690051]-snip-[/QUOTE] I was messing around with tables earlier when I saw this and came up with this: [lua] --This only works for Tables with numeric keys. function table.IReverse(tbl) for k,v in ipairs(tbl) do tbl[v] = k end for i = 1, table.Count(tbl) do tbl[i] = nil end end local tables = {} tables[1] = "John" tables[2] = "Mary" tables[3] = "Dave" table.IReverse(tables) for k,v in pairs(tables) do print(k,v) end [/lua]
[QUOTE=brandonj4;37691850] [lua] --This only works for Tables with numeric keys. function table.IReverse(tbl) for k,v in ipairs(tbl) do tbl[v] = k end for i = 1, table.Count(tbl) do tbl[i] = nil end end [/lua][/QUOTE] uhhh why not just do it in one loop, instead of three (yes, you're currently using three loops. table.Count has a loop inside of it) [lua]function table.IReverse( tbl ) for k,v in ipairs( tbl ) do tbl[v] = k tbl[k] = nil end end[/lua]
Wouldn't it be better to use pairs for yours Divran?
[QUOTE=Banana Lord.;37692138]Wouldn't it be better to use pairs for yours Divran?[/QUOTE] He had commented "This only works for Tables with numeric keys." so I assumed that's what he wanted, and kept it that way Personally, I would have used "for i=1,#tbl do" but I was just editing his.
[QUOTE=Divran;37692167]He had commented "This only works for Tables with numeric keys." so I assumed that's what he wanted, and kept it that way Personally, I would have used "for i=1,#tbl do" but I was just editing his.[/QUOTE] oh, my bad, I was just skimming over the posts!
[QUOTE=Divran;37692103]-snip-[/QUOTE] Uhh, sure whatever works better :P
I'm trying to include a file with some GAMEMODE. functions, but I'm always receiving a error like, [gamemodes/mygamemode/gamemode/stuff.lua:7] attempt to index global 'GAMEMODE' (a nil value) how can I solve that?
the GAMEMODE variable exists after the gamemode has loaded inside the gamemode you need to use GM
Hmm, so everything must use GM? because I started having a spam of errors: Timer 'Stuff_Handling' Error: [gamemodes/Mygamemode/gamemode/stuff.lua:54] attempt to index global 'GM' (a nil value) line 54 is [lua]if #player.GetAll() < GM.Min_player then[/lua]
if that's inside a GM function then you should use self
[QUOTE=Banana Lord.;37693135]if that's inside a GM function then you should use self[/QUOTE] it is, but now, the error changed from "attempt to index global 'GM'" to "attempt to index global 'self'"
can you most more code
[QUOTE=BL00DB4TH;37691776]You're setting global variables serverside. What happens when 2 admins use noclip at the same time? When you're trying to send them back to their start position, you're getting the vector of a vector. GetPos() returns a vector, and you're trying to get the vector of that vector. Same with the angle. [lua]local function AdminNoClip( ply ) if ply:GetMoveType() == MOVETYPE_NOCLIP then ply:SetPos( ply.LastNoclipPos ) ply:SetEyeAngles( ply.LastEyeAng ) else ply.LastNoclipPos = ply:GetPos() ply.LastEyeAng = ply:EyeAngles() end end hook.Add( "PlayerNoClip", "AdminNoClip", AdminNoClip )[/lua] Untested, but should work.[/QUOTE] i pasted the wrong code, sorry about that. Even though it's like that my main problem still exists. It doesn't teleport them back to their original position, it doesn't even set their angle back to the original position... :(
self:DrawEntityOutline( 1.0 ) No longer works in Gmod13, does anyone know an alternative for this?
[QUOTE=jdmmer;37698519]self:DrawEntityOutline( 1.0 ) No longer works in Gmod13, does anyone know an alternative for this?[/QUOTE] They're replaced with halos.
[QUOTE=vercas;37698596]They're replaced with halos.[/QUOTE] Thanks, however I keep getting an error when trying to use it. Code: halo.Add(self.Entity, Color( 255, 255, 255, 255 )) Error: Hook 'RenderHalos' Failed: [@lua/includes/modules/halo.lua:66] bad argument #1 to 'pairs' (table expected, got Entity) 1. lua/includes/modules/hook.lua:83 (unknown) 2. (tail call):-1 (unknown)
[QUOTE=jdmmer;37699300]Thanks, however I keep getting an error when trying to use it. Code: halo.Add(self.Entity, Color( 255, 255, 255, 255 )) Error: Hook 'RenderHalos' Failed: [@lua/includes/modules/halo.lua:66] bad argument #1 to 'pairs' (table expected, got Entity) 1. lua/includes/modules/hook.lua:83 (unknown) 2. (tail call):-1 (unknown)[/QUOTE] The first parameter of [i]halo.Add[/i] is a table which must contain the entities to give the halo. So your code should be: [lua]halo.Add({ self.Entity }, Color( 255, 255, 255, 255 ))[/lua]
[url]http://wiki.garrysmod.com/page/Libraries/halo/Add[/url] :)
[QUOTE=vercas;37699345]The first parameter of [i]halo.Add[/i] is a table which must contain the entities to give the halo. So your code should be: [lua]halo.Add({ self.Entity }, Color( 255, 255, 255, 255 ))[/lua][/QUOTE] The error is gone now, however the whole game stops responding.
what hook are you calling it in
[QUOTE=Divran;37692103]uhhh why not just do it in one loop, instead of three (yes, you're currently using three loops. table.Count has a loop inside of it) [lua]function table.IReverse( tbl ) for k,v in ipairs( tbl ) do tbl[v] = k tbl[k] = nil end end[/lua][/QUOTE] breaks when k == v.
[QUOTE=FPtje;37701609]breaks when k == v.[/QUOTE] It will also break when 2 members have the same value (one of them will disappear).
[QUOTE=FPtje;37701609]breaks when k == v.[/QUOTE] And his original won't? EDIT: No his should have the exact same problem. All you have to do to fix it is to erase tbl[k] = nil
[QUOTE=Divran;37701711]And his original won't? EDIT: No his should have the exact same problem. All you have to do to fix it is to erase tbl[k] = nil[/QUOTE] that leads to redundant data if k != v.
What the fuck is the point of this reversing bullshit again?
[QUOTE=ralle105;37702870]What the fuck is the point of this reversing bullshit again?[/QUOTE] lookup tables? so your shit becomes O(1) instead of O(n)
Then surely making a new table is a better idea? [lua] function table.reverse(t) local newt = {} for k,v in pairs(t) do newt[v] = k end return newt end [/lua]
[QUOTE=ralle105;37703528]Then surely making a new table is a better idea? [lua] function table.reverse(t) local newt = {} for k,v in pairs(t) do newt[v] = k end return newt end [/lua][/QUOTE] Sure, I guess. I was just optimizing his code, not debating which is the best way to do it
Does anybody know how to make a paypal donation button work in derma to open a web-page in the player's background when they click on it? [editline]17th September 2012[/editline] Also, I need help with a modified weedplant for DarkRP, whenever I destroy the max amount of weed pots you can have spawned at once, you can no longer spawn any more weed pots. It simply says that you have reached the limit for weed pots. [lua]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self.Entity:SetModel("models/nater/weedplant_pot_dirt.mdl") self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.Entity:SetUseType(SIMPLE_USE) local phys = self.Entity:GetPhysicsObject() if phys and phys:IsValid() then phys:Wake() end self.Entity:SetNWBool("Usable", false) self.Entity:SetNWBool("Plantable", true) self.damage = 100 end function ENT:CreateMoneybag() if not ValidEntity(self) then return end local MoneyPos = self:GetPos() local amount = self:GetDTInt("drugworth") //GetGlobalInt("mprintamount") if amount == 0 then amount = self:GetDTInt("drugworth", amount) end DarkRPCreateMoneyBag(Vector(MoneyPos.x, MoneyPos.y, MoneyPos.z + 15), amount) self.sparking = true timer.Simple(math.random(250, 300), self) self.Entity:SetNWBool("Plantable", true) end function ENT:OnTakeDamage(dmg) self.damage = (self.damage or 100) - dmg:GetDamage() if self.damage <= 0 then self.Entity:Destruct() self.Entity:Remove() end end function ENT:Use() if self.Entity:GetNWBool("Usable") == true then self.Entity:SetNWBool("Usable", false) self.Entity:SetNWBool("Plantable", true) self.Entity:SetModel("models/nater/weedplant_pot_dirt.mdl") local SpawnPos = self.Entity:GetPos() self:CreateMoneybag() end end function ENT:Destruct() local vPoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vPoint) effectdata:SetOrigin(vPoint) effectdata:SetScale(1) util.Effect("Explosion", effectdata) util.Effect("pickup", effectdata) timer.Destroy("Stage2") timer.Destroy("Stage3") timer.Destroy("Stage4") timer.Destroy("Stage5") timer.Destroy("Stage6") timer.Destroy("Stage7") timer.Destroy("Stage8") timer.Destroy("Stage9") GAMEMODE:Notify(self.dt.owning_ent, 0, 4, "Your Weed Plant has exploded!") end function ENT:Touch(hitEnt) if hitEnt:GetClass() == "seed_weed" then if self.Entity:GetNWBool("Plantable") == true then self.Entity:SetNWBool("Plantable", false) hitEnt:Remove() self.Entity:SetModel("models/nater/weedplant_pot_planted.mdl") timer.Create("Stage2_"..self:EntIndex(), 35, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing1.mdl") end) timer.Create("Stage3_"..self:EntIndex(), 75, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing2.mdl") end) timer.Create("Stage4_"..self:EntIndex(), 110, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing3.mdl") end) timer.Create("Stage5_"..self:EntIndex(), 185, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing4.mdl") end) timer.Create("Stage6_"..self:EntIndex(), 225, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing5.mdl") end) timer.Create("Stage7_"..self:EntIndex(), 275, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing6.mdl") self:SetDTInt("Int",1250,"drugworth") // + end) timer.Create("Stage8_"..self:EntIndex(), 315, 1, function() self.Entity:SetModel("models/nater/weedplant_pot_growing7.mdl") self.Entity:SetNWBool("Usable", true) end) end end end function ENT:OnRemove() if self.Entity:GetNWBool("Plantable") == false then timer.Destroy("Stage2") timer.Destroy("Stage3") timer.Destroy("Stage4") timer.Destroy("Stage5") timer.Destroy("Stage6") timer.Destroy("Stage7") timer.Destroy("Stage8") end end function ENT:Think() end [/lua]
Sorry, you need to Log In to post a reply to this thread.