Ich erstelle immoment einen neuen gamemode(Ein neuen RP Gamemode) und erstelle mir dafür auch waffen.
Nun fehlt mir das wissen, Variablen für bestimmte Waffen zu haben(nur für diese eine Waffe und auch nur für die ID der Waffe, also so das andere gleiche waffen die variable nicht verändern können).
Kann den code jemand so verändern, dass es wie oben beschrieben ist?
Die Basis der Waffe ist weapon_base("base" gamemode)
Edit: Die Variable BanTime soll so wie oben beschrieben sein
cl_init.lua:Lua Code:
include('shared.lua') SWEP.PrintName = "Kickstick" // 'Nice' Weapon name (Shown on HUD) SWEP.Slot = 0 // Slot in the weapon selection menu SWEP.SlotPos = 10 // Position in the slot SWEP.DrawAmmo = true // Should draw the default HL2 ammo counter SWEP.DrawCrosshair = true // Should draw the default crosshair SWEP.DrawWeaponInfoBox = true // Should draw the weapon info box SWEP.BounceWeaponIcon = true // Should the weapon icon bounce? SWEP.SwayScale = 1.0 // The scale of the viewmodel sway SWEP.BobScale = 1.0 // The scale of the viewmodel bobSWEP.RenderGroup = RENDERGROUP_OPAQUE// Override this in your SWEP to set the icon in the weapon selection SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" )// This is the corner of the speech bubble SWEP.SpeechBubbleLid = surface.GetTextureID( "gui/speech_lid" )/*---------------------------------------------------------You can draw to the HUD here - it will only draw whenthe client has the weapon deployed..---------------------------------------------------------*/ function SWEP:DrawHUD() local XS = ScrW()/2 + 50 local YS = ScrH()/2 draw.RoundedBox( 5, XS, YS, 50, 30, Color( 102, 102, 102, 153 ) ) draw.DrawText( "Ban Time:", "", XS+5, YS+5, Color( 255, 255, 255, 153 ) ) draw.DrawText( tostring(BanTime), "", XS+5, YS+5, Color( 255, 255, 255, 153 ) )end/*---------------------------------------------------------Checks the objects before any action is takenThis is to make sure that the entities haven't been removed---------------------------------------------------------*/ function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )// Set us up the texture surface.SetDrawColor( 255, 255, 255, alpha ) surface.SetTexture( self.WepSelectIcon )// Lets get a sin wave to make it bounce local fsin = 0 if ( self.BounceWeaponIcon == true ) then fsin = math.sin( CurTime() * 10 ) * 5end// Borders y = y + 10 x = x + 10 wide = wide - 20// Draw that mother surface.DrawTexturedRect( x + (fsin), y - (fsin), wide-fsin*2 , ( wide / 2 ) + (fsin) )// Draw weapon info box self:PrintWeaponInfo( x + wide + 20, y + tall * 0.95, alpha )end/*---------------------------------------------------------This draws the weapon info box---------------------------------------------------------*/ function SWEP:PrintWeaponInfo( x, y, alpha ) if ( self.DrawWeaponInfoBox == false ) then return end if (self.InfoMarkup == nil ) thenlocal str local title_color = "<color=230,230,230,255>" local text_color = "<color=150,150,150,255>" str = "<font=HudSelectionText>" if ( self.Author != "" ) then str = str .. title_color .. "Author:</color>\t"..text_color..self.Author.."</color>\n" end if ( self.Contact != "" ) then str = str .. title_color .. "Contact:</color>\t"..text_color..self.Contact.."</color>\n\n" end if ( self.Purpose != "" ) then str = str .. title_color .. "Purpose:</color>\n"..text_color..self.Purpose.."</color>\n\n" end if ( self.Instructions != "" ) then str = str .. title_color .. "Instructions:</color>\n"..text_color..self.Instructions.."</color>\n" end str = str .. "</font>" self.InfoMarkup = markup.Parse( str, 250 )end surface.SetDrawColor( 60, 60, 60, alpha ) surface.SetTexture( self.SpeechBubbleLid ) surface.DrawTexturedRect( x, y - 64 - 5, 128, 64 ) draw.RoundedBox( 8, x - 5, y - 6, 260, self.InfoMarkup:GetHeight() + 18, Color( 60, 60, 60, alpha ) ) self.InfoMarkup:Draw( x+5, y+5, nil, nil, alpha )end/*---------------------------------------------------------Name: SWEP:FreezeMovement()Desc: Return true to freeze moving the view---------------------------------------------------------*/ function SWEP:FreezeMovement() return falseend/*---------------------------------------------------------Name: SWEP:ViewModelDrawn()Desc: Called straight after the viewmodel has been drawn---------------------------------------------------------*/ function SWEP:ViewModelDrawn()end/*---------------------------------------------------------Name: OnRestoreDesc: Called immediately after a "load"---------------------------------------------------------*/ function SWEP:OnRestore()end/*---------------------------------------------------------Name: OnRemoveDesc: Called just before entity is deleted---------------------------------------------------------*/ function SWEP:OnRemove()end/*---------------------------------------------------------Name: CustomAmmoDisplayDesc: Return a table---------------------------------------------------------*/ function SWEP:CustomAmmoDisplay()end/*---------------------------------------------------------Name: GetViewModelPositionDesc: Allows you to re-position the view model---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang )return pos, angend/*---------------------------------------------------------Name: TranslateFOVDesc: Allows the weapon to translate the player's FOV (clientside)---------------------------------------------------------*/ function SWEP:TranslateFOV( current_fov )return current_fovend/*---------------------------------------------------------Name: DrawWorldModelDesc: Draws the world model (not the viewmodel)---------------------------------------------------------*/ function SWEP:DrawWorldModel() self.Weapon:DrawModel()end/*---------------------------------------------------------Name: DrawWorldModelTranslucentDesc: Draws the world model (not the viewmodel)---------------------------------------------------------*/ function SWEP:DrawWorldModelTranslucent() self.Weapon:DrawModel()end/*---------------------------------------------------------Name: AdjustMouseSensitivity()Desc: Allows you to adjust the mouse sensitivity.---------------------------------------------------------*/ function SWEP:AdjustMouseSensitivity() return nilend/*---------------------------------------------------------Name: GetTracerOrigin()Desc: Allows you to override where the tracer comes from (in first person view)returning anything but a vector indicates that you want the default action---------------------------------------------------------*/ function SWEP:GetTracerOrigin()/*local ply = self:GetOwner()local pos = ply:EyePos() + ply:EyeAngles():Right() * -5return pos*/end
init.lua:Lua Code:
AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) SWEP.Weight = 1 // Decides whether we should switch from/to this SWEP.AutoSwitchTo = true // Auto switch to if we pick it up SWEP.AutoSwitchFrom = true // Auto switch from if you pick up a better weapon local ActIndex = {} ActIndex[ "pistol" ] = ACT_HL2MP_IDLE_PISTOL ActIndex[ "smg" ] = ACT_HL2MP_IDLE_SMG1 ActIndex[ "grenade" ] = ACT_HL2MP_IDLE_GRENADE ActIndex[ "ar2" ] = ACT_HL2MP_IDLE_AR2 ActIndex[ "shotgun" ] = ACT_HL2MP_IDLE_SHOTGUN ActIndex[ "rpg" ] = ACT_HL2MP_IDLE_RPG ActIndex[ "physgun" ] = ACT_HL2MP_IDLE_PHYSGUN ActIndex[ "crossbow" ] = ACT_HL2MP_IDLE_CROSSBOW ActIndex[ "melee" ] = ACT_HL2MP_IDLE_MELEE ActIndex[ "slam" ] = ACT_HL2MP_IDLE_SLAM ActIndex[ "normal" ] = ACT_HL2MP_IDLE/*---------------------------------------------------------Name: SetWeaponHoldTypeDesc: Sets up the translation table, to translate from normalstanding idle pose, to holding weapon pose.---------------------------------------------------------*/ function SWEP:SetWeaponHoldType( t ) local index = ActIndex[ t ] if (index == nil) then Msg( "SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set!\n" )returnend self.ActivityTranslate = {} self.ActivityTranslate [ ACT_HL2MP_IDLE ] = index self.ActivityTranslate [ ACT_HL2MP_WALK ] = index+1 self.ActivityTranslate [ ACT_HL2MP_RUN ] = index+2 self.ActivityTranslate [ ACT_HL2MP_IDLE_CROUCH ] = index+3 self.ActivityTranslate [ ACT_HL2MP_WALK_CROUCH ] = index+4 self.ActivityTranslate [ ACT_HL2MP_GESTURE_RANGE_ATTACK ] = index+5 self.ActivityTranslate [ ACT_HL2MP_GESTURE_RELOAD ] = index+6 self.ActivityTranslate [ ACT_HL2MP_JUMP ] = index+7 self.ActivityTranslate [ ACT_RANGE_ATTACK1 ] = index+8end// Default hold pos is the melee SWEP:SetWeaponHoldType( "melee" )/*---------------------------------------------------------Name: weapon:TranslateActivity( )Desc: Translate a player's Activity into a weapon's activitySo for example, ACT_HL2MP_RUN becomes ACT_HL2MP_RUN_PISTOLDepending on how you want the player to be holding the weapon---------------------------------------------------------*/ function SWEP:TranslateActivity( act ) if ( self.Owner:IsNPC() ) then if ( self.ActivityTranslateAI[ act ] ) then return self.ActivityTranslateAI[ act ]end return -1end if ( self.ActivityTranslate[ act ] != nil ) then return self.ActivityTranslate[ act ]end return -1end/*---------------------------------------------------------Name: OnRestoreDesc: The game has just been reloaded. This is usually the right placeto call the GetNetworked* functions to restore the script's values.---------------------------------------------------------*/ function SWEP:OnRestore()end/*---------------------------------------------------------Name: AcceptInputDesc: Accepts input, return true to override/accept input---------------------------------------------------------*/ function SWEP:AcceptInput( name, activator, caller, data ) return falseend/*---------------------------------------------------------Name: KeyValueDesc: Called when a keyvalue is added to us---------------------------------------------------------*/ function SWEP:KeyValue( key, value )end/*---------------------------------------------------------Name: OnRemoveDesc: Called just before entity is deleted---------------------------------------------------------*/ function SWEP:OnRemove()end/*---------------------------------------------------------Name: EquipDesc: A player or NPC has picked the weapon up---------------------------------------------------------*/ function SWEP:Equip( NewOwner )end/*---------------------------------------------------------Name: EquipAmmoDesc: The player has picked up the weapon and has taken the ammo from itThe weapon will be removed immidiately after this call.---------------------------------------------------------*/ function SWEP:EquipAmmo( NewOwner )end/*---------------------------------------------------------Name: OnDropDesc: Weapon was dropped---------------------------------------------------------*/ function SWEP:OnDrop()end/*---------------------------------------------------------Name: ShouldDropOnDieDesc: Should this weapon be dropped when its owner dies?---------------------------------------------------------*/ function SWEP:ShouldDropOnDie() return trueend
shared.lua:Lua Code:
// Variables that are used on both client and server SWEP.Author = "Xaymar" SWEP.Contact = "perfectdeath545" SWEP.Purpose = "Adminstick" SWEP.Instructions = "Kick(P)/Ban(S) Stick for Admins" SWEP.ViewModelFOV = 62 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/weapons/v_stunstick.mdl" SWEP.WorldModel = "models/weapons/w_stunstick.mdl" SWEP.AnimPrefix = "python" SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Primary.ClipSize = 1 // Size of a clip SWEP.Primary.DefaultClip = 1 // Default number of bullets in a clip SWEP.Primary.Automatic = false // Automatic/Semi Auto SWEP.Primary.Ammo = "Pistol" SWEP.Secondary.ClipSize = 1 // Size of a clip SWEP.Secondary.DefaultClip = 1 // Default number of bullets in a clip SWEP.Secondary.Automatic = false // Automatic/Semi Auto SWEP.Secondary.Ammo = "Pistol" BanTime = 5/*---------------------------------------------------------Name: SWEP:Initialize( )Desc: Called when the weapon is first loaded---------------------------------------------------------*/ function SWEP:Initialize()end/*---------------------------------------------------------Name: SWEP:Precache( )Desc: Use this function to precache stuff---------------------------------------------------------*/ function SWEP:Precache()end/*---------------------------------------------------------Name: SWEP:PrimaryAttack( )Desc: +attack1 has been pressed---------------------------------------------------------*/ function SWEP:PrimaryAttack()// Make sure we can shoot first if ( !self:CanPrimaryAttack() ) then return end// Play shoot sound self.Weapon:EmitSound("Weapon_Stunstick.Single") local trace = {} trace.start = self.Owner:GetShootPos() trace.endpos = trace.start + (self.Owner:GetAimVector() * 150)trace.filter = self.Owner local tr = util.TraceLine(trace) if !tr.HitNonWorld then return end if !tr.Entity then return end if tr.Entity:IsPlayer() then local ply = player.GetByID( tr.Entity:EntIndex() ) ply:Kick("Kicked by ".. self.Owner:GetName() .."!(KickStick)" )endend/*---------------------------------------------------------Name: SWEP:SecondaryAttack( )Desc: +attack2 has been pressed---------------------------------------------------------*/ function SWEP:SecondaryAttack() local BanText = ""// Make sure we can shoot first if ( !self:CanSecondaryAttack() ) then return end// Play shoot sound self.Weapon:EmitSound("Weapon_Stunstick.Single") local trace = {} trace.start = self.Owner:GetShootPos() trace.endpos = trace.start + (self.Owner:GetAimVector() * 150)trace.filter = self.Owner local tr = util.TraceLine(trace) if !tr.HitNonWorld then return end if !tr.Entity then return end if tr.Entity:IsPlayer() then if BanTime > 0 then BanText = "for ".. tostring(BanTime) .." minutes"else BanText = "permanently"end local ply = player.GetByID( tr.Entity:EntIndex() ) ply:Ban(BanTime, "Banned by ".. self.Owner:GetName() .." ".. BanText .."!(KickStick)" )else BanTime = BanTime +5 if BanTime > 30 then BanTime = 0endendend/*---------------------------------------------------------Name: SWEP:CheckReload( )Desc: CheckReload---------------------------------------------------------*/ function SWEP:CheckReload()end/*---------------------------------------------------------Name: SWEP:Reload( )Desc: Reload is being pressed---------------------------------------------------------*/ function SWEP:Reload()end/*---------------------------------------------------------Name: SWEP:Think( )Desc: Called every frame---------------------------------------------------------*/ function SWEP:Think()end/*---------------------------------------------------------Name: SWEP:Holster( weapon_to_swap_to )Desc: Weapon wants to holsterRetV: Return true to allow the weapon to holster---------------------------------------------------------*/ function SWEP:Holster( wep ) return trueend/*---------------------------------------------------------Name: SWEP:Deploy( )Desc: Whip it out---------------------------------------------------------*/ function SWEP:Deploy() return trueend/*---------------------------------------------------------Name: SWEP:ShootBullet( )Desc: A convenience function to shoot bullets---------------------------------------------------------*/ function SWEP:ShootEffects() self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation self.Owner:MuzzleFlash() // Crappy muzzle light self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animationend/*---------------------------------------------------------Name: SWEP:ShootBullet( )Desc: A convenience function to shoot bullets---------------------------------------------------------*/ function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {}bullet.Num = num_bullets bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 5 // Show a tracer on every x bullets bullet.Force = 1 // Amount of force to give to phys objectsbullet.Damage = damage bullet.AmmoType = "Pistol" self.Owner:FireBullets( bullet ) self:ShootEffects()end/*---------------------------------------------------------Name: SWEP:TakePrimaryAmmo( )Desc: A convenience function to remove ammo---------------------------------------------------------*/ function SWEP:TakePrimaryAmmo( num )// Doesn't use clips if ( self.Weapon:Clip1() <= 0 ) then if ( self:Ammo1() <= 0 ) then return end self.Owner:RemoveAmmo( num, self.Weapon:GetPrimaryAmmoType() ) return end self.Weapon:SetClip1( self.Weapon:Clip1() - num )end/*---------------------------------------------------------Name: SWEP:TakeSecondaryAmmo( )Desc: A convenience function to remove ammo---------------------------------------------------------*/ function SWEP:TakeSecondaryAmmo( num )// Doesn't use clips if ( self.Weapon:Clip2() <= 0 ) then if ( self:Ammo2() <= 0 ) then return end self.Owner:RemoveAmmo( num, self.Weapon:GetSecondaryAmmoType() ) return end self.Weapon:SetClip2( self.Weapon:Clip2() - num )end/*---------------------------------------------------------Name: SWEP:CanPrimaryAttack( )Desc: Helper function for checking for no ammo---------------------------------------------------------*/ function SWEP:CanPrimaryAttack() return trueend/*---------------------------------------------------------Name: SWEP:CanSecondaryAttack( )Desc: Helper function for checking for no ammo---------------------------------------------------------*/ function SWEP:CanSecondaryAttack() return trueend/*---------------------------------------------------------Name: ContextScreenClick( aimvec, mousecode, pressed, ply )---------------------------------------------------------*/ function SWEP:ContextScreenClick( aimvec, mousecode, pressed, ply )end/*---------------------------------------------------------Name: OnRemoveDesc: Called just before entity is deleted---------------------------------------------------------*/ function SWEP:OnRemove()end/*---------------------------------------------------------Name: OwnerChangedDesc: When weapon is dropped or picked up by a new player---------------------------------------------------------*/ function SWEP:OwnerChanged()end/*---------------------------------------------------------Name: Ammo1Desc: Returns how much of ammo1 the player has---------------------------------------------------------*/ function SWEP:Ammo1() return self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() )end/*---------------------------------------------------------Name: Ammo2Desc: Returns how much of ammo2 the player has---------------------------------------------------------*/ function SWEP:Ammo2() return self.Owner:GetAmmoCount( self.Weapon:GetSecondaryAmmoType() )end/*---------------------------------------------------------Name: SetDeploySpeedDesc: Sets the weapon deploy speed.This value needs to match on client and server.---------------------------------------------------------*/ function SWEP:SetDeploySpeed( speed ) self.m_WeaponDeploySpeed = tonumber( speed )end



Zitieren