Difference between revisions of "LUA:Pay Day Baton"

From Official DarkRP Wiki
Jump to navigation Jump to search
(Addon)
(Coding it)
Line 24: Line 24:
 
==Coding it==
 
==Coding it==
  
Add the following code into shared.lua:
+
When your in Shared.lua, find the job you want the player to be demoted from when they're killed. Then add this:
  
{{Code|1=
+
 
if SERVER then
+
----
AddCSLuaFile("shared.lua")
+
 
end
+
PlayerDeath = function(ply, weapon, killer)  
+
if( ply:Team() == TEAM_MAYOR ) then
if CLIENT then --Client stuff
+
ply:ChangeTeam( TEAM_CITIZEN, true )
SWEP.PrintName = "Pay Day Baton" --Name
+
for k,v in pairs( player.GetAll() ) do
SWEP.Slot = 1
+
v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
SWEP.SlotPos = 3
+
end
SWEP.DrawAmmo = false --Draw ammo in bottom right corner
 
SWEP.DrawCrosshair = false --Draw crosshair?
 
end
 
 
SWEP.Author = "KillerLUA" --Author
 
SWEP.Instructions = "Left or right click to give the player a pay day" --How to use
 
SWEP.Contact = "" --Contact
 
SWEP.Purpose = "Gives people paydays" --Purpose
 
 
SWEP.ViewModelFOV = 62
 
SWEP.ViewModelFlip = false
 
SWEP.AnimPrefix = "stunstick"
 
 
SWEP.Spawnable = false --Not spawnable by non-admin players
 
SWEP.AdminSpawnable = true --Only spawnable by admins!
 
 
SWEP.NextStrike = 0
 
 
SWEP.ViewModel = Model("models/weapons/v_stunstick.mdl") --The model while being held
 
SWEP.WorldModel = Model("models/weapons/w_stunbaton.mdl") --World model (on the ground)
 
 
SWEP.Sound = Sound("weapons/stunstick/stunstick_swing1.wav") --The sound
 
 
SWEP.Primary.ClipSize = -1
 
SWEP.Primary.DefaultClip = 0
 
SWEP.Primary.Automatic = false
 
SWEP.Primary.Ammo = ""
 
 
SWEP.Secondary.ClipSize = -1
 
SWEP.Secondary.DefaultClip = 0
 
SWEP.Secondary.Automatic = false
 
SWEP.Secondary.Ammo = ""
 
 
function SWEP:Initialize()
 
if SERVER then self:SetWeaponHoldType("normal") end --Set the hold type
 
end
 
 
function SWEP:PrimaryAttack()
 
if CurTime() < self.NextStrike then return end
 
 
if SERVER then
 
self:SetWeaponHoldType("melee")
 
timer.Simple(0.3, function(wep) if wep:IsValid() then wep:SetWeaponHoldType("normal") end end, self) --Checks that the swep hasn't quickly been switched
 
 
end
 
end
self.Owner:SetAnimation(PLAYER_ATTACK1)
 
self.Weapon:EmitSound(self.Sound) ---Emit a sound, the stunstick wack
 
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
 
 
self.NextStrike = CurTime() + .4
 
 
if CLIENT then return end --No clients past here
 
 
        local trace = self.Owner:GetEyeTrace()
 
  
        if !ValidEntity(trace.Entity) or trace.Entity:IsPlayer() != true then return end
+
 
trace.Entity:PayDay() --Give them a payday
+
----
 +
 
 +
So it should look like this:
 +
 
 +
----
 +
<br>TEAM_MAYOR = AddExtraTeam("Mayor", {</br>
 +
<br> color = Color(150, 20, 20, 255),</br>
 +
<br> model = "models/player/breen.mdl",</br>
 +
description = [[The Mayor of the city creates laws to serve the greater good
 +
of the people.
 +
If you are the mayor you may create and accept warrants.
 +
Type /wanted <name>  to warrant a player
 +
Type /jailpos to set the Jail Position
 +
Type /lockdown initiate a lockdown of the city.
 +
Everyone must be inside during a lockdown.
 +
The cops patrol the area
 +
/unlockdown to end a lockdown]],
 +
weapons = {"weapon_fists"},
 +
command = "mayor",
 +
max = 1,
 +
salary = 100,
 +
admin = 0,
 +
vote = true,
 +
hasLicense = false,
 +
mayor = true,
 +
help = {
 +
"Type /warrant [Nick|SteamID|Status ID] to set a search warrant for a player.",
 +
"Type /wanted [Nick|SteamID|Status ID] to alert everyone to a wanted suspect.",
 +
"Type /unwanted [Nick|SteamID|Status ID] to clear the suspect.",
 +
"Type /lockdown to initiate a lockdown",
 +
"Type /unlockdown to end a lockdown",
 +
"Type /placelaws to place a screen containing the laws.",
 +
"Type /addlaw and /removelaw to edit the laws."
 +
},
 +
PlayerDeath = function(ply, weapon, killer)  
 +
if( ply:Team() == TEAM_MAYOR ) then
 +
ply:ChangeTeam( TEAM_CITIZEN, true )
 +
for k,v in pairs( player.GetAll() ) do
 +
v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
 +
end
 +
end
 
end
 
end
+
})
function SWEP:SecondaryAttack()
+
 
self:PrimaryAttack() --Run Primary Attack
+
----
end
 
}}
 
  
In this script we create the stunstick animation and run payday on our victim.
+
When the mayor dies, he will be demoted.

