Variable setSelfDarkRPVar (error)

  • Initiateur de la discussion Jo Ballas
  • Date de début
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
Hey,
Je cherche a modifier un swep provenant du workshop ( Steam Workshop::Drink SWEPS (steamcommunity.com) )
Ce que je souhaite faire c'est que lorsque tu bois un soda sa te donne de l'énergie (hunger/faim) sa fonctionne mais je reçois une erreur.

function SWEP:Reload()
self.Owner:getDarkRPVar("Energy")
self.Owner:setSelfDarkRPVar( "Energy", math.Clamp( ( energy or 100 ) + 100, 0, 100 ) )
end
[drink_swep] addons/drink_swep/lua/weapons/drink_blue/shared.lua:169: attempt to call method 'setSelfDarkRPVar' (a nil value)
1. unknown - addons/drink_swep/lua/weapons/drink_blue/shared.lua:169
Toute aide ou renseignement serais fort appréciable.
 
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
MeBad, problème résolu, il suffisait d'utiliser setDarkRPVar au lieu de setSelfDarkRPVar !

function SWEP:Reload()
self.Owner:getDarkRPVar("Energy")
self.Owner:setDarkRPVar( "Energy", math.Clamp( ( energy or 100 ) + 100, 0, 100 ) )
end
 
  • J'aime
Réactions: Yoh Sambre ♪
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
Je viens de remarquer que le math.Clamp ne fonctionne pas lorsque je fais ceci par exemple.
self.Owner:setDarkRPVar( "Energy", math.Clamp( ( energy or 100 ) + 50, 0, 100 ) )
Cela devrais donner 50 d'énergie, mais la il me donne 100 d'énergie, auriez vous une idée de ce qui pose problème dans cette ligne de code?
 
  • Administration
Numerix

Numerix

Admin
Membre du Staff
Messages
1 913
Score réaction
356
Points
315
Alors déjà je comprend pas pourquoi tu utilise une variable energy car elle est pas définie donc je voie encore moins l'intérêt du math.Clamp donc pourquoi ne pas juste faire self.Owner:setDarkRPVar( "Energy", 50 )
 
  • J'aime
Réactions: Jo Ballas
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
J'avoue votre commande fait la même chose, mais en revanche le problème persiste la sa me charge max 50 d'énergie, même ci j'en conscomme plusieurs.
Ce code fonctionne avec une entities du workshop.
En m'inspirant de cette addon Steam Workshop::Edible Food Mod (steamcommunity.com)
Code heal fonctionne mais pour l'énergie je voie pas comment le faire même en m'inspirant de l'addon.
function ENT:Use( activator )
local health = activator:Health()
activator:SetHealth( math.Clamp( ( health or 100 ) + 5, 0, 100 ) )
activator:EmitSound( "foodsounds/drinking.wav", 50, 100 )
activator:printMessage( HUD_PRINTTALK, "You drank some beer!" )
self:Remove()
end
NB: j'essaye de le faire correspondre avec cette addon, Steam Workshop::Drink SWEPS (steamcommunity.com)
function SWEP:Melee()
end

function SWEP:precache()
util.PrecacheSound( "weapons/slam/throw.wav" )
util.PrecacheSound( "weapons/drink/Open.wav" )
util.PrecacheSound( "weapons/drink/Drink.wav" )
util.PrecacheModel( "models/foodnhouseholditems/sodacan01.mdl" )
util.PrecacheModel( "models/foodnhouseholditems/sodacan01.mdl" )
end

if (SERVER) then
AddCSLuaFile("shared.lua")
SWEP.HoldType = "slam"
end

if (CLIENT) then
SWEP.Category = "Drinks"
SWEP.PrintName = "Blue Drink(+15 HP)"
SWEP.Author = "Airul"
SWEP.Slot = 1
SWEP.ViewModelFOV = 50
SWEP.DrawSecondaryAmmo = false
SWEP.DrawAmmo = false
SWEP.WepSelectIcon = surface.GetTextureID("vgui/hud/drink_blue")
end

SWEP.ViewModelFlip = false

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = "models/weapons/w_Physics.mdl"
SWEP.WorldModel = "models/weapons/w_Physics.mdl"

