AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if player is in screen (https://forums.alliedmods.net/showthread.php?t=47854)

mateo10 11-28-2006 03:11

Check if player is in screen
 
Hello.
How do i check if the players can see another guy in their screen?
I'm making a plugin where (with a command) the player will automaticaly
duck if another player in screen. How do i check if that player is in screen?

Help will be appreciated.

Thanks,
MaTTe

jim_yang 11-28-2006 03:16

Re: Check if player is in screen
 
is_in_viewcone ( entity, Float: origin[3] )

VEN 11-28-2006 03:24

Re: Check if player is in screen
 
Plus, you need to check if the player is visible.
Also is_in_viewcone method isn't 100% accurate in 3D.

mateo10 11-28-2006 03:29

Re: Check if player is in screen
 
Is a player an entity?
Can I use if(is_in_viewcone(player, ...)

Last question:
How do I work with origin?
I just want to know if the player is in the screen so i can perform the action.

dutchmeat 11-28-2006 03:36

Re: Check if player is in screen
 
Code:
new spotted[33] public server_frame(){ new Float:origin[3] new players[32],pNum get_players(players,pNum,"a")  for(new i=0;i<pNum;i++)  {   get_user_origin(i, origin)   if( is_in_viewcone(id, origin)){   spotted[i] = 1 //the player got spotted   }else{   spotted[i] = 0 //make sure that the flag is off while not spotted.   }  } }

jim_yang 11-28-2006 03:54

Re: Check if player is in screen
 
change get_user_origin(i, origin)
to entity_get_vector(players[i], EV_VEC_origin, origin)

mateo10 11-28-2006 04:25

Re: Check if player is in screen
 
@dutchmeat That code doesn't work cause you're not able to use ids
in public server_frame() it just says "undefined symbol "id"" when i compile
and when i add server_frame(id) it says "function heading differs from
prototype." So what shall i do?

mateo10 11-28-2006 04:44

Re: Check if player is in screen
 
OK ill post my plugin now and you can tell me what's wrong:
Code:
#include <amxmodx> #include <amxmisc> #include <amxconst> #include <engine> public plugin_init() {     register_plugin("Duck When Player In Screen (DWPIS)", "1.0", "MaTTe (mateo10)")     register_cvar("dwa_enable", "1")     register_concmd("amx_dwa", "cmd_dwa", ADMIN_BAN) } public server_frame(id) {     new Float:origin[3]     new players[32], pNum     get_players(players, pNum, "a")     for(new i=0;i<pNum;i++)     {         entity_get_vector(players[i], EV_VEC_origin, origin)         if(is_in_viewcone(id, origin)         {             set_task(0.1, "do_duck", id)         } else         {             return PLUGIN_CONTINUE         }     }     return PLUGIN_CONTINUE } public cmd_dwa(id, level, cid) {     if(!get_cvar_num("dwa_enable"))         return PLUGIN_HANDLED     if(!(get_user_flags(id) & ADMIN_BAN))     {         client_print(id, print_console, "[DWA] You need access level ADMIN_BAN for this command.")         return PLUGIN_HANDLED     }     new arg[32]     read_argv(1, arg, 31)     new player     player = cmd_target(id, arg, 5)     if(!player)         return PLUGIN_HANDLED     if(is_user_bot(player))         return PLUGIN_HANDLED     new params[1]     params[0] = player     return PLUGIN_CONTINUE } public do_jump(id) {     client_cmd(id, "+jump") } public do_duck(id) {     client_cmd(id, "+duck") }

VEN 11-28-2006 05:07

Re: Check if player is in screen
 
Don't use server_frame - it's inefficient.
You could use for example client_PreThink.

Quote:

Plus, you need to check if the player is visible.

native is_visible(entity, target);

jim_yang 11-28-2006 05:15

Re: Check if player is in screen
 
if(is_in_viewcone(id, origin)
{
set_task(0.1, "do_duck", id)
} else
{
return PLUGIN_CONTINUE
}

the situation you did that is:
if the first person is not in your view, then cancel this function
but in fact maybe second one is in your view. so you should change that to
if(is_in_viewcone(id, origin)
{
set_task(0.1,"do_duck",id)
return
}


All times are GMT -4. The time now is 06:56.

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