Raised This Month: $51 Target: $400
 12% 

How to get client index?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bladeee
Junior Member
Join Date: Jan 2016
Old 01-12-2016 , 19:09   How to get client index?
Reply With Quote #1

Code:
#pragma semicolon 1
#include <sourcemod>

#define PLUGIN_VERSION "1.0"

int rdm;
int rdm2;

public Plugin myinfo = {
    name        = "",
    author        = "blade",
    description = "",
    version        = PLUGIN_VERSION,
    url            = ""
};
public OnPluginStart(){
	HookEvent("round_start", OnRoundStart);
}
public Action OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast){
	rdm = GetRandomInt(1, 5);
	if (rdm == 1){
		rdm2 = GetRandomInt(1, 3);
		if (rdm2 == 1){ 
			SetEntityHealth(//need help with getting client index
		}
	}
}
I want to use SetEntityHealth in my OnRoundStart method, but it needs the client index and I'm not sure how to grab it.
PS general criticism of my code will help, new to SP.

Last edited by bladeee; 01-12-2016 at 19:09.
bladeee is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-12-2016 , 19:12   Re: How to get client index?
Reply With Quote #2

Client indexes range from 1 - MaxPlayers, and each client's index reflects what server slot he's connected to.

So if you want the client connected to slot 1, then the index would be 1. 2 is 2, 3 is 3, etc.

You are also mixing aspects of the "old" and "new" Sourcepawn syntaxes. You should put "void" inbetween "public" and "OnPluginStart", and replace this:

PHP Code:
public Action OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast){ 
with this:
PHP Code:
public Action OnRoundStart(Handle event, const char[] namebool dontBroadcast){ 
__________________

Last edited by ddhoward; 01-12-2016 at 19:14.
ddhoward is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 01-12-2016 , 19:54   Re: How to get client index?
Reply With Quote #3

Quote:
Originally Posted by bladeee View Post
I want to use SetEntityHealth in my OnRoundStart method, but it needs the client index and I'm not sure how to grab it.
Well, which client do you want? I'm going to assume that you want all players alive at this time. As stated previously, the range of players is 1 - MaxClients. But be aware that a for loop using the total online clients will be misleading to the code, as the server may reach 8 players, but everyone else except the eighth person could leave. In that situation, the server would say that one player is online, but the slot would not be slot 1; it'd be 8.

Below is a for loop that checks for in-game, alive clients with the variable i.
PHP Code:
for(new i=1;i<=MaxClients;i++){
    if(
IsClientInGame(i) && IsPlayerAlive(i)){
        
SetEntityHealth(iNUMBER);
    }

thecount is offline
bladeee
Junior Member
Join Date: Jan 2016
Old 01-12-2016 , 20:27   Re: How to get client index?
Reply With Quote #4

Quote:
Originally Posted by thecount View Post
Well, which client do you want? I'm going to assume that you want all players alive at this time. As stated previously, the range of players is 1 - MaxClients. But be aware that a for loop using the total online clients will be misleading to the code, as the server may reach 8 players, but everyone else except the eighth person could leave. In that situation, the server would say that one player is online, but the slot would not be slot 1; it'd be 8.

Below is a for loop that checks for in-game, alive clients with the variable i.
PHP Code:
for(new i=1;i<=MaxClients;i++){
    if(
IsClientInGame(i) && IsPlayerAlive(i)){
        
SetEntityHealth(iNUMBER);
    }

Thanks, you make a good point!
+1
bladeee 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 04:49.


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