SWEP.VElements = {
["world_can"] = { type = "Model", model = "models/foodnhouseholditems/sodacan01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(5.000, 2.250, -1.300), angle = Angle(-17.878, -111.371, 171.75), size = Vector(0.600, 0.600, 0.600), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.WElements = {
["world_can"] = { type = "Model", model = "models/foodnhouseholditems/sodacan01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.861, 2.717, -0.897), angle = Angle(-17.878, -111.371, 171.75), size = Vector(0.801, 0.801, 0.801), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.UseHands = true
SWEP.ShowWorldModel = true
SWEP.HoldType = "slam"

SWEP.Primary.Delay = 3.5
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Ammo = "none"

function SWEP:EjectBrass()
end

SWEP.data = {}
SWEP.mode = "auto"

SWEP.data.semi = {}

SWEP.data.auto = {}



function SWEP:SecondaryAttack()
end

function SWEP:ShouldDropOnDie()
return true
end


function SWEP:primaryAttack()
self:SetWeaponHoldType("melee")
timer.Create( "Drink", 0.7, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:ViewPunch( Angle( -15, 0, 0 ) )
end)
timer.Create( "Throw", 1.8, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:ViewPunch( Angle( 0, 50, 0 ) )
end)
timer.Create( "Throw2", 1.5, 1, function()
self.Owner:ViewPunch( Angle( 0, -50, 0 ) )
end)
timer.Create( "Throw Can", 2, 1, function()
self:ThrowCan( "models/foodnhouseholditems/sodacan01.mdl" )
self.Owner:EmitSound("weapons/slam/throw.wav", 500, 100)
if SERVER then
self.Owner:StripWeapon( "drink_blue" ) end
end)
local dmginfo = DamageInfo()
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Weapon:SetNWBool("Drinking",true)
self.DoDrinkSound = CurTime() + 0.4
self.Heal1 = CurTime() + 0.6
self.Heal2 = CurTime() + 1.1
self.Heal3 = CurTime() + 1.7
self.StopDrinking = CurTime() + self.Primary.Delay
end

function SWEP:ThrowCan( model_file )

if ( CLIENT ) then return end

local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 10 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:SetCollisionGroup( COLLISION_GROUP_WEAPON )
ent:Spawn()

local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end

local velocity = self.Owner:GetAimVector()
velocity = velocity * 300
velocity = velocity + ( VectorRand() * 10 )
phys:ApplyForceCenter( velocity )

cleanup.Add( self.Owner, "props", ent )
SafeRemoveEntityDelayed( ent, 10 );

undo.Create( "Can" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()

end


function SWEP:Deploy()
timer.Create( "Open", 1.8, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:EmitSound("weapons/drink/Open.wav", 500, 100)
self.Owner:ViewPunch( Angle( -4, 0, 0 ) )
end)
self.Weapon:SetNextPrimaryFire(CurTime() + 3.5)
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
self.Weapon:SetNWBool("Drinking",false)
self.DoDrinkSound = nil
self.Heal1 = nil
self.Heal2 = nil
self.Heal3 = nil
return true
end

function SWEP:Holster()
timer.Destroy("Drink")
timer.Destroy("Open")
timer.Destroy("Throw")
timer.Destroy("Throw2")
timer.Destroy("Throw Can")
if self.Weapon:GetNWBool("Drinking") then
return false
else
return true
end
end


function SWEP:Reload()
end


function SWEP:Think()
if self.Idle and CurTime()>=self.Idle then
self.Idle = nil
self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
end
if self.DoDrinkSound and CurTime()>=self.DoDrinkSound then
self.DoDrinkSound = nil
self.Weapon:EmitSound("weapons/drink/Drink.wav")
end
if self.Heal1 and CurTime()>=self.Heal1 then
self.Heal1 = nil
self.Owner:getDarkRPVar("Thirst")
self.Owner:setDarkRPVar( "Thirst", 50 )

end
end



function SWEP:Initialize()


self:SetWeaponHoldType("slam")


if CLIENT then

self.VElements = table.FullCopy( self.VElements )
self.WElements = table.FullCopy( self.WElements )
self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )

self:CreateModels(self.VElements) // create viewmodels
self:CreateModels(self.WElements) // create worldmodels

if IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)

if (self.ShowViewModel == nil or self.ShowViewModel) then
vm:SetColor(Color(255,255,255,255))
else
vm:SetColor(Color(255,255,255,1))
vm:SetMaterial("Debug/hsv")
end
end
end

end

end

function SWEP:Holster()

if CLIENT and IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
end
end

return true
end

function SWEP:OnRemove()
self:Holster()
end

if CLIENT then

SWEP.vRenderOrder = nil
function SWEP:ViewModelDrawn()

local vm = self.Owner:GetViewModel()
if !IsValid(vm) then return end

if (!self.VElements) then return end

self:UpdateBonePositions(vm)

if (!self.vRenderOrder) then

self.vRenderOrder = {}

for k, v in pairs( self.VElements ) do
if (v.type == "Model") then
table.insert(self.vRenderOrder, 1, k)
elseif (v.type == "Sprite" or v.type == "Quad") then
table.insert(self.vRenderOrder, k)
end
end

end

for k, name in ipairs( self.vRenderOrder ) do

local v = self.VElements[name]
if (!v) then self.vRenderOrder = nil break end
if (v.hide) then continue end

local model = v.modelEnt
local sprite = v.spriteMaterial

if (!v.bone) then continue end

local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )

if (!pos) then continue end

if (v.type == "Model" and IsValid(model)) then

model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

model:SetAngles(ang)
local matrix = Matrix()
matrix:Scale(v.size)
model:EnableMatrix( "RenderMultiply", matrix )

if (v.material == "") then
model:SetMaterial("")
elseif (model:GetMaterial() != v.material) then
model:SetMaterial( v.material )
end

if (v.skin and v.skin != model:GetSkin()) then
model:SetSkin(v.skin)
end

if (v.bodygroup) then
for k, v in pairs( v.bodygroup ) do
if (model:GetBodygroup(k) != v) then
model:SetBodygroup(k, v)
end
end
end

if (v.surpresslightning) then
render.SuppressEngineLighting(true)
end

render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
render.SetBlend(v.color.a/255)
model:DrawModel()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)

