Raised This Month: $319 Target: $400
 79%   Almost there!

[L4D2] Keep Laser Sights (v1.2, 2012 Jan 7)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
dcx2
Senior Member
Join Date: Sep 2011
Plugin ID:
2703
Plugin Version:
1.2
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Keep existing laser sights when picking up a new gun
    Old 12-10-2011 , 00:58   [L4D2] Keep Laser Sights (v1.2, 2012 Jan 7)
    Reply With Quote #1

    When I find laser sights, I want to keep them, even if I switch guns. Why can't I just take the laser sight off one and put it onto the other gun?

    So I wrote this plugin. When a player drops a weapon, it checks to see if there's a laser sight on it. If there is, it removes the laser sight from the dropped gun and adds it to whatever gun was picked up.

    This only works if you already have laser sights. It won't give you laser sights if you don't already have them.

    This is my first plugin so let me know if there's anything I can do to improve it. Thanks to Mr. Zero for l4dstocks.

    EDIT:

    2011-Dec-18 (version 1.1): fixed "gun spawn spam glitch". Also added cvar to remove hint. 71 views

    EDIT2:

    Still a bit nooby at this sourcemod stuff. I realized that this plugin does not require SDKHooks. It uses sdktools instead, so the web compiler works fine, therefore I removed the precompiled smx.

    EDIT3:

    2012-Jan-7 (version 1.2): Added a cvar for mode; Swap, Keep, or Always. See below.

    PLANS:

    1) Preserve other upgrades (fire ammo, explosive ammo)

    CVARS:

    sm_keeplasers_enable - default 1 - enables this plugin
    sm_keeplasers_nohint - default 1 - disables hint on receiving laser sights
    sm_keeplasers_mode - default 0 -
    0 = Swap laser sights from dropped gun to current gun; if no current gun (e.g. player died), old gun keeps lasers.
    1 = Keep laser sights once found, even if player dies and respawns
    2 = Always give players laser sights, even if they were never found
    sm_keeplasers_debug - default 0 - print debugging output to chat

    UPGRADING:

    If upgrading, backup any modifications made to [game]/cfg/sourcemod/L4D2_KeepLasers.cfg, then delete that file and restart your server. The file will be auto-created again with the new cvars. Modify as needed.
    Attached Files
    File Type: sp Get Plugin or Get Source (l4d2_keeplasers.sp - 7342 views - 12.3 KB)

    Last edited by dcx2; 01-07-2012 at 17:00. Reason: version 1.2
    dcx2 is offline
    ResistanceYoshi
    Junior Member
    Join Date: Dec 2010
    Old 12-11-2011 , 18:10   Re: [L4D2] Keep Laser Sights
    Reply With Quote #2

    Great idea, great plugin.

    Currently bug-free as far as I know and personally I think it's a must have to get this plugin in your server.

    Edit: I have encountered 2 things:

    1: Everything you swap a weapon, the laser sights hint message pops-up.

    2: Whenever swapping a weapon at a certain case that there are weapon spawns (ex: You are holding an M16, you found a AK47 spawn and another M16 spawn). If you constantly switch weapons by swapping the 2 weapons alternatively, instead of the weapons being placed back where they're supposed to be, you end up dropping every single AK47 + M16 found dropped on the ground like a prop, creating a messy pile of weapons.
    __________________
    There's nothing you need to know about me, I'm just your everyday Green Yoshi.


    Last edited by ResistanceYoshi; 12-12-2011 at 22:12. Reason: Possible plugin problems
    ResistanceYoshi is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 12-12-2011 , 23:07   Re: [L4D2] Keep Laser Sights
    Reply With Quote #3

    Thanks for the feedback.

    1) I don't think there's anything I can do about the hint message. Under the hood, I'm just doing "upgrade_add laser_sight". I had originally tried just adding the laser_sight flag to the gun but I don't remember that working, which is why I went with the cheat instead.

    2) This doesn't sound good...I've read other plugins that had a problem like this and folks would exploit it to crash the server.

    However, I haven't seen that behavior. When I drop guns near a spawn of the dropped gun's type, the gun I dropped disappears.

    What campaign/map were you on?

    FYI, this plugin has a cvar, sm_keeplasers_enable. 1 = on, 0 = off.
    dcx2 is offline
    ResistanceYoshi
    Junior Member
    Join Date: Dec 2010
    Old 12-13-2011 , 20:21   Re: [L4D2] Keep Laser Sights
    Reply With Quote #4

    The map I was playing was on "TankFever1 Forever" which is found at ( The map I was playing was on "TankFever1 Forever" which is found at ( http://www.l4dmaps.com/details.php?file=9381 )

    But however by looking at the bug, I would assume that the bug would affect all campaigns/ maps.
    __________________
    There's nothing you need to know about me, I'm just your everyday Green Yoshi.

    ResistanceYoshi is offline
    Mr. Zero
    Veteran Member
    Join Date: Jun 2009
    Location: Denmark
    Old 12-14-2011 , 12:59   Re: [L4D2] Keep Laser Sights
    Reply With Quote #5

    Quote:
    Originally Posted by dcx2 View Post
    1) I don't think there's anything I can do about the hint message. Under the hood, I'm just doing "upgrade_add laser_sight". I had originally tried just adding the laser_sight flag to the gun but I don't remember that working, which is why I went with the cheat instead.
    (Nice use of stocks ;3)

    PHP Code:
    L4D2_SetWeaponUpgrades(weaponL4D2_GetWeaponUpgrades(weapon) | L4D2_WEPUPGFLAG_LASER); 
    Works fine from what I can test.

    I have another script where I apply laser sights to players after spawning. No director hint is shown so it should be working.
    Mr. Zero is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 12-14-2011 , 13:14   Re: [L4D2] Keep Laser Sights
    Reply With Quote #6

    I actually tried the L4D2_SetWeaponUpgrades at first (thanks for the stocks btw, I copied them directly into the source file so others wouldn't need to find your stocks to make the plugin compile, but I left a comment with your name in it)

    But it didn't seem to work for me, hence why I went the upgrade_add route. I will try SetWeaponUpgrades again, probably this weekend.

    In hind sight, the problem might have been that you need to wait a bit after the Weapon Drop event before the player is actually holding the new gun. I had that problem with upgrade_add, and the timer delay solved it, but I probably didn't test if the timer solved the SetWeaponUpgrades flag.

    Honestly, I kinda like getting the hint message and hearing the sound. It's a satisfying sound, like opening a chest in Zelda. If SetWeaponUpgrades works, I'll probably add a cvar so you can choose whether or not you want to see the hint/hear the sound.

    EDIT:

    Well this is interesting. The guns didn't drop in Survival, and they don't drop if you don't have the laser sight. I presume the game clears out a "base" weapon when it's dropped. But since you dropped a laser sight, it doesn't clear the weapon you dropped. But my plugin takes the laser sight off *after* it's been dropped (i.e. after the game has decided not to clear it).

    If the guns are dropped enough times, the weapon spawn goes away. So you can't use this to crash the server. That's good news, at least.

    I'm not sure what I can do about this. Is there a way to "redrop" the gun so the game can decide whether to remove it?

    Last edited by dcx2; 12-14-2011 at 22:33. Reason: didn't want to make a second reply
    dcx2 is offline
    Mr. Zero
    Veteran Member
    Join Date: Jun 2009
    Location: Denmark
    Old 12-15-2011 , 03:03   Re: [L4D2] Keep Laser Sights
    Reply With Quote #7

    We had that problem with another plugin, I used SDKHooks to fix that.

    PHP Code:
    public OnClientPostAdminCheck(client)
    {
        if (
    client <= 0) return;

        
    SDKHook(clientSDKHook_WeaponEquipPostOnClientWeaponEquip);
        
    SDKHook(clientSDKHook_WeaponDropPostOnClientWeaponDrop);
    }

    public 
    OnClientWeaponEquip(clientweapon)
    {
        if (
    client <= || !IsClientInGame(client) || L4DTeam:GetClientTeam(client) != L4DTeam_Survivor || !IsPlayerAlive(client)) return; // Invalid survivor, return

        
    new priWeapon GetPlayerWeaponSlot(client_:L4DWeaponSlot_Primary); // Get primary weapon
        
    if (priWeapon <= || !IsValidEntity(priWeapon)) return; // Invalid weapon, return

        
    decl String:netclass[128];
        
    GetEntityNetClass(priWeaponnetclass128);
        if (
    FindSendPropInfo(netclass"m_upgradeBitVec") < 1) return; // This weapon does not support upgrades

        
    new upgrades L4D2_GetWeaponUpgrades(priWeapon); // Get upgrades of primary weapon
        
    if (upgrades L4D2_WEPUPGFLAG_LASER) return; // Primary weapon already have laser sight, return

        
    L4D2_SetWeaponUpgrades(priWeaponupgrades L4D2_WEPUPGFLAG_LASER); // Add laser sight to primary weapon
    }

    public 
    OnClientWeaponDrop(clientweapon)
    {
        if (
    client <= || !IsClientInGame(client) || L4DTeam:GetClientTeam(client) != L4DTeam_Survivor) return; // Invalid survivor, return

        
    if (weapon <= || !IsValidEntity(weapon)) return; // Invalid weapon, return

        
    decl String:netclass[128];
        
    GetEntityNetClass(weaponnetclass128);
        if (
    FindSendPropInfo(netclass"m_upgradeBitVec") < 1) return; // This weapon does not support upgrades

        
    new upgrades L4D2_GetWeaponUpgrades(weapon); // Get upgrades of dropped weapon
        
    if (!(upgrades L4D2_WEPUPGFLAG_LASER)) return; // Weapon did not have laser sight, return

        
    L4D2_SetWeaponUpgrades(weaponupgrades L4D2_WEPUPGFLAG_LASER); // Remove laser sight from weapon

    Mr. Zero is offline
    ResistanceYoshi
    Junior Member
    Join Date: Dec 2010
    Old 12-16-2011 , 20:24   Re: [L4D2] Keep Laser Sights
    Reply With Quote #8

    Tested the plugin for the presence of the bug I have mention since the last post. It is true as it may may affect all maps/campaigns.

    I'm not too fond of having a pile of weapons left behind as the weapons spawns looks cleaner, but then again, you may decide what to do.

    (Tested in the beginning safe room at Dead Center: Chapter 2)
    __________________
    There's nothing you need to know about me, I'm just your everyday Green Yoshi.

    ResistanceYoshi is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 12-17-2011 , 12:28   Re: [L4D2] Keep Laser Sights
    Reply With Quote #9

    I will be modifying this plugin to add new features.

    1) I will add a cvar to enable no hint (default no hint).

    2) I will add a cvar that should fix the gun spawn glitch (default fixed). I will call it "realistic". Allow me to explain.

    I like the original behavior, because when you die the gun is dropped on the ground. If you spawn from a closet, you have to go pick up the gun, and it still has the laser sight. If you die and don't come back, your laser sight is gone for good. This is more realistic and was the original intention.

    Mr Zero's technique of removing the laser sight instantly can cause the gun to disappear (that's the behavior we're shooting for). Well, if you die, your gun falls, loses the laser sight, and disappears, sp you can't get the laser sight back. So I have to track which clients have had laser sights already, and every time they equip a new gun I have to give them new laser sights. This means that you'll have laser sights coming out of closets and in safe rooms etc. I'm not sure how to fix that specific issue.

    3) In the spirit of auto grab laser sight, since it will be pretty trivial to add that to this plugin, I'm going to add a cvar to do that, too. Then you'll only need one plugin and set the cvars as needed.

    I should have this done later today.

    EDIT:

    I think there's something Weapon Factory plugin. So if I had to put laser sights on a dropped gun because there's no player to give them to, and the gun was disappeared by the Director, I could just spawn one from nothing with a laser sight. I'll still leave the cvar though, in case you want permanent laser sights once they're found, regardless of death.

    EDIT2:

    Mr. Zero, you do it differently than I do. I use HookEvent and OnPluginStart, you use SDKHook and OnClientPostAdminCheck. Could you perhaps explain the difference?

    Last edited by dcx2; 12-17-2011 at 16:23. Reason: Not double posting
    dcx2 is offline
    dcx2
    Senior Member
    Join Date: Sep 2011
    Old 12-18-2011 , 13:11   Re: [L4D2] Keep Laser Sights
    Reply With Quote #10

    I'm double-posting to generate notification emails for anyone following this thread.

    This has been updated to version 1.1. At this point I don't have the different "modes"; this is only an improvement on 1.0 which doesn't suffer from the "gun spawn spam glitch", and which allows the hint to be disabled.

    I plan on adding modes later, but I figured I would post this now since I have tested it and it works.

    I have tested dying, and the gun you drop keeps the laser sight. In fact, when you die and the weapon_drop event is called, you are still technically alive, but your health is <= 0. So if you're "dying" then I do not remove the laser sight.

    I have tested the WeaponDrop SDK call. If you drop your laser sight gun, and you don't pick up a new one, it will put the laser sight back on the old gun.

    The next version will support "permanent laser sights once found" and "permanent laser sights always" via a mode cvar.
    dcx2 is offline
    Reply


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 13:04.


    Powered by vBulletin®
    Copyright ©2000 - 2021, vBulletin Solutions, Inc.
    Theme made by Freecode