AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is looking at player (https://forums.alliedmods.net/showthread.php?t=245273)

KneeGrow 07-30-2014 17:29

Is looking at player
 
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)

mottzi 07-30-2014 17:48

Re: Is looking at player
 
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...)

hornet 07-30-2014 23:47

Re: Is looking at player
 
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.


All times are GMT -4. The time now is 13:04.

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