if (v.surpresslightning) then
render.SuppressEngineLighting(false)
end

elseif (v.type == "Sprite" and sprite) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
render.SetMaterial(sprite)
render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)

elseif (v.type == "Quad" and v.draw_func) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

cam.Start3D2D(drawpos, ang, v.size)
v.draw_func( self )
cam.End3D2D()

end

end

end

SWEP.wRenderOrder = nil
function SWEP:DrawWorldModel()

if (self.ShowWorldModel == nil or self.ShowWorldModel) then
self:DrawModel()
end

if (!self.WElements) then return end

if (!self.wRenderOrder) then

self.wRenderOrder = {}

for k, v in pairs( self.WElements ) do
if (v.type == "Model") then
table.insert(self.wRenderOrder, 1, k)
elseif (v.type == "Sprite" or v.type == "Quad") then
table.insert(self.wRenderOrder, k)
end
end

end

if (IsValid(self.Owner)) then
bone_ent = self.Owner
else
bone_ent = self
end

for k, name in pairs( self.wRenderOrder ) do

local v = self.WElements[name]
if (!v) then self.wRenderOrder = nil break end
if (v.hide) then continue end

local pos, ang

if (v.bone) then
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
else
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
end

if (!pos) then continue end

local model = v.modelEnt
local sprite = v.spriteMaterial

if (v.type == "Model" and IsValid(model)) then

model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

model:SetAngles(ang)
local matrix = Matrix()
matrix:Scale(v.size)
model:EnableMatrix( "RenderMultiply", matrix )

if (v.material == "") then
model:SetMaterial("")
elseif (model:GetMaterial() != v.material) then
model:SetMaterial( v.material )
end

if (v.skin and v.skin != model:GetSkin()) then
model:SetSkin(v.skin)
end

if (v.bodygroup) then
for k, v in pairs( v.bodygroup ) do
if (model:GetBodygroup(k) != v) then
model:SetBodygroup(k, v)
end
end
end

if (v.surpresslightning) then
render.SuppressEngineLighting(true)
end

render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
render.SetBlend(v.color.a/255)
model:DrawModel()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)

if (v.surpresslightning) then
render.SuppressEngineLighting(false)
end

elseif (v.type == "Sprite" and sprite) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
render.SetMaterial(sprite)
render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)

elseif (v.type == "Quad" and v.draw_func) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

cam.Start3D2D(drawpos, ang, v.size)
v.draw_func( self )
cam.End3D2D()

end

end

end

function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )

local bone, pos, ang
if (tab.rel and tab.rel != "") then

local v = basetab[tab.rel]

if (!v) then return end

pos, ang = self:GetBoneOrientation( basetab, v, ent )

if (!pos) then return end

pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

else

