AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Preventing Spectators for certain players *solved* (https://forums.alliedmods.net/showthread.php?t=74595)

MALON 07-21-2008 16:37

Preventing Spectators for certain players *solved*
 
I know it's possible because I've seen it done, I just don't know how it was done. Players could say /nospec and it would prevent them from having spectators. They could say it again and then spectators would be allowed.

Yes, I really did search the forums and I didn't see anything, but this seems like something that should be fairly easy.

Thanks!

MALON 07-21-2008 20:28

Re: Preventing Spectators for certain players
 
Well, it was a nice attempt, but all it seems to do is tell the player "You're not allowed to spectate this player!" Maybe it's functioning correctly, but I guess what I had meant is that I'd like for the plugin to skip a player with /nospec active, as if he's not even in the server.

I appreciate the attempt though. Thanks :D

danielkza 07-22-2008 04:37

Re: Preventing Spectators for certain players
 
Quote:

Originally Posted by Alka (Post 656448)
1.You have tried it with 2 players? beacause if the player spectated is the last alive from his team won't be skipped.
2.

What ?!
3.Try this new version...

Have you tried just setting pev_iuser2 to the player you want the user to spectate now?

Alka 07-22-2008 07:55

Re: Preventing Spectators for certain players
 
1 Attachment(s)
From mistake i deleted the last post o.0, anyway try this version.Make shure that number of players from same team with spectated player is > 1.

EDIT:
-Little update, and i've tested it, works fine.
-The plugin switches to another player from same team with spectated player...so if spectated player is CT then will pick a random player from CT and switch to him.

Maybe i will make this more complex:
*Menu.
*Switch to a random player from all players or specfied team.
*Can restrict spec only for some players, not for all.

MALON 07-22-2008 18:25

Re: Preventing Spectators for certain players
 
I am going to test it now. I didn't really need all this fancy stuff :P

Sorry for saying it didn't work before, I tested it with only two players. Didn't realize that it would still spec if only one player is left. The reason why I wanted the plugin is because I run a KZ server, and when people are going for a really fast run, they don't like people speccing them. Ideally, I'd like it so that if there are two players left, one being a spectator and the other is doing a run and is nospecced, that it would basically tell the user trying to spectate "No one available to spectate". Your plugin might already do this! Your code is just beyond my level and I can't read the source to tell if it does or not :P

Thanks again!

--MALON

MALON 07-22-2008 18:51

Re: Preventing Spectators for certain players
 
Ok, it works close to correct. I am testing it with two players at the moment. It appears that with two players, spec in first person mode doesn't work quite correctly. It still follows the player's location, but not direction of looking. I think this might be good enough for me to use even so.

Thank you very much. Greatly appreciated.

--MALON

MALON 07-22-2008 19:08

Re: Preventing Spectators for certain players
 
Ok, it's now been tested with more than 2 players and the first person bug still exists. Sorry for that info :(

I am also using SpecInfo by ian.cammarata and even though i'm not allowed to spectate the given player, i still show up on that message as spectating them. This can be dealt with by me (i think), so don't worry too much about it, unless you know a better fix.

If you decide to fix the the first-person glitch, I will probably remove the "you are not allowed to spectate that player!" message. Basically, I want it to emulate as if the person isn't even in the server.

Thank you for what you've done so far, +karma.

Alka 07-23-2008 03:45

Re: Preventing Spectators for certain players
 
-Maybe i can do somehting if are only 2 players on server, just attach player view on a fake ent.
-I've notice that too, you can see old spectated body, but the vision is attached to next player.But after 3-4 worked fine;dunno i will make more tests.
-About SpecInfo, strange pev_iuser2 should be the spectated target, so if change it, you can't appear on that list.Maybe there is another offset/value , that store spectated player info, so must be changed too.

I will try to fix those bugs.

MALON 07-26-2008 14:40

Re: Preventing Spectators for certain players
 
Ok, I tried to make a barebones one. Why is it failing? It seems like it should logically work..All it does is instantly set anyone who spectates to free-roam.

PHP Code:


#include <amxmodx>
#include <fakemeta>

new bool:specMe[33] = true;
new 
playerCounter[33] = 0;

public 
plugin_init() 
{        
  
register_concmd("say /nospec""cmdNoSpec"0"Don't allow players to spec you")
  
register_forward(FM_PlayerPreThink"fwdPlayerPreThink"0);
}


public 
cmdNoSpec(id)
{
    if(
specMe[id]){
        
client_print(idprint_chat"[xKz] No one can spec you now"); // Re-assure the guy
        
specMe[id]=false// Tell the pricks not to look at this guy 
    
}else{
        
client_print(idprint_chat"[xKz] Anyone can spec you now"); // Re-assure the guy
        
specMe[id]=true// Tell the pricks not to look at this guy
    
}
}


public 
fwdPlayerPreThink(id)
{
    if(
is_user_alive(id))//if you are alive
        
return FMRES_IGNORED;
    
    static 
iTarget;
    
iTarget pev(idpev_iuser2);//get the person you're spectatings id
    
    
if(!is_user_alive(iTarget))//are they alive?
        
return FMRES_IGNORED;

    
    if (!
specMe[iTarget]){//execute +attack if unspeccable
        
client_cmd(id"+attack;-attack")
    }
    
    if(
playerCounter[id] >= get_playersnum())//if looped through all players in the server and none found speccable
    
{
        
playerCounter[id] = 0;
        
set_pev(idpev_iuser13)//set to free roam
        
set_pev(idpev_iuser20)//not sure, but it helps setting free roam
        
return PLUGIN_CONTINUE
    
}
    
    
playerCounter[id]++;//if not looped through everyone, increase player counter by one
    
return PLUGIN_CONTINUE



MALON 07-28-2008 02:39

Re: Preventing Spectators for certain players *solved*
 
PHP Code:

public cmdNoSpec(id)
{
    if(
get_entity_visibility(id)){
        
client_print(idprint_chat"No one can spec you now");
        
set_entity_visibility(id0)
    }else{
        
client_print(idprint_chat"Anyone can spec you now");
        
set_entity_visibility(id1)
    }
    return 
PLUGIN_CONTINUE


:) Works perfectly and does just what i wanted


All times are GMT -4. The time now is 05:32.

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