Raised This Month: $ Target: $400
 0% 

Is looking at player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KneeGrow
Junior Member
Join Date: Mar 2014
Old 07-30-2014 , 17:29   Is looking at player
Reply With Quote #1

I wanted to make a code where it will make the player use the command +attack if they are looking at another player, but I have no idea how to put it into code and have looked at other people's code but to no success.
This is what I've tried
PHP Code:
public plugin_init()
{
    
register_plugin(PLUGIN,VERSION,AUTHOR);
    
register_concmd("start","detect");
    
}
public 
detect(id){
    
    
    
    for(new 
i=1;i>0;i++){
        
        new 
target,body;
        
get_user_aiming(idtargetbody9999);
 
        if(!
is_user_alive(id))
        {
            if(
target>0){
                
client_cmd(id,"+attack");
            } else {
                
client_cmd(id,"-attack");
            }
        }
    
client_print(id,print_chat,"You are dead");
    return 
PLUGIN_HANDLED;
    }

But this ended up in me crashing and burning with it literally crashing (or at most freezing)

Last edited by KneeGrow; 07-30-2014 at 17:29.
KneeGrow is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-30-2014 , 17:48   Re: Is looking at player
Reply With Quote #2

for(new i=1;i>0;i++)

Your server is 'freezing' because you are starting a endless loop there. (i will always be bigger than 0...)
mottzi is offline
Send a message via MSN to mottzi
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-30-2014 , 23:47   Re: Is looking at player
Reply With Quote #3

This is the short way:
Code:
#include <amxmodx> public plugin_init() {     register_event( "StatusValue", "Event_StatusValue", "be", "1=2" );     register_event( "StatusValue", "Event_StatusValue_Stop", "be", "2=0" );     register_event( "DeathMsg", "Event_DeathMsg", "a" ); } public Event_StatusValue( id ) {     client_cmd( id, "+attack" ); } public Event_StatusValue_Stop( id ) {     client_cmd( id, "-attack" ); } public Event_DeathMsg() {     client_cmd( read_data( 2 ), "-attack" ); }

Although if a player disconnects during that time of auto fire their key will get "stuck on" a bit for the next time they join a server.

The full method is quite a bit of work.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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:09.


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