LUA:Pay Day Baton:fr

From DarkRP
This page is available in the following languages:
Данная версия страницы доступна на следующих языках:
English | Français



Commencer[edit]

Créez un nouveau fichier appelé shared.lua à l'intérieur de l'addon DarkRP modification dans lua/weapons/pay_day_baton (voir ici).

Code[edit]

Ajoutez le code suivant dans shared.lua:

AddCSLuaFile()
 
if CLIENT then --Client stuff
	SWEP.PrintName = "Baton de jour de paie" --Nom
	SWEP.Slot = 1
	SWEP.SlotPos = 3
	SWEP.DrawAmmo = false --Dessiner des munitions en bas à droite dans le coin
	SWEP.DrawCrosshair = false --Dessiner le viseur?
end
 
SWEP.Author = "KillerLUA" --Auteur
SWEP.Instructions = "Clique gauche ou droit pour donner à un joueur une paie" --Comment l'utiliser
SWEP.Contact = "" --Contact
SWEP.Purpose = "Donne au joueur une paie" --Résumé
 
SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "stunstick"
 
SWEP.Spawnable = true
SWEP.AdminOnly = true --Peut être spawn uniquement par les admins !
 
SWEP.NextStrike = 0
 
SWEP.ViewModel = Model("models/weapons/v_stunstick.mdl") --Le model dans les mains
SWEP.WorldModel = Model("models/weapons/w_stunbaton.mdl") --Le World model (quand il est par terre)
 
SWEP.Sound = Sound("weapons/stunstick/stunstick_swing1.wav") --Le son
 
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()
	self:SetHoldType("normal")
end
 
function SWEP:PrimaryAttack()
	if CurTime() < self.NextStrike then return end
 
	self:SetHoldType("normal")
	timer.Simple(0.3, function() if self:IsValid() then self:SetHoldType("normal") end end) --Regarder si le SWEP n'a pas été changé rapidement

	self.Owner:SetAnimation(PLAYER_ATTACK1)
	self.Weapon:EmitSound(self.Sound) ---Ajoute un son, ici celui du stunstick
	self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
 
	self.NextStrike = CurTime() + 0.51
 
	if CLIENT then return end --Pas de clients collés ici
 
	self.Owner:LagCompensation(true)
	local trace = util.QuickTrace(self.Owner:EyePos(), self.Owner:GetAimVector() * 90, {self.Owner})
	self.Owner:LagCompensation(false)

	local ent = self.Owner:getEyeSightHitEntity(nil, nil, function(p) return p ~= self.Owner and p:IsPlayer() and p:Alive() end)

        if not IsValid(ent) or (self.Owner:EyePos():Distance(ent:GetPos()) > 90) or (not ent:IsPlayer() and not ent:IsNPC()) then
		return
	end

	ent:payDay() --Donner une paie
end
 
function SWEP:SecondaryAttack()
	self:PrimaryAttack() --Lancer le clique gauche
end

Dans ce script nous avons créer l'animation du stunstick qui permet de déclencher un jour de paie sur la victime.