So i'm editing the Cider gamemode, and i'd like, instead of Police having lots of different weapons for knock out, wake up, arrest, unarrest, bash and so on... i'd like to just have it all in a single baton with different keys binded to it. Okay, here comes what i cant figure out...
I want to have it, so when you press the secondary fire button, you shall could arrest a player, but then when he's arrested, you shall also could unarrest him. Here's the code that's working - but it can only arrest by using secondary fire:
[LUA] -- Check to see if the entity is a player and that it's close to the owner.
if (trace.Entity and trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
if (!trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanArrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, true);[/LUA]
Now, here comes my shitty attempt to make it unarrest a player when he's arrested:
[LUA] -- Check to see if the entity is a player and that it's close to the owner.
if (trace.Entity and trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
if (!trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanArrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, true);
elseif (trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanUnarrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, false);[/LUA]
But it can still only arrest people, not unarrest them again. Sorry for probably being a retard, but i really need help with this one.
Sorry I can't help more, and im tired so I can't really do anything.
(and I don't have time to test the game mode)
Anyway, you're code would kinda look like this
[lua]
function SWEP:OnFire()
if ply:IsArrested() then ply.Unarrest()
else
ply.Arrest()
end
end [/lua]
I'm not really sure how to put that in, as it is now...
But you can take a look at my whole code for the Secondary Fire:
[LUA]-- Called when the player attempts to secondary fire.
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + self.Secondary.Delay);
-- Set the animation of the owner and weapon and play the sound.
self.Owner:SetAnimation(PLAYER_ATTACK1);
-- Get an eye trace from the player.
local trace = self.Owner:GetEyeTrace();
-- Check if the trace hit or it hit the world.
if ( (trace.Hit or trace.HitWorld) and self.Owner:GetPos():Distance(trace.HitPos) <= 128 ) then
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet3.wav");
else
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
self.Weapon:EmitSound("weapons/stunstick/stunstick_swing1.wav");
end;
-- Check if we're running on the client.
if (CLIENT) then return; end;
-- Check to see if the entity is a player and that it's close to the owner.
if (trace.Entity and trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
if (!trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanArrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, true);
else if (trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanUnarrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, false);
-- Let the administrators know that this happened.
cider.player.printConsoleAccess(self.Owner:Name().." arrested "..trace.Entity:Name()..".", "a");
-- Call a hook.
hook.Call("PlayerArrest", GAMEMODE, self.Owner, trace.Entity);
end;
end;
end;
end;
end;
end;[/LUA]
[code]function SWEP:OnFire()
if ply:IsArrested() then ply.Unarrest()
else
ply.Arrest()
end
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + self.Secondary.Delay);
-- Set the animation of the owner and weapon and play the sound.
self.Owner:SetAnimation(PLAYER_ATTACK1);
-- Get an eye trace from the player.
local trace = self.Owner:GetEyeTrace();
-- Check if the trace hit or it hit the world.
if ( (trace.Hit or trace.HitWorld) and self.Owner:GetPos():Distance(trace.HitPos) <= 128 ) then
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
self.Weapon:EmitSound("physics/flesh/flesh_impact_bullet3.wav");
else
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
self.Weapon:EmitSound("weapons/stunstick/stunstick_swing1.wav");
end;
-- Check if we're running on the client.
if (CLIENT) then return; end;
-- Check to see if the entity is a player and that it's close to the owner.
if (trace.Entity and trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
if (!trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanArrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, true);
else if (trace.Entity.cider._Arrested) then
if ( hook.Call("PlayerCanUnarrest", GAMEMODE, self.Owner, trace.Entity) ) then
cider.player.arrest(trace.Entity, false);
-- Let the administrators know that this happened.
cider.player.printConsoleAccess(self.Owner:Name().." arrested "..trace.Entity:Name()..".", "a");
-- Call a hook.
hook.Call("PlayerArrest", GAMEMODE, self.Owner, trace.Entity);
end;
end;
end;
end;
end;
end; [/code]
doesnt work... but i did something wrong... so just close/delete this thread or something :p
Sorry, you need to Log In to post a reply to this thread.