Raised This Month: $ Target: $400
 0% 

detect weapon and run commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
razieljohn619
Senior Member
Join Date: May 2011
Location: Philippines
Old 06-18-2011 , 22:32   detect weapon and run commands
Reply With Quote #1

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

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

and the errors are:
Code:
invalid declaration or something
unmatched closing brace
__________________


Last edited by razieljohn619; 06-18-2011 at 22:34.
razieljohn619 is offline
Send a message via Yahoo to razieljohn619
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-19-2011 , 01:27   Re: detect weapon and run commands
Reply With Quote #2

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
__________________
fysiks is online now
razieljohn619
Senior Member
Join Date: May 2011
Location: Philippines
Old 06-19-2011 , 03:11   Re: detect weapon and run commands
Reply With Quote #3

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
__________________

razieljohn619 is offline
Send a message via Yahoo to razieljohn619
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2011 , 04:28   Re: detect weapon and run commands
Reply With Quote #4

... 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?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
razieljohn619
Senior Member
Join Date: May 2011
Location: Philippines
Old 06-19-2011 , 06:17   Re: detect weapon and run commands
Reply With Quote #5

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 because i really want these to work..
__________________

razieljohn619 is offline
Send a message via Yahoo to razieljohn619
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2011 , 06:25   Re: detect weapon and run commands
Reply With Quote #6

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         }     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
razieljohn619
Senior Member
Join Date: May 2011
Location: Philippines
Old 06-19-2011 , 07:15   Re: detect weapon and run commands
Reply With Quote #7

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

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

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
__________________


Last edited by razieljohn619; 06-19-2011 at 07:34.
razieljohn619 is offline
Send a message via Yahoo to razieljohn619
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2011 , 07:49   Re: detect weapon and run commands
Reply With Quote #8

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().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
razieljohn619
Senior Member
Join Date: May 2011
Location: Philippines
Old 06-19-2011 , 08:16   Re: detect weapon and run commands
Reply With Quote #9

how about detecting if player has shield and do the commands??
__________________

razieljohn619 is offline
Send a message via Yahoo to razieljohn619
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-19-2011 , 08:19   Re: detect weapon and run commands
Reply With Quote #10

http://www.amxmodx.org/funcwiki.php?...ield&go=search
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 23:26.


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