Force Choke - help again (new thread, last one was in the wrong category)
8 replies, posted
So yeah... I tried to make it so EVERYONE on a server could use it, but it didn't work out great
What happend before:
>Player 1 is on the server, maybe afk, who knows
>Players 2 joins the server
>Player 2 is a admin and therefore can spawn weapons
>Player 2 tries to force choke player 1
>Player 2 dies.
This is because I set it to target Player 1's vision and not the current players vision... so how do I fix this I thought?
Maybe like this:
[code]
i = Player:GetAll():UserID()
-- further down
local eyetrace = Entity( i ):GetEyeTrace()
[/code]
Did that work? No, for some reason.
So... I need help (again)!
Full code:
[code]
if SERVER then // This is where the init.lua stuff goes.
AddCSLuaFile ("shared.lua")
SWEP.Weight = 1
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
elseif CLIENT then
SWEP.PrintName = "Force Choke"
SWEP.Slot = 4
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
end
SWEP.Author = "PIXX"
SWEP.Contact = "rctgamestv@gmail.com"
SWEP.Purpose = "Force choke lets you choke people at least make them recive damage"
SWEP.Instructions = "Left click to choke."
SWEP.Category = "Force Choke"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.UseHands = false
SWEP.ViewModel = "models/weapons/v_hands.mdl"
SWEP.WorldModel = ""
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = false
SWEP.ViewModelBoneMods = {}
SWEP.Primary.Recoil = 5
SWEP.Primary.Damage = 0
SWEP.Pistol = false
SWEP.Rifle = false
SWEP.Shotgun = false
SWEP.Sniper = false
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
ForceChoke()
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
ForceSecond()
end
-- Everything down bellow here does not work
function ForceSecond()
if CLIENT then
i = LocalPlayer():UserID()
elseif SERVER then
i = 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 or 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 or 29 or 30 or 31 or 32
end
local eyetrace = Entity( i ):GetEyeTrace()
if SERVER then
if eyetrace.Entity:IsPlayer() == true then
eyetrace.Player:Freeze(true)
end
elseif CLIENT then
end
end
function ForceChoke(tr,dmginfo)
if CLIENT then
i = LocalPlayer():UserID()
elseif SERVER then
i = 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 or 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 or 29 or 30 or 31 or 32 -- The players id
end
local eyetrace = Entity( i ):GetEyeTrace()
local gun = weapons.Get("forcechoke")
if SERVER then
if eyetrace.Entity:IsPlayer() == true then
eyetrace.Entity:TakeDamage(20000,player,eyetrace.Entity)
elseif eyetrace.Entity:IsNPC() == true then
eyetrace.Entity:TakeDamage(20000,player,eyetrace.Entity)
end
elseif CLIENT then
if eyetrace.Entity:IsPlayer() == true then
ReadSound()
elseif eyetrace.Entity:IsNPC() == true then
ReadSound()
end
end
end
concommand.Add("forcechoke_playsound",function(ply)
if CLIENT then
ReadSound()
elseif SERVER then
print("You are console, no sounds for you!")
end
end)
function ReadSound()
EmitSound( Sound("player/pl_pain5.wav"), Entity( i ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
end
[/code]
Please no hate, only love
Thanks in regards
--- PIXX
Edit:
Yes, I have tried player:GetAll()
but it gets a table, but "Entity( i ):GetEyeTrace()" requires a id, not a table.
Wow, that's some awful code man...
I'd love to help, but I would have to buy a rope and hang myself in the process.
[editline]4th June 2016[/editline]
Also your:
i = 0 or 1 or 2... will always return 0, because 0 exists and will always be valid.
[QUOTE=Netheous;50452378]Wow, that's some awful code man...
I'd love to help, but I would have to buy a rope and hang myself in the process.
[editline]4th June 2016[/editline]
Also your:
i = 0 or 1 or 2... will always return 0, because 0 exists and will always be valid.[/QUOTE]
1) First swep/weapon
2) Okay, I will set it to zero and try it
3) Plz don't... you can help people.
4) Thanks :D
[QUOTE=PIXX;50452392][B]2) Okay, I will set it to zero and try it[/B][/QUOTE]
You what?
Use this instead:
[code]i = self.Owner:UserID()[/code]
[editline]4th June 2016[/editline]
Also you are using 'player' as your variable, whereas it's a library containing functions... so don't.
There's so much wrong with this code I don't know where to start.
[QUOTE=Netheous;50452401]You what?
Use this instead:
[code]i = self.Owner:UserID()[/code]
[editline]4th June 2016[/editline]
Also you are using 'player' as your variable, whereas it's a library containing functions... so don't.
There's so much wrong with this code I don't know where to start.[/QUOTE]
Okay..
First off this is my first swep I ever made..
Second: Why would you want to hang yourself
Third: Thanks again.
Update:
[code]
[ERROR] addons/forcechoke/lua/weapons/forcechoke/shared.lua:62: attempt to index global 'self' (a nil value)
1. unknown - addons/forcechoke/lua/weapons/forcechoke/shared.lua:62
2. include - [C]:-1
3. unknown - addons/forcechoke/lua/weapons/forcechoke/init.lua:4
[¤PIXX¤|2|STEAM_0:1:82801350] Lua Error:
[ERROR] addons/forcechoke/lua/weapons/forcechoke/shared.lua:62: attempt to index global 'self' (a nil value)
1. unknown - addons/forcechoke/lua/weapons/forcechoke/shared.lua:62
2. include - [C]:-1
3. unknown - addons/forcechoke/lua/weapons/forcechoke/cl_init.lua:1
[/code]
Oh, ofcourse, your functions aren't even attached to weapon meta.
[QUOTE=Netheous;50452481]Oh, ofcourse, your functions aren't even attached to weapon meta.[/QUOTE]
Fuck me... I am stupid at lua... why did I think I could do this xD
Anyway.. gonna try to find something online, always helps
Update:
Like this?
[code]
if SERVER then // This is where the init.lua stuff goes.
AddCSLuaFile ("shared.lua")
SWEP.Weight = 1
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
elseif CLIENT then
SWEP.PrintName = "Force Choke"
SWEP.Slot = 4
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
end
SWEP.Author = "PIXX"
SWEP.Contact = "rctgamestv@gmail.com"
SWEP.Purpose = "Force choke lets you choke people at least make them recive damage"
SWEP.Instructions = "Left click to choke."
SWEP.Category = "Force Choke"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.UseHands = false
SWEP.ViewModel = "models/weapons/v_hands.mdl"
SWEP.WorldModel = ""
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = false
SWEP.ViewModelBoneMods = {}
SWEP.Primary.Recoil = 5
SWEP.Primary.Damage = 0
SWEP.Pistol = false
SWEP.Rifle = false
SWEP.Shotgun = false
SWEP.Sniper = false
i = self.Owner:UserID()
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
local eyetrace = Entity(i):GetEyeTrace()
local gun = weapons.Get("forcechoke")
if SERVER then
if eyetrace.Entity:IsPlayer() == true then
eyetrace.Entity:TakeDamage(20000,player,eyetrace.Entity)
EmitSound( Sound("player/pl_pain5.wav"), Entity( i ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
elseif eyetrace.Entity:IsNPC() == true then
eyetrace.Entity:TakeDamage(20000,player,eyetrace.Entity)
EmitSound( Sound("player/pl_pain5.wav"), Entity( i ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
end
elseif CLIENT then
if eyetrace.Entity:IsPlayer() == true then
ReadSound()
elseif eyetrace.Entity:IsNPC() == true then
ReadSound()
end
end
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
local eyetrace = Entity(i):GetEyeTrace()
if SERVER then
if eyetrace.Entity:IsPlayer() == true then
eyetrace.Player:Freeze(true)
end
elseif CLIENT then
end
end
concommand.Add("forcechoke_playsound",function(ply)
if CLIENT then
EmitSound( Sound("player/pl_pain5.wav"), Entity( i ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
elseif SERVER then
print("You are console, no sounds for you!")
end
end)
[/code]
It returns:
[code]
[ERROR] addons/forcechoke/lua/weapons/forcechoke/shared.lua:53: attempt to index global 'self' (a nil value)
1. unknown - addons/forcechoke/lua/weapons/forcechoke/shared.lua:53
2. include - [C]:-1
3. unknown - addons/forcechoke/lua/weapons/forcechoke/init.lua:4
[/code]
Update 2:
Fixed it but now:
[code]
[ERROR] addons/forcechoke/lua/weapons/forcechoke/shared.lua:56: attempt to call method 'GetEyeTrace' (a nil value)
1. unknown - addons/forcechoke/lua/weapons/forcechoke/shared.lua:56
[/code]
Change [LUA]local eyetrace = Entity(i):GetEyeTrace()[/LUA] to [LUA]local eyetrace = self.Owner:GetEyeTrace()[/LUA] and remove [LUA]i = self.Owner:UserID()[/LUA]
[QUOTE=rtm516;50453358]Change [LUA]local eyetrace = Entity(i):GetEyeTrace()[/LUA] to [LUA]local eyetrace = self.Owner:GetEyeTrace()[/LUA] and remove [LUA]i = self.Owner:UserID()[/LUA][/QUOTE]
ok
will try :D
Update:
works
Sorry, you need to Log In to post a reply to this thread.