bone = ent:LookupBone(bone_override or tab.bone)

if (!bone) then return end

pos, ang = Vector(0,0,0), Angle(0,0,0)
local m = ent:GetBoneMatrix(bone)
if (m) then
pos, ang = m:GetTranslation(), m:GetAngles()
end

if (IsValid(self.Owner) and self.Owner:IsPlayer() and
ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
ang.r = -ang.r // Fixes mirrored models
end

end

return pos, ang
end

function SWEP:CreateModels( tab )

if (!tab) then return end

for k, v in pairs( tab ) do
if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then

v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
if (IsValid(v.modelEnt)) then
v.modelEnt:SetPos(self:GetPos())
v.modelEnt:SetAngles(self:GetAngles())
v.modelEnt:SetParent(self)
v.modelEnt:SetNoDraw(true)
v.createdModel = v.model
else
v.modelEnt = nil
end

elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then

local name = v.sprite.."-"
local params = { ["$basetexture"] = v.sprite }
local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
for i, j in pairs( tocheck ) do
if (v[j]) then
params["$"..j] = 1
name = name.."1"
else
name = name.."0"
end
end

v.createdSprite = v.sprite
v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)

end
end

end

local allbones
local hasGarryFixedBoneScalingYet = false

function SWEP:UpdateBonePositions(vm)

if self.ViewModelBoneMods then

if (!vm:GetBoneCount()) then return end

local loopthrough = self.ViewModelBoneMods
if (!hasGarryFixedBoneScalingYet) then
allbones = {}
for i=0, vm:GetBoneCount() do
local bonename = vm:GetBoneName(i)
if (self.ViewModelBoneMods[bonename]) then
allbones[bonename] = self.ViewModelBoneMods[bonename]
else
allbones[bonename] = {
scale = Vector(1,1,1),
pos = Vector(0,0,0),
angle = Angle(0,0,0)
}
end
end

loopthrough = allbones
end

for k, v in pairs( loopthrough ) do
local bone = vm:LookupBone(k)
if (!bone) then continue end

local s = Vector(v.scale.x,v.scale.y,v.scale.z)
local p = Vector(v.pos.x,v.pos.y,v.pos.z)
local ms = Vector(1,1,1)
if (!hasGarryFixedBoneScalingYet) then
local cur = vm:GetBoneParent(bone)
while(cur >= 0) do
local pscale = loopthrough[vm:GetBoneName(cur)].scale
ms = ms * pscale
cur = vm:GetBoneParent(cur)
end
end

s = s * ms

if vm:GetManipulateBoneScale(bone) != s then
vm:ManipulateBoneScale( bone, s )
end
if vm:GetManipulateBoneAngles(bone) != v.angle then
vm:ManipulateBoneAngles( bone, v.angle )
end
if vm:GetManipulateBonePosition(bone) != p then
vm:ManipulateBonePosition( bone, p )
end
end
else
self:ResetBonePositions(vm)
end

end

function SWEP:ResetBonePositions(vm)

if (!vm:GetBoneCount()) then return end
for i=0, vm:GetBoneCount() do
vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
end

end



function table.FullCopy( tab )

if (!tab) then return nil end

local res = {}
for k, v in pairs( tab ) do
if (type(v) == "table") then
res[k] = table.FullCopy(v) // recursion ho!
elseif (type(v) == "Vector") then
res[k] = Vector(v.x, v.y, v.z)
elseif (type(v) == "Angle") then
res[k] = Angle(v.p, v.y, v.r)
else
res[k] = v
end
end

return res

end

end
 
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
Jo Ballas à dit:
J'avoue votre commande fait la même chose, mais en revanche le problème persiste la sa me charge max 50 d'énergie, même ci j'en conscomme plusieurs.
Ce code fonctionne avec une entities du workshop.
En m'inspirant de cette addon Steam Workshop::Edible Food Mod (steamcommunity.com)
Code heal fonctionne mais pour l'énergie je voie pas comment le faire même en m'inspirant de l'addon.
function ENT:Use( activator )
local health = activator:Health()
activator:SetHealth( math.Clamp( ( health or 100 ) + 5, 0, 100 ) )
activator:EmitSound( "foodsounds/drinking.wav", 50, 100 )
activator:printMessage( HUD_PRINTTALK, "You drank some beer!" )
self:Remove()
end
NB: j'essaye de le faire correspondre avec cette addon, Steam Workshop::Drink SWEPS (steamcommunity.com)
function SWEP:Melee()
end

