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

Get Best Player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-15-2017 , 06:14   Get Best Player
Reply With Quote #1

I'm trying to learn a little bit SourceMod, thats my first job on this language.
I"m trying to show the player that has the most kills of the round. But I got a little problem with SortCustom1D

Code:
SourcePawn Compiler 1.7.1
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2014 AlliedModders LLC

/groups/sourcemod/upload_tmp/textCB4RVp.sp(86) : warning 213: tag mismatch
/groups/sourcemod/upload_tmp/textCB4RVp.sp(86) : error 178: cannot coerce char[] to int[]; storage classes differ

1 Error.
Code:

PHP Code:
#include <sourcemod>

public Plugin:myinfo 
{
    
name "My first official plugin",
    
author "EFFx",
    
description "Not know yet",
    
version "1.0",
    
url "www.nourl.com"
}

int MaxPlayers

char PlayerKills
[MAXPLAYERS+1]
char PlayerDmg[MAXPLAYERS+1]

public 
OnPluginStart()
{
    
HookEvent("player_death"smPlayerDeath)
    
HookEvent("player_spawn"smPlayerSpawn)
    
HookEvent("player_hurt"smPlayerDmg)
    
HookEvent("round_end"smRoundEndEventHookMode_Post)
    
    
MaxPlayers GetMaxClients()
}

public 
Action:smPlayerSpawn(Event:event, const char[] namebool:dontBroadCast)
{
    
int id_spawner GetEventInt(event"userid")
    
int client GetClientOfUserId(id_spawner)
    
    
PlayerKills[client] = 0
}

public 
Action:smPlayerDmg(Event:event, const char[] namebool:dontBroadCast)
{
    
int id_attacker event.GetInt("attacker")
    
int id_victim event.GetInt("userid")

    
int iAttacker GetClientOfUserId(id_attacker)
    
int iVictim GetClientOfUserId(id_victim)
    
    
int health_damage event.GetInt("dmg_health")

    if(
IsClientValid(iAttacker) && IsClientValid(iVictim))
    {
        
PlayerDmg[iAttacker] += health_damage
    
}
}
public 
Action:smPlayerDeath(Event:event, const char[] namebool:dontBroadCast)
{
    
int id_attacker event.GetInt("attacker")
    
int id_victim event.GetInt("userid")
    
    
int iAttacker GetClientOfUserId(id_attacker)
    
int iVictim GetClientOfUserId(id_victim)
    
    if(
iVictim != iAttacker && GetClientTeam(iAttacker) != GetClientTeam(iVictim))
    {
        
PlayerKills[iAttacker]++
    }
}
public 
Action:smRoundEnd(Event:event, const char[] namebool:dontBroadCast)
{
    
int BestPlayer GetTopPlayer()
    
    
char BestPlayerName[32]
    
GetClientName(BestPlayerBestPlayerNamesizeof(BestPlayerName))
    
    
PrintToChatAll("\x04[BestPlayer] \x01The best player of the round is \x06%s\x01 with\x06 %d\x01 kill%s (\x04 %d dmg\01 )"BestPlayerNamePlayerKills[BestPlayer], (PlayerKills[BestPlayer] >= 2) ? "s" ""PlayerDmg[BestPlayer])
}

GetTopPlayer()
{
    
char players[MAXPLAYERS]
    
int PlayersNum
    int i
    
for(1;<= MaxPlayers;i++)
    {
        if(
IsClientInGame(i))
        {
            
players[PlayersNum] = i
            PlayersNum
++
        }
    }
    
SortCustom1D(playersPlayersNumsmTakeBestPlayer)
    return 
players[0]
}

public 
smTakeBestPlayer(int client1int client2)
{
    if(
PlayerKills[client1] > PlayerKills[client2])
        return -
1
    
    
else if(PlayerKills[client1] < PlayerKills[client2])
        return 
1
        
    
return 0
}

stock bool IsClientValid(int client)
{
    if (
client >= && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
        return 
true

    
return false

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-15-2017 at 06:48.
EFFx is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 02-15-2017 , 08:50   Re: Get Best Player
Reply With Quote #2

Code:
    char players[MAXPLAYERS]
why char tho?
__________________
fakuivan is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-15-2017 , 09:14   Re: Get Best Player
Reply With Quote #3

the lack of semicolons are disturbing me.
Mitchell is offline
sdz
Senior Member
Join Date: Feb 2012
Old 02-15-2017 , 13:45   Re: Get Best Player
Reply With Quote #4

Quote:
Originally Posted by EFFx View Post
I'm trying to learn a little bit SourceMod, thats my first job on this language.
I"m trying to show the player that has the most kills of the round. But I got a little problem with SortCustom1D
use int not char. char is just 1 character ("letter") such as: a, #, 9 h, v, $, 1. Almost any one key on the keyboard. Though formerly known as String, albeit String in sourcepawn is just a char array.
also players are viewed upon as integers, so you'd want int players[MAXPLAYERS + 1]; or some other index deal

also please #pragma semicolon 1;

Last edited by sdz; 02-15-2017 at 13:49.
sdz is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 02-15-2017 , 22:17   Re: Get Best Player
Reply With Quote #5

Quote:
Originally Posted by EasSidezz View Post
use int not char. char is just 1 character ("letter") such as: a, #, 9 h, v, $, 1. Almost any one key on the keyboard. Though formerly known as String, albeit String in sourcepawn is just a char array.
also players are viewed upon as integers, so you'd want int players[MAXPLAYERS + 1]; or some other index deal

also please #pragma semicolon 1;
char is used to declare a string in the new syntax
Addicted. is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-16-2017 , 01:22   Re: Get Best Player
Reply With Quote #6

Quote:
Originally Posted by oaaron99 View Post
char is used to declare a string in the new syntax
A char declares a char, Sourcemod doesn't support real strings. In Sourcemod it used to be that String declared what was really a char.

Last edited by Kolapsicle; 02-16-2017 at 01:23.
Kolapsicle is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-16-2017 , 01:56   Re: Get Best Player
Reply With Quote #7

Quote:
Originally Posted by Kolapsicle View Post
A char declares a char, Sourcemod doesn't support real strings. In Sourcemod it used to be that String declared what was really a char.
Quote:
Originally Posted by oaaron99 View Post
char is used to declare a string in the new syntax
Yes. It's very important to underline that

PHP Code:
char playername[MAX_NAME_LENGTH]; 
is not a string, but rather a simple array of characters.
headline is offline
good_live
AlliedModders Donor
Join Date: Oct 2013
Old 02-16-2017 , 09:19   Re: Get Best Player
Reply With Quote #8

Quote:
Originally Posted by Headline View Post
not a string, but rather a simple array of characters.
What's your definition of a String? In my eyes a char array is a String.

Last edited by good_live; 02-16-2017 at 09:19.
good_live is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-16-2017 , 12:28   Re: Get Best Player
Reply With Quote #9

Quote:
Originally Posted by good_live View Post
What's your definition of a String? In my eyes a char array is a String.
A string generally is a data structure. I believe most languages a string type uses a char array but handles that array for you.

Last edited by headline; 02-16-2017 at 12:30.
headline is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-17-2017 , 16:35   Re: Get Best Player
Reply With Quote #10

Why should I use semicolon? Do it something special?

And I did not see any help about my code, just replies about what's a string or an interger.

Ok, I'm using int instead of char, my mistake. In amxx it's an interger as well.

Should PlayerKills and PlayerDmg be int instead of char?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-17-2017 at 17:42.
EFFx 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 11:59.


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