AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   is this method correct? (https://forums.alliedmods.net/showthread.php?t=215028)

Blizzard_87 05-02-2013 23:29

is this method correct?
 
is this method correct in detecting if weapon is in certain group then makeing sure to strip receiver of that weapon group before getting new weapon?

Code:
if( equal( type, "guns" ) )     {           new szWeaponNameD[ 32 ], iWeaponD = get_user_weapon( id );         get_weaponname( iWeaponD, szWeaponNameD, 31);                 for( new i = 0; i < sizeof Primary && i < sizeof Secondary && i < sizeof Grenade; i++ )         {             if( equal( szWeaponNameD, Grenade[ i ] ) )             {                 ham_strip_weapon( id, szWeaponNameD );                 ham_strip_weapon( g_iDonationTarget, Grenade[ i ] );                 ham_give_weapon( g_iDonationTarget, szWeaponNameD );             }                         else if( equal( szWeaponNameD, Secondary[ i ] ) )             {                 ham_strip_weapon( id, szWeaponNameD );                 ham_strip_weapon( g_iDonationTarget, Secondary[ i ] );                 ham_give_weapon( g_iDonationTarget, szWeaponNameD );             }                         else if( equal( szWeaponNameD, Primary[ i ] ) )             {                 ham_strip_weapon( id, szWeaponNameD );                 ham_strip_weapon( g_iDonationTarget, Primary[ i ] );                 ham_give_weapon( g_iDonationTarget, szWeaponNameD );             }         }                 Color( 0, "%s !t%s!n Donated !g%s!n To !t%s!n", PREFIX, dName, szWeaponNameD, rName );         show_dhudmessage( g_iDonationTarget, "[ Donation Revieved ]^n^n Weapon: %s^n^nFrom %s", szWeaponNameD, dName );     }

guipatinador 05-03-2013 03:21

Re: is this method correct?
 
PHP Code:

// only weapon index or its name can be passed, if neither is passed then the current gun will be transferred
stock bool:fm_transfer_user_gun(index1index2wid 0, const wname[] = ""

fakemeta_util.inc

Blizzard_87 05-03-2013 05:13

Re: is this method correct?
 
Quote:

Originally Posted by guipatinador (Post 1944838)
PHP Code:

// only weapon index or its name can be passed, if neither is passed then the current gun will be transferred
stock bool:fm_transfer_user_gun(index1index2wid 0, const wname[] = ""

fakemeta_util.inc

this doesnt work with Grenades....

Strick3n 05-03-2013 07:26

Re: is this method correct?
 
no that's incorrect, you should use one loop for each check.

hornet 05-03-2013 09:29

Re: is this method correct?
 
-POST UPDATED-

Try this now, should work for all weapons including shield and C4.
Code:
#define MAX_WEAPON_SLOTS    6 #define OFFSET_PLAYER       5 #define OFFSET_WEAPON       4 #define OFFSET_SHIELD       24 #define m_iClip         51 #define m_fHasPrimary       116 #define m_pActiveItem       373 #define m_iUserPrefs        510 new const m_rgpPlayerItems[ MAX_WEAPON_SLOTS ] = { 367, 368, ... };

Code:
bool:transfer_user_current_weapon( const iOwner, const iTarget ) {     new iActiveItem = get_pdata_cbase( iOwner, m_pActiveItem, OFFSET_PLAYER );     new iClip = get_pdata_int( iActiveItem, m_iClip, OFFSET_WEAPON );         new szWeapon[ 32 ];         if( get_pdata_int( iOwner, m_iUserPrefs, OFFSET_PLAYER ) & ( 1<<OFFSET_SHIELD ) )     {         strip_user_weapon( iTarget, 1 );         set_pdata_int( iTarget, m_fHasPrimary, 0, OFFSET_PLAYER );         give_item( iTarget, "weapon_shield" );         deploy_next_best( iTarget );                 set_pdata_int( iOwner, m_iUserPrefs, get_pdata_int( iOwner, m_iUserPrefs, OFFSET_PLAYER ) & ~( 1<<OFFSET_SHIELD ), OFFSET_PLAYER );                 new iBest = deploy_next_best( iOwner );                 pev( iBest, pev_classname, szWeapon, charsmax( szWeapon ) );         replace( szWeapon, charsmax( szWeapon ), "weapon_", "" );         format( szWeapon, charsmax( szWeapon ), "models/v_%s.mdl", szWeapon );         set_pev( iOwner, pev_viewmodel2, szWeapon );                 return true;     }         pev( iActiveItem, pev_classname, szWeapon, charsmax( szWeapon ) );         new iWeapon = get_weaponid( szWeapon );         new iSlot;         if( contain( szWeapon, "flash" ) == -1 && contain( szWeapon, "nade" ) == -1 )     {         if( iWeapon == CSW_C4  )         {             if( user_has_weapon( iTarget, CSW_C4 ) )                 return false;                         give_item( iTarget, "weapon_c4" );             deploy_next_best( iTarget );                         strip_user_weapon( iOwner, 5 );             deploy_next_best( iOwner );                         return true;         }                 if( iClip < 0 )             return false;                 new iAmmo = cs_get_user_bpammo( iOwner, iWeapon );                 for( new i = 1 ; i < MAX_WEAPON_SLOTS ; i ++ )         {             if( iActiveItem == get_pdata_cbase( iOwner, m_rgpPlayerItems[ i ], OFFSET_PLAYER ) )             {                 iSlot = i;                 break;             }         }                 if( get_pdata_cbase( iTarget, m_rgpPlayerItems[ iSlot ], OFFSET_PLAYER ) > 0 )             strip_user_weapon( iTarget, iSlot );             get_weaponname( iWeapon, szWeapon, charsmax( szWeapon ) );             cs_set_weapon_ammo( give_item( iTarget, szWeapon ), iClip );         cs_set_user_bpammo( iTarget, iWeapon, iAmmo );                 cs_set_user_bpammo( iOwner, iWeapon, 0 );         strip_user_weapon( iOwner, iSlot );     }     else     {           switch( iWeapon )         {             case CSW_SMOKEGRENADE, CSW_HEGRENADE:                 if( user_has_weapon( iTarget, iWeapon ) )                     return false;                                 case CSW_FLASHBANG:                 if( cs_get_user_bpammo( iTarget, CSW_FLASHBANG ) == 2 )                     return false;         }                 cs_set_user_bpammo( iOwner, iWeapon, cs_get_user_bpammo( iOwner, iWeapon ) - 1 );         give_item( iTarget, szWeapon );     }         engclient_cmd( iTarget, szWeapon );     deploy_next_best( iOwner );         return true; }

Code:
strip_user_weapon( const id, const iSlot ) {     new iEnt = get_pdata_cbase( id, m_rgpPlayerItems[ iSlot ], OFFSET_PLAYER );         if( pev_valid( iEnt ) )     {         new szWeapon[ 32 ];                 pev( iEnt, pev_classname, szWeapon, charsmax( szWeapon ) );         set_pev( id, pev_weapons, pev( id, pev_weapons ) & ~( 1<<get_weaponid( szWeapon ) ) );                 set_pdata_cbase( id, m_rgpPlayerItems[ iSlot ], -1, OFFSET_PLAYER );     } }

Code:
deploy_next_best( const id ) {     new iEnt, szWeapon[ 32 ];         for( new i = 1 ; i < MAX_WEAPON_SLOTS ; i ++ )     {         iEnt = get_pdata_cbase( id, m_rgpPlayerItems[ i ], OFFSET_PLAYER );                 if( iEnt > 0 )         {             pev( iEnt, pev_classname, szWeapon, charsmax( szWeapon ) );             engclient_cmd( id, szWeapon );                         break;         }     }         return iEnt; }

Blizzard_87 05-03-2013 17:14

Re: is this method correct?
 
tested and only thing is if you donate to your self it strips weapon but does not give.. but thats ok i'll just edit the player list to not show yourself.

hornet 05-04-2013 08:32

Re: is this method correct?
 
I've updated my original post. Try it out.
Also no I didn't take transferring to self into consideration - it seems like a silly idea for your plugin anyway ;)

Blizzard_87 05-06-2013 18:24

Re: is this method correct?
 
Quote:

Originally Posted by hornet (Post 1945546)
I've updated my original post. Try it out.
Also no I didn't take transferring to self into consideration - it seems like a silly idea for your plugin anyway ;)

thanks seems to be working, uploading Beta version of my new update. for Donations.


All times are GMT -4. The time now is 10:49.

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