function SWEP:precache()
util.PrecacheSound( "weapons/slam/throw.wav" )
util.PrecacheSound( "weapons/drink/Open.wav" )
util.PrecacheSound( "weapons/drink/Drink.wav" )
util.PrecacheModel( "models/foodnhouseholditems/sodacan01.mdl" )
util.PrecacheModel( "models/foodnhouseholditems/sodacan01.mdl" )
end

if (SERVER) then
AddCSLuaFile("shared.lua")
SWEP.HoldType = "slam"
end

if (CLIENT) then
SWEP.Category = "Drinks"
SWEP.PrintName = "Blue Drink(+15 HP)"
SWEP.Author = "Airul"
SWEP.Slot = 1
SWEP.ViewModelFOV = 50
SWEP.DrawSecondaryAmmo = false
SWEP.DrawAmmo = false
SWEP.WepSelectIcon = surface.GetTextureID("vgui/hud/drink_blue")
end

SWEP.ViewModelFlip = false

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = "models/weapons/w_Physics.mdl"
SWEP.WorldModel = "models/weapons/w_Physics.mdl"

SWEP.VElements = {
["world_can"] = { type = "Model", model = "models/foodnhouseholditems/sodacan01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(5.000, 2.250, -1.300), angle = Angle(-17.878, -111.371, 171.75), size = Vector(0.600, 0.600, 0.600), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.WElements = {
["world_can"] = { type = "Model", model = "models/foodnhouseholditems/sodacan01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.861, 2.717, -0.897), angle = Angle(-17.878, -111.371, 171.75), size = Vector(0.801, 0.801, 0.801), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}

SWEP.UseHands = true
SWEP.ShowWorldModel = true
SWEP.HoldType = "slam"

SWEP.Primary.Delay = 3.5
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Ammo = "none"

function SWEP:EjectBrass()
end

SWEP.data = {}
SWEP.mode = "auto"

SWEP.data.semi = {}

SWEP.data.auto = {}



function SWEP:SecondaryAttack()
end

function SWEP:ShouldDropOnDie()
return true
end


function SWEP:primaryAttack()
self:SetWeaponHoldType("melee")
timer.Create( "Drink", 0.7, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:ViewPunch( Angle( -15, 0, 0 ) )
end)
timer.Create( "Throw", 1.8, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:ViewPunch( Angle( 0, 50, 0 ) )
end)
timer.Create( "Throw2", 1.5, 1, function()
self.Owner:ViewPunch( Angle( 0, -50, 0 ) )
end)
timer.Create( "Throw Can", 2, 1, function()
self:ThrowCan( "models/foodnhouseholditems/sodacan01.mdl" )
self.Owner:EmitSound("weapons/slam/throw.wav", 500, 100)
if SERVER then
self.Owner:StripWeapon( "drink_blue" ) end
end)
local dmginfo = DamageInfo()
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Weapon:SetNWBool("Drinking",true)
self.DoDrinkSound = CurTime() + 0.4
self.Heal1 = CurTime() + 0.6
self.Heal2 = CurTime() + 1.1
self.Heal3 = CurTime() + 1.7
self.StopDrinking = CurTime() + self.Primary.Delay
end

function SWEP:ThrowCan( model_file )

if ( CLIENT ) then return end

local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( model_file )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 10 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:SetCollisionGroup( COLLISION_GROUP_WEAPON )
ent:Spawn()

local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end

local velocity = self.Owner:GetAimVector()
velocity = velocity * 300
velocity = velocity + ( VectorRand() * 10 )
phys:ApplyForceCenter( velocity )

cleanup.Add( self.Owner, "props", ent )
SafeRemoveEntityDelayed( ent, 10 );

undo.Create( "Can" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()

end


function SWEP:Deploy()
timer.Create( "Open", 1.8, 1, function()
if !IsValid(self.Owner) then return end
self.Owner:EmitSound("weapons/drink/Open.wav", 500, 100)
self.Owner:ViewPunch( Angle( -4, 0, 0 ) )
end)
self.Weapon:SetNextPrimaryFire(CurTime() + 3.5)
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
self.Weapon:SetNWBool("Drinking",false)
self.DoDrinkSound = nil
self.Heal1 = nil
self.Heal2 = nil
self.Heal3 = nil
return true
end

function SWEP:Holster()
timer.Destroy("Drink")
timer.Destroy("Open")
timer.Destroy("Throw")
timer.Destroy("Throw2")
timer.Destroy("Throw Can")
if self.Weapon:GetNWBool("Drinking") then
return false
else
return true
end
end


function SWEP:Reload()
end


function SWEP:Think()
if self.Idle and CurTime()>=self.Idle then
self.Idle = nil
self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
end
if self.DoDrinkSound and CurTime()>=self.DoDrinkSound then
self.DoDrinkSound = nil
self.Weapon:EmitSound("weapons/drink/Drink.wav")
end
if self.Heal1 and CurTime()>=self.Heal1 then
self.Heal1 = nil
self.Owner:getDarkRPVar("Thirst")
self.Owner:setDarkRPVar( "Thirst", 50 )

end
end



function SWEP:Initialize()


self:SetWeaponHoldType("slam")


if CLIENT then

self.VElements = table.FullCopy( self.VElements )
self.WElements = table.FullCopy( self.WElements )
self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )

self:CreateModels(self.VElements) // create viewmodels
self:CreateModels(self.WElements) // create worldmodels

if IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)

if (self.ShowViewModel == nil or self.ShowViewModel) then
vm:SetColor(Color(255,255,255,255))
else
vm:SetColor(Color(255,255,255,1))
vm:SetMaterial("Debug/hsv")
end
end
end

end

end

function SWEP:Holster()

if CLIENT and IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
end
end

return true
end

function SWEP:OnRemove()
self:Holster()
end

if CLIENT then

SWEP.vRenderOrder = nil
function SWEP:ViewModelDrawn()

local vm = self.Owner:GetViewModel()
if !IsValid(vm) then return end

if (!self.VElements) then return end

self:UpdateBonePositions(vm)

if (!self.vRenderOrder) then

self.vRenderOrder = {}

for k, v in pairs( self.VElements ) do
if (v.type == "Model") then
table.insert(self.vRenderOrder, 1, k)
elseif (v.type == "Sprite" or v.type == "Quad") then
table.insert(self.vRenderOrder, k)
end
end

end

for k, name in ipairs( self.vRenderOrder ) do

local v = self.VElements[name]
if (!v) then self.vRenderOrder = nil break end
if (v.hide) then continue end

local model = v.modelEnt
local sprite = v.spriteMaterial

if (!v.bone) then continue end

local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )

if (!pos) then continue end

if (v.type == "Model" and IsValid(model)) then

model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

model:SetAngles(ang)
local matrix = Matrix()
matrix:Scale(v.size)
model:EnableMatrix( "RenderMultiply", matrix )

if (v.material == "") then
model:SetMaterial("")
elseif (model:GetMaterial() != v.material) then
model:SetMaterial( v.material )
end

if (v.skin and v.skin != model:GetSkin()) then
model:SetSkin(v.skin)
end

if (v.bodygroup) then
for k, v in pairs( v.bodygroup ) do
if (model:GetBodygroup(k) != v) then
model:SetBodygroup(k, v)
end
end
end

if (v.surpresslightning) then
render.SuppressEngineLighting(true)
end

render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
render.SetBlend(v.color.a/255)
model:DrawModel()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)

