View Single Post
Author Message
SHIFT0
Senior Member
Join Date: Apr 2021
Location: Palestine
Old 07-02-2022 , 20:41   Hud message to chat ?
Reply With Quote #1

Hi guys i have this plugin
i just want to change from hud to chat and add every kill this chats..
&x04[DZ-Points] You Killed %s , and you got 5 Points.
&x04[DZ-Points] Head Shot kill %s, and you got 10 Points.
&x04[DZ-Points] You Knifed %s , and you got 5 Points.
&x04[DZ-Points] You Knifed %s HS , and you got 10 Points.

PHP Code:
#include <amxmodx>
#include <nvault>

// Defining numbers , for better read ability
#define NORMAL_KILL 5
#define HEADSHOT_KILL 10
#define KNIFE_KILL 5
#define KNIFE_HEADSHOT 10
#define BOMB_DEFUSED 8

#define CT_WIN 5
#define TR_WIN 5

//our uniq task id
#define TASK_ID     1000

// Max players that a server can have
#define MAX_PLAYERS 32

// Hud X position
const FloatHUD_POSITION_X = -1.0
// Hud Y position
const FloatHUD_POSITION_Y 0.88

// Hud display time
const Float:HOLD_TIME 9.9
const HUD_CHANNEL 1

new const VERSION[] = "1.0"

//Our main array for Point_System
new Points[MAX_PLAYERS 1]
// Saving users authid here
new szAuthid[MAX_PLAYERS 1][35]
// nVault
new g_save

public plugin_init()
{
    
register_plugin("Point System" VERSION "Abaaaaadiii.")
    
// Logevents , (For increasing points)
    
register_logevent("bomb_defused"3"2=Defused_The_Bomb")
    
register_logevent("on_CTWin"6"3=CTs_Win""3=All_Hostages_Rescued")
    
register_logevent("on_TerroristWin" 6"3=Terrorists_Win""3=Target_Bombed")
    
// called whenever a cliend dies/killed
    
register_event ("DeathMsg""Event_Death""a")
}

// Opening Our nVault (All of our data related to points , authids are saved in an nVault file)
public plugin_cfg()
{
    
g_save nvault_open("FR-Points")
    if ( 
g_save == INVALID_HANDLE )
    {
        
set_fail_state"Error opening nVault" )
    }
}

// close nVault 
public plugin_end()
{
    
nvault_close(g_save)
}

// Our natives (They are so useful whe you want to make sub-plugins)
public plugin_natives()
{
    
register_library("point_sytem")
    
register_native("get_user_point" "native_get_user_point")
    
register_native("set_user_point" "native_set_user_point")
}

// get_user_point
public native_get_user_point(index)
{
    return 
Points[get_param(1)]
}

// set_user_point
public native_set_user_point(index amount)
{
    
Points[get_param(1)] = get_param(2)
}

// get user authid , and load point whenever a client joins server + start a task for showing player point in hud
public client_putinserver(id)
{
    
get_user_authid(id szAuthid[id] , charsmax(szAuthid))
    
LoadData(id)
    
set_task (1.0"show_points",id TASK_ID,_,_,"b")
}

// Save data (points) and remove task
public client_disconnect(id)
{
    
remove_task(id TASK_ID)
    
SaveData(id)
}

// increasing points
public Event_Death()
{
    static 
Attacker Victim Headshot wpn
    Attacker 
read_data(1)
    
Victim read_data(2)
    
Headshot read_data(3)
    
wpn get_user_weapon(Attacker)

    if (
Attacker == Victim) return PLUGIN_HANDLED
    
if(Headshot && wpn != CSW_KNIFE)
    {
        
Points[Attacker] += HEADSHOT_KILL
    
}
    if (
wpn == CSW_KNIFE && !Headshot)
    {
        
Points[Attacker] += KNIFE_KILL
    
}
    if (
wpn == CSW_KNIFE && Headshot)
    {
        
Points[Attacker] += KNIFE_HEADSHOT
    
}
    if (!
Headshot && wpn != CSW_KNIFE)
    {
        
Points[Attacker] += NORMAL_KILL
    
}
    return 
PLUGIN_CONTINUE
}

// give points to defuser
public bomb_defused(id)
{
    
Points[id] += BOMB_DEFUSED
}

// give point to all terrorist's
public on_TerroristWin()
{
    new 
players[32], num
    get_players
(playersnum"ceh" "TERRORIST")
    for( --
numnum >= 0num-- )
    {
        
Points[players[num]] += TR_WIN
    
}
}

// give point to all CT's
public on_CTWin()
{
    new 
players[32], num
    get_players
(playersnum"ceh" "CT")
    for( --
numnum >= 0num-- )
    {
        
Points[players[num]] += CT_WIN
    
}
}

// show hud message
public show_points(TASK)
{
    new 
id TASK TASK_ID
    set_hudmessage
(255 HUD_POSITION_X HUD_POSITION_Y , -1.00.88HOLD_TIME9.91.0HUD_CHANNEL)
    
show_hudmessage(id "Your Points : %i" Points[id])
    
    
}

// Saving Data to nVault file
SaveData(id)
{
    new 
vaultkey[64], vaultdata[256]
            
    
formatex(vaultkeycharsmax(vaultkey), "%s-/"szAuthid[id])

    
formatex(vaultdatacharsmax(vaultdata), "%i#"Points[id])
    
    
nvault_set(g_savevaultkeyvaultdata)
}

// Loading Data from nVault file
LoadData(id)
{
    new 
vaultkey[64], vaultdata[256]
            
    
formatex(vaultkeycharsmax(vaultkey), "%s-/"szAuthid[id])

    
formatex(vaultdatacharsmax(vaultdata), "%i#"Points[id])
    
    
nvault_get(g_savevaultkeyvaultdatacharsmax(vaultdata))
    
replace_all(vaultdatacharsmax(vaultdata), "#"" ")
    
    new 
get_points[MAX_PLAYERS]
    
parse(vaultdataget_points charsmax(get_points))
    
Points[id] = str_to_num(get_points)

__________________
Thank You For Helps
Discord:
null.#0096
https://www.youtube.com/@NullHere/
SHIFT0 is offline