...:::Vizite Server:::...
Descriere: Din momentul in care ati pus acest plugin pe server la fiecare conectare de jucator va creste un numar, numarul de vizitatori sa zicem.
Cod:
#include <amxmodx>
#include <nvault>
#pragma semicolon 1
new vizite;
enum Color {
NORMAL = 1, // clients scr_concolor cvar color
GREEN, // Green Color
TEAM_COLOR, // Red, grey, blue
GREY, // grey
RED, // Red
BLUE, // Blue
};
new TeamName[][] = {
"",
"TERRORIST",
"CT",
"SPECTATOR"
};
public plugin_init() {
register_plugin( "Vizite" , "0.3" , "Ex3cuTioN" );
register_clcmd("say /vizite","vizitecmd");
vizite = Load();
}
public plugin_end()
Save(vizite);
public client_putinserver()
vizite +=1;
public Load() {
new valut = nvault_open("Vizite_server");
new vaultkey[64], vaultdata[64];
format(vaultkey, 63, "VIZITE");
nvault_get(valut, vaultkey, vaultdata, 63);
nvault_close(valut);
return str_to_num(vaultdata);
}
public Save(vizite_x) {
new valut = nvault_open("Vizite_server");
if(valut == INVALID_HANDLE)
set_fail_state("nValut returned invalid handle");
new vaultkey[64], vaultdata[64];
format(vaultkey, 63, "VIZITE");
format(vaultdata, 63, "%d", vizite_x);
nvault_set(valut, vaultkey, vaultdata);
nvault_close(valut);
}
public vizitecmd() {
new server[64];
get_cvar_string("hostname",server,63);
ColorChat(0,GREEN,"[Vizite]^x01 %s a acumulat^x04^x01 %i vizite",server,vizite);
return PLUGIN_CONTINUE;
}
ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {
if( !get_playersnum() ) return;
new message[256];
switch(type)
{
case NORMAL: // clients scr_concolor cvar color
{
message[0] = 0x01;
}
case GREEN: // Green
{
message[0] = 0x04;
}
default: // White, Red, Blue
{
message[0] = 0x03;
}
}
vformat(message[1], 251, msg, 4);
// Make sure message is not longer than 192 character. Will crash the server.
message[192] = '^0';
new team, ColorChange, index, MSG_Type;
if(id)
{
MSG_Type = MSG_ONE;
index = id;
} else {
index = FindPlayer();
MSG_Type = MSG_ALL;
}
team = get_user_team(index);
ColorChange = ColorSelection(index, MSG_Type, type);
ShowColorMessage(index, MSG_Type, message);
if(ColorChange)
{
Team_Info(index, MSG_Type, TeamName[team]);
}
}
ShowColorMessage(id, type, message[]) {
static bool:saytext_used;
static get_user_msgid_saytext;
if(!saytext_used)
{
get_user_msgid_saytext = get_user_msgid("SayText");
saytext_used = true;
}
message_begin(type, get_user_msgid_saytext, _, id);
write_byte(id);
write_string(message);
message_end();
}
Team_Info(id, type, team[])
{
static bool:teaminfo_used;
static get_user_msgid_teaminfo;
if(!teaminfo_used)
{
get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
teaminfo_used = true;
}
message_begin(type, get_user_msgid_teaminfo, _, id);
write_byte(id);
write_string(team);
message_end();
return 1;
}
ColorSelection(index, type, Color:Type)
{
switch(Type)
{
case RED:
{
return Team_Info(index, type, TeamName[1]);
}
case BLUE:
{
return Team_Info(index, type, TeamName[2]);
}
case GREY:
{
return Team_Info(index, type, TeamName[0]);
}
}
return 0;
}
FindPlayer()
{
new i = -1;
while(i <= get_maxplayers())
{
if(is_user_connected(++i))
return i;
}
return -1;
}
Nume: Vizite
Versiune:
0.1 - prima publicare
0.2
- optimizare cod
- format -> formatex0.3 - optimizare cod + functionalitate perfecta
Instalare:
1. Fisierul vizite2.sma il puneti in addons/amxmodx/scripting
2. Fisierul vizite2.amxx il puneti in addons/amxmodx/plugins
3. Intrati in fisierul addons/amxmodx/configs/plugins.ini si adaugati la urma:
Code: Select all
vizite2.amxx
Comenzi publice (se tasteaza in joc prin apasarea tastei Y):
/vizite - afiseaza numarul de vizite acumulate
Module necesare (se sterge ; din fata modulului de mai jos; acestea le gasiti in fisierul amxmodx\configs\modules.ini):
- nVault