Revision as of 06:51, 17 August 2013

Lua: Pay Day Baton
Page white text.png Description:How to create a pay day baton.
User.png Original Author:KillerLUA
Calendar.png Created:March 13, 2010


Introduction

Welcome to the tutorial, in this tutorial, I will show you how to demote a player asoon as they die.

Setting up the files

Gamemode

Open Shared.lua in garrysmod/garrysmod/gamemodes/darkrp/gamemode

Gamemode

Create a new file called shared.lua inside YourGamemode/entites/weapons/pay_day_baton

Coding it

When your in Shared.lua, find the job you want the player to be demoted from when they're killed. Then add this:



PlayerDeath = function(ply, weapon, killer) if( ply:Team() == TEAM_MAYOR ) then ply:ChangeTeam( TEAM_CITIZEN, true ) for k,v in pairs( player.GetAll() ) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" ) end end



So it should look like this:



TEAM_MAYOR = AddExtraTeam("Mayor", {

color = Color(150, 20, 20, 255),

model = "models/player/breen.mdl",
description = [[The Mayor of the city creates laws to serve the greater good of the people. If you are the mayor you may create and accept warrants. Type /wanted <name> to warrant a player Type /jailpos to set the Jail Position Type /lockdown initiate a lockdown of the city. Everyone must be inside during a lockdown. The cops patrol the area /unlockdown to end a lockdown]], weapons = {"weapon_fists"}, command = "mayor", max = 1, salary = 100, admin = 0, vote = true, hasLicense = false, mayor = true, help = { "Type /warrant [Nick|SteamID|Status ID] to set a search warrant for a player.", "Type /wanted [Nick|SteamID|Status ID] to alert everyone to a wanted suspect.", "Type /unwanted [Nick|SteamID|Status ID] to clear the suspect.", "Type /lockdown to initiate a lockdown", "Type /unlockdown to end a lockdown", "Type /placelaws to place a screen containing the laws.", "Type /addlaw and /removelaw to edit the laws." }, PlayerDeath = function(ply, weapon, killer) if( ply:Team() == TEAM_MAYOR ) then ply:ChangeTeam( TEAM_CITIZEN, true ) for k,v in pairs( player.GetAll() ) do v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" ) end end end })


When the mayor dies, he will be demoted.