Code:
#include <amxmodx>
#include <tsx>
#include <amxmisc>
// By Mockers aka Glen Chatfield
// Version 0.1b
new hostage_taken = 0
new playerid
new hostageid
public plugin_init() {
register_plugin("Mockers' Hostage","Hostage 0.1b","Mockers")
register_cvar("hostage_distance_start","200") // How close to start the hostage situation
register_cvar("hostage_distance_max","800") // Maxiumum distance away from kidnappers during the situation
register_concmd("amx_takehostage","take_hostage",ADMIN_ALL,"<name of hostage>")
register_menucmd(register_menuid("Hostage"),1023,"hostage_menu")
}
// Uncomment to set your own:
// hostage_distance_start 200 // How close the person has to be to the hostage-to-be to start the hostage situation
// hostage_distance_max 800 // Maxiumum distance away from kidnappers the hostage can wander during the situation
public take_hostage(id) {
if(hostage_taken == 0)
{
hostage_taken = 1
}
if(hostage_taken == 1)
{
client_print(id,print_chat,"[HostageMod] Someone else has already taken someone hostage.^nTry again later.")
return PLUGIN_HANDLED
}
new arg[32], hname[32]
read_argv(1,arg,31)
new name[32], hostage[32], h_id
hostage = arg
h_id = cmd_target(id,hostage,12)
get_user_name(id,name,31)
get_user_name(h_id,hname,31)
new origin[3], h_origin[3]
if(!is_user_alive(id) || !is_user_alive(h_id)) return PLUGIN_HANDLED
get_user_origin(id,origin)
get_user_origin(h_id,h_origin)
if(get_distance(origin,h_origin) > get_cvar_num("hostage_distance_start"))
{
client_print(id,print_chat,"[HostageMod] The player %s must be near you",hostage)
return PLUGIN_HANDLED
}
hostage_menu(id,h_id)
return PLUGIN_HANDLED
}
public hostage_menu(id,hid)
{
new body[256]
new key = (1<<0|1<<9)
new name[32]
get_user_name(id,name,31)
format(body,sizeof(body),"Hostage^nPlayer %s is attempting to take you hostage.^nIf you accept, you will drop all your weapons but he^nwon't hurt you. If you decline, he will^nmost definatly shoot and kill you.^n^n1. Accept^n2.Decline",name)
playerid = id
show_menu(hid,key,body)
return PLUGIN_HANDLED
}
public hostage_action(hid,key)
{
if(!is_user_alive(hid)) return PLUGIN_HANDLED
if(key == 0) hostage_accept(playerid,hid)
if(key == 9) hostage_decline(playerid,hid)
return PLUGIN_HANDLED
}
public hostage_accept(id,hid) {
new name[32], hname[32]
get_user_name(id,name,31)
get_user_name(hid,hname,31)
client_print(id,print_center,"%s has become your hostage.",hname)
client_print(id,print_center,"If he runs away you may shoot him.")
client_print(hid,print_center,"You are now %s's hostage.",name)
client_print(hid,print_center,"Stay close to him or you will be shot.")
for(new i=1;i<=35;i++)
{
client_cmd(hid,"weapon_%d; drop",i)
}
new hudstring[256]
format(hudstring,255,"Attention ALL MCPD, SWAT and Army Units!^n %s has taken %s hostage!",name,hname)
set_hudmessage ( 200, 100, 0, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.2, 1+2 )
show_hudmessage(0,hudstring)
set_task(5.0,"checkhostagedistance",0,"",0,"b")
playerid = id
hostageid = hid
return PLUGIN_HANDLED
}
public checkhostagedistance() {
new origin[3], horigin[3]
get_user_origin(playerid,origin)
get_user_origin(hostageid,horigin)
if(get_distance(origin,horigin) > get_cvar_num("hostage_distance_max"))
{
hostage_escape()
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public hostage_escape()
{
hostage_taken = 0
new name[32], hname[32], hudstring[256]
get_user_name(playerid,name,31)
get_user_name(hostageid,hname,31)
client_print(hostageid,print_center,"You have left %s",name)
client_print(playerid,print_center,"%s has left you",hname)
format(hudstring,255,"Hostage %s has left %s",hname,name)
set_hudmessage( 200, 100, 0, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.2, 1+2 )
show_hudmessage(0,hudstring)
}
public hostage_decline(id,hid)
{
new name[32], hname[32], hudstring[256]
get_user_name(id,name,31)
get_user_name(hid,hname,31)
client_print(id,print_center,"%s is making a break for it.",hname)
client_print(hid,print_center,"!!!Make a break for it, %s is going to shoot you!!!",name)
format(hudstring,255,"%s attempted to take %s hostage",name,hname)
set_hudmessage( 200, 100, 0, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.2, 1+2 )
show_hudmessage(0,hudstring)
hostage_taken = 0
}