AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   detect weapon and run commands (https://forums.alliedmods.net/showthread.php?t=159563)

razieljohn619 06-18-2011 22:32

detect weapon and run commands
 
hey guys i'm having problem with this.. i want to detect the weapons of players if it has this specific weapon (example M249) and if that player has that weapon this commands will run but only on that player that has that specific weapon..and it checks that weapon after each player spawn, because my server gives weapons auto when respawn and also has resapwn, ..thanks :D

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define PLUGIN "M249"
#define VERSION "1.0"
#define AUTHOR "razieljohn619"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
set_task(5.0"hasWeapon");
        
}


public 
hasWeapon(idweapid){
    new 
weapons[32], wnum
    get_user_weapons
(idweaponswnum)
    for(new 
0wnumi++){
        if(
weapons[i] == weapid) return 1
    
}
    return 
0
    
}
    if(
user_has_weapon(idCSW_M249)){
            
entity_set_int(weaponEV_INT_iuser41)
       
set_task(0.01"//commands..")
        {
        else 
        }
            
set_task(0.01"//commands2..")
    
        
}

public 
//commands..(id)
{

//commands..
    
}

public 
//commands2..(id)
{

//commands..



and also if player does not have that weapon the commands2 will run only on that player but if it has,. the commands.. will run on that player..hope you guys understand. i'm really hoping that this will work :D

and the errors are:
Code:

invalid declaration or something
unmatched closing brace


fysiks 06-19-2011 01:27

Re: detect weapon and run commands
 
plugin_ini() is only run one at the begining of the map. You need to detect when the player spawns. See this thread and bookmark it.

Oh, and FYI, the smallest value for the first argument of set_task() is 0.1

razieljohn619 06-19-2011 03:11

Re: detect weapon and run commands
 
should it be like this now??

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>
#include <hamsandwich>

#define PLUGIN "M249"
#define VERSION "1.0"
#define AUTHOR "razieljohn619"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""hasWeapon"1)  
        
}


public 
hasWeapon(idweapid){
    new 
weapons[32], wnum
    get_user_weapons
(idweaponswnum)
    for(new 
0wnumi++){
        if(
weapons[i] == weapid) return 1
    
}
    return 
0
    
}
    if(
user_has_weapon(idCSW_M249)){
            
entity_set_int(weaponEV_INT_iuser41)
       
set_task(0.1"//commands..")
        {
        else 
        }
            
set_task(0.1"//commands2..")
    
        
}

public 
//commands..(id)
{

//commands..
    
}

public 
//commands2..(id)
{

//commands..



and also is this correct
PHP Code:

        else 
        }
            
set_task(0.01"//commands2.."

this here should run if player has that weapon
PHP Code:

public //commands..(id)
{

//commands..
    


and if not this here should run
PHP Code:

public //commands2..(id)
{

//commands..



...so im asking if here is right
PHP Code:

    set_task(0.01"//commands..")
        {
        else 
        }
            
set_task(0.01"//commands2.."

pls help me thanks :D

Exolent[jNr] 06-19-2011 04:28

Re: detect weapon and run commands
 
... You are just making up stuff.

Describe what you want to do exactly, not what you are trying to do.
In other words, what is this plugin supposed to do?

razieljohn619 06-19-2011 06:17

Re: detect weapon and run commands
 
first my server gives specific weapons to each player depends on what class you have chosen and server has respawn.. what the plugins is supposed to do is when after player spawn it will detect what are the weapons of the player and if that has a weapon(like MP5) the
PHP Code:

public //commands..(id) 

will run and if does not have those weapons the
PHP Code:

public //commands2..(id) 

will run and these commands will run only on that player that is currently check that has these weapons(like MP5) or not..hope you understand :D because i really want these to work..

Exolent[jNr] 06-19-2011 06:25

Re: detect weapon and run commands
 
Code:
public plugin_init( ) {     RegisterHam( Ham_Spawn, "player", "FwdPlayerSpawnPost", 1 ); } public FwdPlayerSpawnPost( iPlayer ) {     if( is_user_alive( iPlayer ) )     {         if( user_has_weapon( iPlayer, CSW_MP5 ) )         {             // player has mp5         }         else         {             // player does not have mp5         }     } }

razieljohn619 06-19-2011 07:15

Re: detect weapon and run commands
 
should it look like this now??
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define PLUGIN "M249"
#define VERSION "1.0"
#define AUTHOR "razieljohn619"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""FwdPlayerSpawnPost"); 
   
        
}


public 
hasWeapon(idweapid){
    new 
weapons[32], wnum
    get_user_weapons
(idweaponswnum)
    for(new 
0wnumi++){
        if(
weapons[i] == weapid) return 1
    
}
    return 
0
    
}    

public 
FwdPlayerSpawnPostiPlayer )
{
    if( 
is_user_aliveiPlayer ) )
    {
        if( 
user_has_weaponiPlayerCSW_M249 ) )
        {
            
set_task(0.1"//player has")
        }
        else
        {
            
set_task(0.1"//player does not have")
        }
    }
        
}

public 
//player has(id)
{
    
//commands
    
}

public 
//player does not have(id)
{
    
//commands 


should it look like this now, because i'm having many errors on that part of
PHP Code:

RegisterHam(Ham_Spawn"player""FwdPlayerSpawnPost"); 

can you help me..pls..thanks :D

EDIT:
it now works because i included hamsandwich..thanks Exolent :D

i dont know if it's working or not..and how about detecting if player has shield and runs commands if has shield or not, just like here
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define PLUGIN "M249"
#define VERSION "1.0"
#define AUTHOR "razieljohn619"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""FwdPlayerSpawnPost"); 
   
        
}


public 
hasWeapon(idweapid){
    new 
weapons[32], wnum
    get_user_weapons
(idweaponswnum)
    for(new 
0wnumi++){
        if(
weapons[i] == weapid) return 1
    
}
    return 
0
    
}    

public 
FwdPlayerSpawnPostiPlayer )
{
    if( 
is_user_aliveiPlayer ) )
    {
        if( 
user_has_weaponiPlayerCSW_M249 ) )
        {
            
set_task(0.1"//player has")
        }
        else
        {
            
set_task(0.1"//player does not have")
        }
    }
        
}

public 
//player has(id)
{
    
//commands
    
}

public 
//player does not have(id)
{
    
//commands 


but only detect if has shield..thanks :D

Exolent[jNr] 06-19-2011 07:49

Re: detect weapon and run commands
 
Delete this:
PHP Code:

public hasWeapon(idweapid){
    new 
weapons[32], wnum
    get_user_weapons
(idweaponswnum)
    for(new 
0wnumi++){
        if(
weapons[i] == weapid) return 1
    
}
    return 
0
    


You are not even using it.
Even if you need a function like that, use user_has_weapon().

razieljohn619 06-19-2011 08:16

Re: detect weapon and run commands
 
how about detecting if player has shield and do the commands??

Exolent[jNr] 06-19-2011 08:19

Re: detect weapon and run commands
 
http://www.amxmodx.org/funcwiki.php?...ield&go=search


All times are GMT -4. The time now is 23:26.

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