Raised This Month: $51 Target: $400
 12% 

[HL2:DM] Restricting Weapons on Spawn/Dropping Weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chadlytubbs
Junior Member
Join Date: May 2007
Old 03-09-2008 , 05:05   [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #1

I'm fairly new to SourceMod, so bear with me. I'm wondering if it's possible to restrict what weapons a player can spawn with in HL2: DM. For example, I might want players to only spawn with crowbars, but maybe they can pick up a gravity gun somewhere else in the map. I'm not wanting to restrict the weapon from the game altogether, just when the player spawns. Also, I'm curious as to whether or not its possible to force a player to drop the weapon they are currently holding. Anything to point me in the right direction would be a tremendous help. Thanks.
chadlytubbs is offline
chadlytubbs
Junior Member
Join Date: May 2007
Old 03-09-2008 , 17:41   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #2

After playing around with SourceMod, I've found a couple of really useful functions within sdktools that allow me to see what weapon is in which slot (GetPlayerWeaponSlot) and to remove weapons that weapon from it (RemovePlayerItem). Using these functions I was able to write my own function that removes a weapon from the specified slot.

PHP Code:
/**
 * Removes weapon from the specified client's slot.
 * ChadlyTubbs
 */
public bool:RemoveWeaponFromSlot(clientslot)
{
    
//get the entity id of the weapon in the client's slot specified
    
new bool:isRemoved;
    new 
weapon_entid GetPlayerWeaponSlot(client,slot);
    
//attempt to retrieve the weapon's entity id from the slot..
    
if(weapon_entid >= 0)
    {
        
//get the classname of the weapon
        
new String:weapon_classname[32];
        
GetEdictClassname(weapon_entidweapon_classname32);
        
//attempt to remove the weapon
        
isRemoved RemovePlayerItem(client,weapon_entid);
        
RemoveEdict(weapon_entid);
        if(
isRemoved)
        {
            
PrintToConsole(client,"Removed %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);
        }
        else
        {
            
PrintToConsole(client,"Could NOT remove %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);
        }
    }
    else
    {
        
isRemoved false;
        
PrintToConsole(client,"No weapon to remove from slot %d",slot);
    }
    return 
isRemoved;

This is close to what I'm trying to accomplish. What I'm really going for is a function like
PHP Code:
/**
 * Removes the specified weapon type from the client
 */
public bool:RemoveWeapon(clientString:weapon_classname
The only problem with this, is that HL2DM can store multiple weapons in the same slot. For example slot0 can potentially store up to 3 weapons: weapon_crowbar, weapon_stunstick, and weapon_physcannon. Using the GetPlayerWeaponSlot function, I can only retrieve 1 at a time. Is there anyway to loop through the weapons stored in the slot?

As for dropping the weapon on the ground, I guess the process would be:
1) Temporarily storing the amount of ammo in the weapon.
2) Getting the remove weapon function above to work.
3) Spawning a new weapon of the same type with the same ammo in front of the player on the ground.
I could still use a push in the right direction for this type of function.

Again, any help is most definitely appreciated. Thanks.

EDIT: Bug Report [Disregard. Error on my part. See next edit.]
This code actually causes glitch where some of the models of the removed weapons will appear to "float" around the user; even after the player dies and respawns. I filed a bug report and attached my testing plugin to it. Here's the link: http://bugs.alliedmods.net/index.php...s&task_id=1521

EDIT: Solution [duh]
RemoveEdict after RemovePlayerItem fixed the issue. The code above has been updated.

Last edited by chadlytubbs; 03-09-2008 at 20:28. Reason: I cannot brain today. I have the dumb.
chadlytubbs is offline
pRED*
Join Date: Dec 2006
Old 03-09-2008 , 20:25   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #3

I believe calling GetWeaponSlot a second time will retrieve the second weapon. So you can loop through them all.
pRED* is offline
chadlytubbs
Junior Member
Join Date: May 2007
Old 03-10-2008 , 12:13   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #4

The only way it seems that I can view other weapons stored in a slot is to remove the weapon stored first in a slot. For example, let's say slot 0 has the crowbar, physcannon, and stunstick stored in that order. By using GetWeaponSlot, I can only see that I have a crowbar. The only way that I can see that I have a physcannon is to first RemovePlayerItem on the crowbar entity. Then GetWeaponSlot will give me the entity id of the physcannon. I'd have to go through this same procedure if I want to see whether or not I have a stunstick. Is it possible to obtain a list of weapon entity id's linked to a player without looping through the weapon slots and having to remove any previous weapons?
chadlytubbs is offline
steambob
Member
Join Date: Sep 2007
Old 03-10-2008 , 12:36   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #5

I have done something similar for hl2dm and found it easier to strip all weapons at first and then give the player the weapons you want.

Also, if you want to do this on player spawn, it is useful to start a timer and make strip/give operations with a small delay (I've made 0.1 seconds, though 0.0 which is next frame would also probably work ).

If you want I can post my plugin. Using it and the Stripper Source plugin I've made a crossbow/gravgun only server (I hope I do not make anything wrong if I post here the server IP so you can take a look how it works: 62.104.166.243:27015)
steambob is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-10-2008 , 12:40   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #6

You can browse through all the weapons a client has with m_hMyWeapons

PHP Code:
bool:RemoveWeapon(client,const String:weapon[]) {
    
decl String:class[32], ent
    
new bool:isRemovedoffs FindSendPropInfo("CBasePlayer","m_hMyWeapons")

    for(new 
0<= 47i++) {
        
ent GetEntDataEnt2(client,offs + (4))

        if(
ent != -&& GetEdictClassname(ent,class,sizeof class) && strcmp(class,weapon) == 0) {
            
isRemoved RemovePlayerItem(client,ent)
            
RemoveEdict(ent)
            break
        }
    }

    return 
isRemoved

CSS has 47 weapon fields, donnu about HL2DM...
__________________
plop

Last edited by p3tsin; 03-16-2008 at 21:04. Reason: fixed offset in the loop as chadlytubbs noted 2 posts below
p3tsin is offline
BAILOPAN
Join Date: Jan 2004
Old 03-10-2008 , 17:35   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #7

Since you started at 0 that'd be 48 weapon fields. I think it's the same in HL2DM.

CS:S DM uses this (here is the HL2MP version):
Code:
219	CHL2MP_Player::Weapon_Drop(CBaseCombatWeapon *,Vector  const*,Vector  const*)
It's a virtual function in CBasePlayer. But if the solution you have is working now, I guess there's no reason to change it.
__________________
egg
BAILOPAN is offline
chadlytubbs
Junior Member
Join Date: May 2007
Old 03-10-2008 , 23:33   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #8

Thanks everyone for the quick responses.

@p3tsin - You just about nailed it. This was exactly what I was looking for. The only thing that needed to be changed was:
PHP Code:
ent GetEntDataEnt2(client,offs i*4); 
+karma

There is one nasty side effect: when calling this function on the weapon_rpg while the player is currently holding it, the targeting laser still shows up on the screen once it is removed. I have no idea how to remove it.

@BAILOPAN - Maybe the laser could be removed if I called the Weapon_Drop virtual function as opposed to the RemovePlayerItem function. I'm not really sure how to do this though. Could you post an example or a link to one?

Thanks again for the help everybody!
chadlytubbs is offline
BAILOPAN
Join Date: Jan 2004
Old 03-11-2008 , 00:01   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #9

something like this (note I did not test).

Code:
new Handle:hSDKWeaponDrop; StartPrepSDKCall(SDKCall_Player); PrepSDKCall_SetVirtual(219); PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer); PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef, VDECODE_FLAG_ALLOWNULL); PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef, VDECODE_FLAG_ALLOWNULL); hSDKWeaponDrop = EndPrepSDKCall(); SDKWeaponDrop(client, weaponEnt, const Float:vecTarget[3], const Float:velocity[3]) {     SDKCall(hSDKWeaponDrop, client, weaponEnt, vecTarget, velocity); }

vecTarget is the position to throw the weapon at. velocity is the velocity to throw it. NULL_VECTOR can be used for vecTarget and velocity, but velocity cannot be NULL if vecTarget is not NULL.
__________________
egg
BAILOPAN is offline
DiscoBBQ
Veteran Member
Join Date: Jan 2005
Location: Clemson, South Carolina
Old 03-16-2008 , 20:35   Re: [HL2:DM] Restricting Weapons on Spawn/Dropping Weapons
Reply With Quote #10

Code:
new Weapon_Offset = FindSendPropOffs("CSSPlayer", "m_hMyWeapons");
new Weapon_ID = GetEntDataEnt(Client, Weapon_Offset);
RemovePlayerItem(Client, Weapon_ID);
RemoveEdict(Weapon_ID);
Tested on HL2DM and works flawlessly, except i used HL2PLayer or whatev instead of CSSPLayer; for me Weapon_ID = crowbar, and then I just add 4 to go to the next weapon ext ext
__________________
"Every man is guilty of all the good he did not do"
DiscoBBQ is offline
Reply



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 21:15.


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