Half-Life и Adrenaline Gamer форум
http://econ.aghl.ru/forum/

[TUT] Set Team Scores method
http://econ.aghl.ru/forum/viewtopic.php?f=39&t=2189
Страница 1 из 1

Автор:  Kuma77 [ 17 июн 2015, 02:44 ]
Заголовок сообщения:  [TUT] Set Team Scores method

Hi ,

This tutorial will shows you how to set team scores .

I mean like this :
Изображение

First we need to make a plugin , then we need make a teams ofcourse ,

Код:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Set Team Scores"
#define VERSION "0.01"
#define AUTHOR "TuTorial"

enum
{
TEAM_NONE = 0, // This is NULL Team and always = 0
TEAM_RED,        // This is Red Team = 1
TEAM_BLUE,       // This is Blue Team = 2
TEAM_SPEC       // This is Spectator = 3
}

fine now we need to make an Array String to hold teams name eg : "scientist" and "hgrunt"
scientist , will be the red team , and hgrunt is the blue team
like this
Код:
new const g_szHLTeams[][] =
{
"",                // Also like the first one this is NULL but this is a Sting
"scientist",     // my red team name
"hgrunt",        // my blue team name
"SPECTATOR"  //this is spectator as you know .
}

NOTE : if your Teams are not the same as my , just change "scientist" and "hgrunt" to your teams name

now we need to send message to score board
now we have this code

Код:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Set Team Scores"
#define VERSION "0.01"
#define AUTHOR "TuTorial"

enum
{
TEAM_NONE = 0,
TEAM_RED,
TEAM_BLUE,
TEAM_SPEC
}

new const g_szHLTeams[][] =
{
"",
"scientist",
"hgrunt",
"SPECTATOR"
}


new gMsg_TeamScore
public plugin_init() {
   register_plugin(PLUGIN, VERSION, AUTHOR)
   gMsg_TeamScore = get_user_msgid("TeamScore")
   register_message(gMsg_TeamScore, "msg_teamScore")
   register_clcmd("say add", "Function") // Lets make this command to run your Function that will set team scores
   
}

first lets make an array to hold your teams
will be g_iScore[3]



Код:
new g_iScore[3]

public Function(id)
{
   new iTeam = get_user_team(id)
   switch(iTeam)
   {
      case 1: iTeam = TEAM_RED
      case 2: iTeam = TEAM_BLUE
   }
   emessage_begin(MSG_BROADCAST, gMsg_TeamScore)
   ewrite_string(g_szHLTeams[id])
   ewrite_short(++g_iScore[iTeam])
   ewrite_short(0)
   emessage_end()
}

almost we done this is the final code .

Код:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Set Team Scores"
#define VERSION "0.01"
#define AUTHOR "TuTorial"

enum
{
TEAM_NONE = 0, // This is NULL Team and always = 0
TEAM_RED,        // This is Red Team = 1
TEAM_BLUE,       // This is Blue Team = 2
TEAM_SPEC       // This is Spectator = 3
}

new const g_szHLTeams[][] =
{
"",                // Also like the first one this is NULL but this is a Sting
"scientist",     // my red team name
"hgrunt",        // my blue team name
"SPECTATOR"  //this is spectator as you know .
}

new gMsg_TeamScore
new g_iScore[3]

public plugin_init() {
   register_plugin(PLUGIN, VERSION, AUTHOR)
   gMsg_TeamScore = get_user_msgid("TeamScore")
   register_message(gMsg_TeamScore, "msg_teamScore")
   register_clcmd("say add", "Function") // Lets make this command to run your Function that will set team scores
   
}



public Function(id)
{
   new iTeam = get_user_team(id)
   switch(iTeam)
   {
      case 1: iTeam = TEAM_RED
      case 2: iTeam = TEAM_BLUE
   }
   emessage_begin(MSG_BROADCAST, gMsg_TeamScore) // Send message
   ewrite_string(g_szHLTeams[id]) //Check string names for teams
   ewrite_short(++g_iScore[iTeam]) // Rewrite Scores
   ewrite_short(0)                        //This is Deaths i think we dont need to set this
   emessage_end()
}

public msg_teamScore()
{
   static szTeam[32]
   
   get_msg_arg_string(1, szTeam, 1)
   
   switch(szTeam[0])
   {
      case 1: set_msg_arg_int(2, ARG_SHORT, g_iScore[TEAM_RED]) //This is msg for Red team will send this scores  that you added with your Function
      case 2: set_msg_arg_int(2, ARG_SHORT, g_iScore[TEAM_BLUE]) // The same
   }
}


i hop you understand what i am explaining here

Автор:  abdobiskra [ 04 май 2016, 00:34 ]
Заголовок сообщения:  Re: [TUT] Set Team Scores method

i think here problem ?

Вложения:
Capture.PNG
Capture.PNG [ 264.58 КБ | Просмотров: 7586 ]

Автор:  Lev [ 04 май 2016, 02:10 ]
Заголовок сообщения:  Re: [TUT] Set Team Scores method

Kuma77 писал(а):
public Function(id)
I recommend to give meaning names to the functions same as for variables.

Автор:  Lev [ 04 май 2016, 06:16 ]
Заголовок сообщения:  Re: [TUT] Set Team Scores method

Kuma77
Код:
register_message(gMsg_TeamScore, "msg_teamScore")
will not work because hl.dll do not sends this message.
Actually this tutorial has drawbacks. I suggest you to rewrite it so: write a plugin that fully manage team scores based on players frags, i.e.
- it will have a function that will increase (and possibly decrease) team frags (decision function)
- send team frags on connect
- send team frags on change
- read team names from mp_teamlist
- read mp_teamplay cvar
Yes, it tends to be more a plugin than a TUT, but managing team scores require all these steps. And still decision function should be written by a coder based on gameplay needs so possibly this will be the best way.

Страница 1 из 1 Часовой пояс: UTC + 5 часов [ Летнее время ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/