if (v.surpresslightning) then
render.SuppressEngineLighting(false)
end

elseif (v.type == "Sprite" and sprite) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
render.SetMaterial(sprite)
render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)

elseif (v.type == "Quad" and v.draw_func) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

cam.Start3D2D(drawpos, ang, v.size)
v.draw_func( self )
cam.End3D2D()

end

end

end

SWEP.wRenderOrder = nil
function SWEP:DrawWorldModel()

if (self.ShowWorldModel == nil or self.ShowWorldModel) then
self:DrawModel()
end

if (!self.WElements) then return end

if (!self.wRenderOrder) then

self.wRenderOrder = {}

for k, v in pairs( self.WElements ) do
if (v.type == "Model") then
table.insert(self.wRenderOrder, 1, k)
elseif (v.type == "Sprite" or v.type == "Quad") then
table.insert(self.wRenderOrder, k)
end
end

end

if (IsValid(self.Owner)) then
bone_ent = self.Owner
else
bone_ent = self
end

for k, name in pairs( self.wRenderOrder ) do

local v = self.WElements[name]
if (!v) then self.wRenderOrder = nil break end
if (v.hide) then continue end

local pos, ang

if (v.bone) then
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
else
pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
end

if (!pos) then continue end

local model = v.modelEnt
local sprite = v.spriteMaterial

