Raised This Month: $ Target: $400
 0% 

Common Issues and Examples/Solutions


Post New Thread Reply   
 
Thread Tools Display Modes
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-10-2012 , 02:12   Re: Common Issues and Examples/Solutions
Reply With Quote #31

Quote:
Originally Posted by ^SmileY View Post
A good way to remove droped weapons?

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new g_flDelay;

public 
plugin_init()
{
    
register_plugin("Remvoe Dropped Weapons""0.0.1""SavSin");
    
    
g_flDelay register_cvar("rdw_delay""0.5");
    
    
RegisterHam(Ham_Touch"item_thighpack""fwdWeaponDropped"1);//Rmoves Thighpack
    
RegisterHam(Ham_Touch"weaponbox""fwdWeaponDropped"1); //Weapon box spawn
    
RegisterHam(Ham_Touch"armoury_entity""fwdWeaponDropped"1); //Armor entity
}

public 
fwdWeaponDropped(iEnt)
{
    if(
pev_valid(iEnt))
    {
        
set_task(get_pcvar_float(g_flDelay), "RemoveWeapons"iEnt);
    }
}

public 
RemoveWeapons(iEnt)
{
    if(
pev_valid(iEnt))
    {
        new 
szModelName[32];
        
pev(iEntpev_modelszModelNamecharsmax(szModelName));
        
        if(
containi(szModelName"backpack") == -1)
        {
            
set_pev(iEntpev_flagsFL_KILLME);
            
ExecuteHam(Ham_ThinkiEnt);
        }
    }

Ive been using this.
Doc-Holiday is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-10-2012 , 08:23   Re: Common Issues and Examples/Solutions
Reply With Quote #32

I using one posted by xpaw, but dont remember'it


Using only fakemeta, its not only a weapon but any item
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-10-2012 , 11:09   Re: Common Issues and Examples/Solutions
Reply With Quote #33

Quote:
Originally Posted by ^SmileY View Post
I using one posted by xpaw, but dont remember'it


Using only fakemeta, its not only a weapon but any item
By item im not sure i know what you mean. In cs you only have by default weapons/armor/thighpack
Doc-Holiday is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-10-2012 , 16:53   Re: Common Issues and Examples/Solutions
Reply With Quote #34

This

Ps. I not sure if this code its been made by xPaw.

PHP Code:
#include <amxmodx>
#include <fakemeta>

#pragma semicolon 1

new pTime;

public 
plugin_init()
{
    
register_plugin("Remove Weapons",AMXX_VERSION_STR,"xPaw");

    
pTime register_cvar("remove_time","0.1");

    
register_forward(FM_SetModel,"FwdSetModel",1);
}

public 
FwdSetModel(iEntity)
{
    if(!
pev_valid(iEntity)) return 1;

    static const 
szWeaponbox[] = "weaponbox";
    static 
szClassname[10];

    
pev(iEntity,pev_classname,szClassname,charsmax(szClassname));
    
    if(
equal(szClassname,szWeaponbox)) set_pev(iEntity,pev_nextthink,get_gametime() + get_pcvar_float(pTime));

    return 
0;

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 03-10-2012 at 16:56.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-10-2012 , 19:08  
Reply With Quote #35

Quote:
Originally Posted by ^SmileY View Post
This

Ps. I not sure if this code its been made by xPaw.

PHP Code:
#include <amxmodx>
#include <fakemeta>

#pragma semicolon 1

new pTime;

public 
plugin_init()
{
    
register_plugin("Remove Weapons",AMXX_VERSION_STR,"xPaw");

    
pTime register_cvar("remove_time","0.1");

    
register_forward(FM_SetModel,"FwdSetModel",1);
}

public 
FwdSetModel(iEntity)
{
    if(!
pev_valid(iEntity)) return 1;

    static const 
szWeaponbox[] = "weaponbox";
    static 
szClassname[10];

    
pev(iEntity,pev_classname,szClassname,charsmax(szClassname));
    
    if(
equal(szClassname,szWeaponbox)) set_pev(iEntity,pev_nextthink,get_gametime() + get_pcvar_float(pTime));

    return 
0;

Should do the same. Ill have to change the way i do my timer i think his might be more efficient
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-11-2012 , 05:59   Re: Common Issues and Examples/Solutions
Reply With Quote #36

If you want a very efficient version you can use this one : https://forums.alliedmods.net/showpo...87&postcount=4 ; it patches in memory one time the original time 300 seconds by 0.1 second.
__________________

Last edited by Arkshine; 03-11-2012 at 06:00.
Arkshine is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-11-2012 , 14:56   Re: Common Issues and Examples/Solutions
Reply With Quote #37

Quote:
Originally Posted by Arkshine View Post
If you want a very efficient version you can use this one : https://forums.alliedmods.net/showpo...87&postcount=4 ; it patches in memory one time the original time 300 seconds by 0.1 second.
So adding in a delay for this is as simple as the code below? If its not the best way let me know. (Tested and it works)

PHP Code:
#include <amxmodx> 
#include <orpheu> 
#include <orpheu_memory> 
#include <orpheu_advanced> 

enum Function {packPlayerItemDropPlayerItemDropShield}; 
new 
g_flDelay

public 
plugin_init() 

    
register_plugin("Dropped Weapons Killer""1.0.0""Arkshine"); 
    
g_flDelay register_cvar("dwk_delay""10"); //Seconds before removal 
     
    
patch(packPlayerItemOrpheuGetFunctionAddress(OrpheuGetFunction("packPlayerItem"))); 
    
patch(DropPlayerItemOrpheuGetFunctionAddress(OrpheuGetFunction("DropPlayerItem","CBasePlayer")));
    
patch(DropShieldOrpheuGetFunctionAddress(OrpheuGetFunction("DropShield","CBasePlayer"))); 


public 
plugin_end() 

    
patch(packPlayerItem, .undo true); 
    
patch(DropPlayerItem, .undo true); 
    
patch(DropShield, .undo true); 


patch(const Function:currentFunctionstartAddress 0, const bool:undo false

    const 
Float:originalValue 300.0
    new 
Float:newValueget_pcvar_float(g_flDelay); 
     
    static 
SavedAddress[Function]; 
     
    
undo OrpheuMemorySetAtAddress(SavedAddress[currentFunction], "float"1originalValue) : 
           
OrpheuMemoryReplaceAtAddress(startAddress"float"1originalValuenewValueSavedAddress[currentFunction] ); 


Last edited by Doc-Holiday; 03-11-2012 at 15:05.
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-11-2012 , 17:08   Re: Common Issues and Examples/Solutions
Reply With Quote #38

No it's ok.
__________________
Arkshine is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 03-12-2012 , 01:26   Re: Common Issues and Examples/Solutions
Reply With Quote #39

Quote:
Originally Posted by Arkshine View Post
No it's ok.
Using the above code with CZ Bots. I was in Dust2_Cz and the bots just ran towards the door on the bottom of T spawn... And the CT Bots ran up the hill towards bombsite A and then ran into the wall and just went back and forth..

This is on a windows server (it was deleting the weapons correctly)

On the server we run.
Rage for CZ Bots register with ham
Round Terminator
Cvar Unlocker
Doc-Holiday is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-26-2014 , 12:36   Re: Common Issues and Examples/Solutions
Reply With Quote #40

Today, someone asked me how to restrict some buy commands. So, I made this code for him, with comments, and I think it's a good thing to share it

Code:
#include < amxmodx > #include < fakemeta > //Create a trie in which we will store all commands new Trie: g_tCommands public plugin_precache( ) {     //create a constant, in which we put all buy commands     //optionaly you can add cl_*buy ones     new const szCommands[ ] [ ] =     {         "usp", "glock", "deagle", "p228", "elites", "fn57", "m3", "xm1014",         "mp5", "tmp", "p90", "mac10", "ump45", "ak47", "galil", "famas",         "sg552", "m4a1", "aug", "scout", "awp", "g3sg1", "sg550", "m249",         "vest", "vesthelm", "flash", "hegren", "sgren", "defuser", "nvgs",         "shield", "primammo", "secammo", "km45", "9x19mm", "nighthawk",         "228compact", "12gauge", "autoshotgun", "smg", "mp", "c90", "cv47",         "defender", "clarion", "krieg552", "bullpup", "magnum", "d3au1", "krieg550",         "buyammo1", "buyammo2"     }         //create our trie. An array is not suitable for this.     g_tCommands = TrieCreate( )         //loop through all commands from constant     for( new i; i < sizeof szCommands; i++ )     {         //add it to the trie. command name will be the key         //command number will be the value         TrieSetCell( g_tCommands, szCommands[ i ], i )     }         //Hook FM_ClientCommand forward     register_forward( FM_ClientCommand, "pfnClientCommand") } public plugin_end( ) {     //Destroy the trie     TrieDestroy( g_tCommands ) } public pfnClientCommand( id ) {     //if he is no longer alive, don't do anything, let game decide     if( !is_user_alive( id ) )     {         return 0     }         //szCommand will hold the command     static szCommand[ 20 ]; read_argv( 0, szCommand, charsmax( szCommand ) )     static szLower[ 20 ]         //a player may write it capitalized, so we convert everything to lower letters     for( new i; i < sizeof szCommand; i ++ )     {         szLower[ i ] = tolower( szCommand[ i ] )     }         if( TrieKeyExists( g_tCommands, szLower ) )//we check if the key exists     {         //print a message and block the command         console_print( id, "Command is restricted" )         return FMRES_SUPERCEDE     }         return FMRES_IGNORED }
__________________

Last edited by HamletEagle; 08-26-2014 at 12:48.
HamletEagle 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 10:44.


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