Raised This Month: $ Target: $400
 0% 

Check if player is in screen


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mateo10
Veteran Member
Join Date: Jan 2006
Old 11-28-2006 , 03:11   Check if player is in screen
Reply With Quote #1

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
mateo10 is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 11-28-2006 , 03:16   Re: Check if player is in screen
Reply With Quote #2

is_in_viewcone ( entity, Float: origin[3] )
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 11-28-2006 , 03:24   Re: Check if player is in screen
Reply With Quote #3

Plus, you need to check if the player is visible.
Also is_in_viewcone method isn't 100% accurate in 3D.
VEN is offline
mateo10
Veteran Member
Join Date: Jan 2006
Old 11-28-2006 , 03:29   Re: Check if player is in screen
Reply With Quote #4

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.
mateo10 is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 11-28-2006 , 03:36   Re: Check if player is in screen
Reply With Quote #5

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.   }  } }
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.

Last edited by dutchmeat; 11-28-2006 at 03:43.
dutchmeat is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 11-28-2006 , 03:54   Re: Check if player is in screen
Reply With Quote #6

change get_user_origin(i, origin)
to entity_get_vector(players[i], EV_VEC_origin, origin)
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
mateo10
Veteran Member
Join Date: Jan 2006
Old 11-28-2006 , 04:25   Re: Check if player is in screen
Reply With Quote #7

@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 is offline
mateo10
Veteran Member
Join Date: Jan 2006
Old 11-28-2006 , 04:44   Re: Check if player is in screen
Reply With Quote #8

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") }
mateo10 is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 11-28-2006 , 05:07   Re: Check if player is in screen
Reply With Quote #9

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);
VEN is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 11-28-2006 , 05:15   Re: Check if player is in screen
Reply With Quote #10

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
}
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Reply


Thread Tools
Display Modes

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 06:56.


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