if (v.type == "Model" and IsValid(model)) then

model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

model:SetAngles(ang)
local matrix = Matrix()
matrix:Scale(v.size)
model:EnableMatrix( "RenderMultiply", matrix )

if (v.material == "") then
model:SetMaterial("")
elseif (model:GetMaterial() != v.material) then
model:SetMaterial( v.material )
end

if (v.skin and v.skin != model:GetSkin()) then
model:SetSkin(v.skin)
end

if (v.bodygroup) then
for k, v in pairs( v.bodygroup ) do
if (model:GetBodygroup(k) != v) then
model:SetBodygroup(k, v)
end
end
end

if (v.surpresslightning) then
render.SuppressEngineLighting(true)
end

render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
render.SetBlend(v.color.a/255)
model:DrawModel()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)

if (v.surpresslightning) then
render.SuppressEngineLighting(false)
end

elseif (v.type == "Sprite" and sprite) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
render.SetMaterial(sprite)
render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)

elseif (v.type == "Quad" and v.draw_func) then

local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

cam.Start3D2D(drawpos, ang, v.size)
v.draw_func( self )
cam.End3D2D()

end

end

end

function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )

local bone, pos, ang
if (tab.rel and tab.rel != "") then

local v = basetab[tab.rel]

if (!v) then return end

pos, ang = self:GetBoneOrientation( basetab, v, ent )

if (!pos) then return end

pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
ang:RotateAroundAxis(ang:Up(), v.angle.y)
ang:RotateAroundAxis(ang:Right(), v.angle.p)
ang:RotateAroundAxis(ang:Forward(), v.angle.r)

else

bone = ent:LookupBone(bone_override or tab.bone)

if (!bone) then return end

pos, ang = Vector(0,0,0), Angle(0,0,0)
local m = ent:GetBoneMatrix(bone)
if (m) then
pos, ang = m:GetTranslation(), m:GetAngles()
end

if (IsValid(self.Owner) and self.Owner:IsPlayer() and
ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
ang.r = -ang.r // Fixes mirrored models
end

end

return pos, ang
end

function SWEP:CreateModels( tab )

if (!tab) then return end

for k, v in pairs( tab ) do
if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then

v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
if (IsValid(v.modelEnt)) then
v.modelEnt:SetPos(self:GetPos())
v.modelEnt:SetAngles(self:GetAngles())
v.modelEnt:SetParent(self)
v.modelEnt:SetNoDraw(true)
v.createdModel = v.model
else
v.modelEnt = nil
end

elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then

local name = v.sprite.."-"
local params = { ["$basetexture"] = v.sprite }
local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
for i, j in pairs( tocheck ) do
if (v[j]) then
params["$"..j] = 1
name = name.."1"
else
name = name.."0"
end
end

v.createdSprite = v.sprite
v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)

end
end

end

local allbones
local hasGarryFixedBoneScalingYet = false

function SWEP:UpdateBonePositions(vm)

if self.ViewModelBoneMods then

if (!vm:GetBoneCount()) then return end

local loopthrough = self.ViewModelBoneMods
if (!hasGarryFixedBoneScalingYet) then
allbones = {}
for i=0, vm:GetBoneCount() do
local bonename = vm:GetBoneName(i)
if (self.ViewModelBoneMods[bonename]) then
allbones[bonename] = self.ViewModelBoneMods[bonename]
else
allbones[bonename] = {
scale = Vector(1,1,1),
pos = Vector(0,0,0),
angle = Angle(0,0,0)
}
end
end

loopthrough = allbones
end

for k, v in pairs( loopthrough ) do
local bone = vm:LookupBone(k)
if (!bone) then continue end

local s = Vector(v.scale.x,v.scale.y,v.scale.z)
local p = Vector(v.pos.x,v.pos.y,v.pos.z)
local ms = Vector(1,1,1)
if (!hasGarryFixedBoneScalingYet) then
local cur = vm:GetBoneParent(bone)
while(cur >= 0) do
local pscale = loopthrough[vm:GetBoneName(cur)].scale
ms = ms * pscale
cur = vm:GetBoneParent(cur)
end
end

s = s * ms

if vm:GetManipulateBoneScale(bone) != s then
vm:ManipulateBoneScale( bone, s )
end
if vm:GetManipulateBoneAngles(bone) != v.angle then
vm:ManipulateBoneAngles( bone, v.angle )
end
if vm:GetManipulateBonePosition(bone) != p then
vm:ManipulateBonePosition( bone, p )
end
end
else
self:ResetBonePositions(vm)
end

end

function SWEP:ResetBonePositions(vm)

if (!vm:GetBoneCount()) then return end
for i=0, vm:GetBoneCount() do
vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
end

end



function table.FullCopy( tab )

if (!tab) then return nil end

local res = {}
for k, v in pairs( tab ) do
if (type(v) == "table") then
res[k] = table.FullCopy(v) // recursion ho!
elseif (type(v) == "Vector") then
res[k] = Vector(v.x, v.y, v.z)
elseif (type(v) == "Angle") then
res[k] = Angle(v.p, v.y, v.r)
else
res[k] = v
end
end

return res

end

end
Waouw le post qui pique les yeux, hier j'était éclaté lorsque j'ai répondu je sais ce n'est pas une excuse :)
Bah au final je vais dépanner en faisant que sa donne 100 d'énergie.
function SWEP:Think()
if self.Idle and CurTime()>=self.Idle then
self.Idle = nil
self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
end
if self.DoDrinkSound and CurTime()>=self.DoDrinkSound then
self.DoDrinkSound = nil
self.Weapon:EmitSound("weapons/drink/Drink.wav")
end
if self.Heal1 and CurTime()>=self.Heal1 then
self.Heal1 = nil
self.Owner:setDarkRPVar( "Energie", 100 )
end
end
Juste une dernière question, j'ai supprimer ceci du code self.Owner:getDarkRPVar("Energie") j'utilise juste self.Owner:setDarkRPVar( "Energie", 100 ) et ça fonctionne donc self.Owner:getDarkRPVar("Energie") ne sert a rien dans ce cas précis ?
 
  • Administration
Numerix

Numerix

Admin
Membre du Staff
Messages
1 913
Score réaction
356
Points
315
Enfaite si tu veux ajouter par rapport à l'énergie actuelle et ne pas dépasser 100 il faut faire

self.Owner:setDarkRPVar( "Energy", math.Clamp(self.Owner:getDarkRPVar("Energy") + 10, 0, 100 ) )

Ici ca augmente à chaque fois de 10 mais ne peux dépasser 100
 
  • Love
Réactions: Jo Ballas
  • Initiateur de la discussion
Jo Ballas

Jo Ballas

Geek suprême
Messages
561
Score réaction
103
Points
150
Parfait ça fonctionne comme un charme, merci.
 
Zelio

Zelio

Nouveau né
Messages
5
Score réaction
0
Points
20
Numerix à dit:
Enfaite si tu veux ajouter par rapport à l'énergie actuelle et ne pas dépasser 100 il faut faire

self.Owner:setDarkRPVar( "Energy", math.Clamp(self.Owner:getDarkRPVar("Energy") + 10, 0, 100 ) )

Ici ca augmente à chaque fois de 10 mais ne peux dépasser 100
Bonsoir/Bonjour. Quand je met ce code ou un autre contenant setDarkRPVar, lorsque j'essai de consommer une entité, ce message apparait :" attempt to call method 'setDarkRPVar' (a nil value) " et l'entité ne se consomme pas . Merçi
 
  • Administration
Numerix

Numerix

Admin
Membre du Staff
Messages
1 913
Score réaction
356
Points
315
tu es bien sur le gamemode darkrp ?
 
Zelio

Zelio

Nouveau né
Messages
5
Score réaction
0
Points
20
  • Administration
Numerix

Numerix

Admin
Membre du Staff
Messages
1 913
Score réaction
356
Points
315
Tu l'utilise côté client ou serveur ?
 
Zelio

Zelio

Nouveau né
Messages
5
Score réaction
0
Points
20
client je crois, j'ai l'addon qui et mis sur la collection du serveur, j'ai mis dans le dossier addons l'addon de nourriture qui est dans la collection, et j'ai remplacé
activator:SetHealth(activator:Health()+10)
par
self.Owner:setDarkRPVar("Energy",math.Clamp(self.Owner:getDarkRPVar("Energy") + 10, 0, 100 ) )
 
Zelio

Zelio

Nouveau né
Messages
5
Score réaction
0
Points
20
C'est bon j'ai réussi à régler le problème
 
Discord d'entraide
Rejoignz-nous sur Discord