/* AMX Mod X
* Pick up present
*
* / \ / \ ___________________________
* / / \_/ \ \ / \
* \__/\ /\__/ / GIVE ME A CARROT OR I WILL \
* \O O/ \ BLOW UP YOUR HOUSE /
* ___/ ^ \___ / ___________________________/
* \___/ /_/
* _/ \_
* __// \\__
* /___\/_\/___\
*
* (c) Copyright 2008 by FakeNick
*
* This file is provided as is (no warranties)
*
* DESCRIPTION
* This plugin allows admin add/remove/rotate/save presents on map ( ADMIN_KICK flag required).
* When player touches present, it will dissapear and player will (or no) receive some weapons
* or stuff (soon more than now), then present respawns with nice blast :]. Models for
* presents are randomly chosen, so user can add as many, as he want.
*
* VERY IMPORTANT!
* Create an folder called "presents" in addons/amxmodx/config/ directory, otherwise
* plugin won't be able to save presents origins!
*
* COMMANDS
* !add - adds a present at admin aim origin
* !remove - removes a present (admin must aim at present)
* !removeall - removes all presents from map
* !save - saves all present created on map
* !rotate - rotates a present (admin must aim at present)
*
* MODULES
* fakemeta
*
* CVARS
* present_on - turn plugin on/off
* present_respawn_time - time between present disapear and respawn (must be float!)
* present_blast - turns blast on/off
* present_blast_color - color of the blast (default 255 255 255)
* present_m4a1 - turns m4a1 and deagle on/off (pick up)
* present_ak47 - turns ak47 and deagle on/off (pick up)
* present_awp - turns awp and deagle on/off (pick up)
* present_nades - turns nades on/off (pick up)
* present_m4a1_chance - chance to receive m4a1 and deagle
* present_ak47_chance - chance to reveive ak47 and deagle
* present_awp_chance - chance to receive awp and deagle
* present_nades_chance - chance to receive nades
*
* VERSIONS
* 1.0 - first release
*
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fakemeta_util>
new const VERSION[] = "1.0"
//Model is randomly chosen, add as many, as you want
new const model_present[][] = { "models/present/jajko1.mdl","models/present/jajko2.mdl","models/present/jajko3.mdl", "models/present/jajko4.mdl", "models/present/jajko5.mdl", "models/present/jajko6.mdl", "models/present/jajko7.mdl", "models/present/jajko8.mdl", "models/present/jajko9.mdl", "models/present/jajko10.mdl", "models/present/jajko11.mdl", "models/present/male_jajo.mdl", "models/present/chick.mdl", "models/present/kura.mdl"}
new const sound_respawn[] = "present/respawn.wav"
new const sound_present[] = "present/present.wav"
new const sound_pick[] = "present/pick.wav"
new pcvar_on,pcvar_respawn_time,pcvar_blast,pcvar_blast_color,
pcvar_m4a1,pcvar_ak47,pcvar_g3sg1,pcvar_m3,pcvar_xm1014,pcvar_flare,pcvar_m4a1_chance,pcvar_ak47_chance,pcvar_g3sg1_chance,pcvar_m3_chance,pcvar_xm1014_chance,pcvar_awp,pcvar_awp_chance,pcvar_nades_chance,pcvar_flare_chance,pcvar_nades
new g_explo
public plugin_init()
{
register_plugin("Pick up present", VERSION, "FakeNick")
pcvar_on = register_cvar("present_on","1")
if(get_pcvar_num(pcvar_on))
{
register_dictionary("present.txt")
register_clcmd("jajka","show_menu2")
register_clcmd("!load","plugin_cfg")
register_clcmd("!add","func_add_present")
register_clcmd("!remove","func_remove_present")
register_clcmd("!removeall","func_remove_present_all")
register_clcmd("!save","func_save_origins")
register_clcmd("!rotate","func_rotate_present")
register_forward(FM_Touch,"forward_touch")
register_forward(FM_Think,"forward_think")
pcvar_respawn_time = register_cvar("present_respawn_time","150.0")
pcvar_blast = register_cvar("present_blast","1")
pcvar_blast_color = register_cvar("present_blast_color","255 255 255")
pcvar_m4a1 = register_cvar("present_m4a1","1")
pcvar_ak47 = register_cvar("present_ak47","1")
pcvar_awp = register_cvar("present_awp","1")
pcvar_g3sg1 = register_cvar("present_g3sg1","1")
pcvar_m3 = register_cvar("present_m3","1")
pcvar_xm1014 = register_cvar("present_xm1014","1")
pcvar_flare = register_cvar("present_flare","1")
pcvar_nades = register_cvar("present_nades","1")
pcvar_m4a1_chance = register_cvar("present_m4a1_chance","15")
pcvar_ak47_chance = register_cvar("present_ak47_chance","15")
pcvar_awp_chance = register_cvar("present_awp_chance","10")
pcvar_g3sg1_chance = register_cvar("present_g3sg1_chance","4")
pcvar_m3_chance = register_cvar("present_m3_chance","12")
pcvar_xm1014_chance = register_cvar("present_xm1014_chance","8")
pcvar_flare_chance = register_cvar("present_flare_chance","10")
pcvar_nades_chance = register_cvar("present_nades_chance","6")
}
}
public show_menu2(id) {
new menu = menu_create("Menu jajek", "handle_menu");
menu_additem(menu, "Postaw Jajko");
menu_additem(menu, "Usun Jajko");
menu_additem(menu, "Zapisz Jajka");
menu_additem(menu, "Wczytaj Jajka");
menu_additem(menu, "Obroc Jajko");
menu_additem(menu, "Usun wszystkie Jajka");
menu_display(id, menu);
}
public handle_menu(id, menu, item) {
if(item == MENU_EXIT) {
menu_destroy(menu);
return PLUGIN_HANDLED;
}
switch(item) {
case 0:{
client_cmd(id, "!add");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
case 1:{
client_cmd(id, "!remove");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
case 2:{
client_cmd(id, "!save");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
case 3:{
client_cmd(id, "!load");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
case 4:{
client_cmd(id, "!rotate");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
case 5:{
client_cmd(id, "!removeall");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public plugin_precache()
{
for(new i = 0; i < sizeof model_present; i++)
engfunc(EngFunc_PrecacheModel,model_present[i])
engfunc(EngFunc_PrecacheSound,sound_respawn)
engfunc(EngFunc_PrecacheSound,sound_present)
engfunc(EngFunc_PrecacheSound,sound_pick)
g_explo = engfunc(EngFunc_PrecacheModel,"sprites/shockwave.spr")
}
//From Winter Events by alka
public plugin_cfg()
{
static sConfigsDir[64], sFile[64]
get_configsdir(sConfigsDir, sizeof sConfigsDir - 1)
static sMapName[32]
get_mapname(sMapName, sizeof sMapName - 1)
formatex(sFile, sizeof sFile - 1, "%s/presents/%s_presents_origins.cfg", sConfigsDir, sMapName)
if(!file_exists(sFile))
return
static sFileOrigin[3][32], sFileAngles[3][32], iLine, iLength, sBuffer[256]
static sTemp1[128], sTemp2[128]
static Float:fOrigin[3], Float:fAngles[3]
while(read_file(sFile, iLine++, sBuffer, sizeof sBuffer - 1, iLength))
{
if((sBuffer[0]==';') || !iLength)
continue
strtok(sBuffer, sTemp1, sizeof sTemp1 - 1, sTemp2, sizeof sTemp2 - 1, '|', 0)
parse(sTemp1, sFileOrigin[0], sizeof sFileOrigin[] - 1, sFileOrigin[1], sizeof sFileOrigin[] - 1, sFileOrigin[2], sizeof sFileOrigin[] - 1)
fOrigin[0] = str_to_float(sFileOrigin[0])
fOrigin[1] = str_to_float(sFileOrigin[1])
fOrigin[2] = str_to_float(sFileOrigin[2])
parse(sTemp2, sFileAngles[0], sizeof sFileAngles[] - 1, sFileAngles[1], sizeof sFileAngles[] - 1, sFileAngles[2], sizeof sFileAngles[] - 1)
fAngles[0] = str_to_float(sFileAngles[0])
fAngles[1] = str_to_float(sFileAngles[1])
fAngles[2] = str_to_float(sFileAngles[2])
func_spawn(fOrigin)
}
}
//From Winter Events by alka
public func_add_present(id)
{
if(!is_user_alive(id))
return
if(!access(id,ADMIN_KICK))
return
new Float:fOrigin[3],origin[3]
get_user_origin(id,origin,3)
IVecFVec(origin,fOrigin)
if((engfunc(EngFunc_PointContents, fOrigin) != CONTENTS_SKY) && (engfunc(EngFunc_PointContents, fOrigin) != CONTENTS_SOLID))
{
func_spawn(fOrigin)
client_print(id,print_chat,"%L",LANG_PLAYER,"SUCC_ADD",origin[0],origin[1],origin[2])
client_print(id,print_chat,"%L",LANG_PLAYER,"SAVE_INFO")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"LOCATION_UN")
}
}
//From Winter Events by alka
public func_remove_present(id)
{
if(!is_user_alive(id))
return
if(!access(id,ADMIN_KICK))
return
static ent, body
get_user_aiming(id, ent, body)
if(pev_valid(ent))
{
static classname[32]
pev(ent, pev_classname, classname, sizeof classname - 1)
if(!strcmp(classname, "present", 1))
{
engfunc(EngFunc_RemoveEntity, ent)
client_print(id, print_chat, "%L",LANG_PLAYER,"SUCC_REMOVE")
}else
{
client_print(id, print_chat, "%L",LANG_PLAYER,"PRESENT_AIM")
}
}
}
//My function :]
public func_remove_present_all(id)
{
if(!access(id, ADMIN_KICK))
return
if(!is_user_alive(id))
return
new ent = -1,count = 0
while((ent = fm_find_ent(ent,"present")))
{
count++
engfunc(EngFunc_RemoveEntity,ent)
}
client_print(id,print_chat,"%L",LANG_PLAYER,"REMOVE_ALL",count)
client_print(id,print_chat,"%L",LANG_PLAYER,"SAVE_INFO")
}
//From Winter Events by alka
public func_save_origins(id)
{
if(!access(id, ADMIN_KICK))
return
if(!is_user_alive(id))
return
static sConfigsDir[64], sFile[64]
get_configsdir(sConfigsDir, sizeof sConfigsDir - 1)
static sMapName[32]
get_mapname(sMapName, sizeof sMapName - 1)
formatex(sFile, sizeof sFile - 1, "%s/presents/%s_presents_origins.cfg", sConfigsDir, sMapName)
if(file_exists(sFile))
delete_file(sFile)
new iEnt = -1, Float:fEntOrigin[3], Float:fEntAngles[3], iCount
static sBuffer[256]
while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", "present")))
{
pev(iEnt, pev_origin, fEntOrigin)
pev(iEnt, pev_angles, fEntAngles)
formatex(sBuffer, sizeof sBuffer - 1, "%f %f %f | %f %f %f", fEntOrigin[0], fEntOrigin[1], fEntOrigin[2], fEntAngles[0], fEntAngles[1], fEntAngles[2])
write_file(sFile, sBuffer, -1)
iCount++
}
client_print(id, print_chat, "%L",LANG_PLAYER,"SUCC_SAVE", iCount,sMapName)
}
//From Winter Events by alka
public func_rotate_present(id)
{
if(!access(id, ADMIN_KICK))
return
if(!is_user_alive(id))
return
static ent, body
get_user_aiming(id, ent, body)
if(pev_valid(ent))
{
static sClassname[32]
pev(ent, pev_classname, sClassname, sizeof sClassname - 1)
if(!strcmp(sClassname, "present", 1))
{
static Float:fAngles[3]
pev(ent, pev_angles, fAngles)
fAngles[1] += 90.0
set_pev(ent, pev_angles, fAngles)
client_print(id, print_chat, "%L",LANG_PLAYER,"SUCC_ROTATE")
}else{
client_print(id, print_chat, "%L",LANG_PLAYER,"PRESENT_AIM")
}
}
}
//Function for present spawning
public func_spawn(Float:origin[3])
{
new ent = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
set_pev(ent,pev_classname,"present")
engfunc(EngFunc_SetOrigin,ent,origin)
static Float:fMaxs[3] = { 2.0, 2.0, 4.0 }
static Float:fMins[3] = { -2.0, -2.0, -4.0 }
engfunc(EngFunc_SetModel,ent,model_present[random_num(0,sizeof model_present - 1)])
dllfunc(DLLFunc_Spawn,ent)
set_pev(ent,pev_solid,SOLID_BBOX)
engfunc(EngFunc_SetSize,ent,fMins,fMaxs)
}
//Touch forward
public forward_touch(ent,id)
{
if(!pev_valid(ent))
return FMRES_IGNORED
static class[20]
pev(ent,pev_classname,class,sizeof class - 1)
if(!equali(class,"present"))
return FMRES_IGNORED
if(!is_user_alive(id))
return FMRES_IGNORED
set_pev(ent,pev_solid,SOLID_NOT)
set_pev(ent,pev_effects,EF_NODRAW)
set_pev(ent,pev_nextthink,get_gametime() + get_pcvar_float(pcvar_respawn_time))
engfunc(EngFunc_EmitSound,ent,CHAN_ITEM,sound_pick,1.0,ATTN_NORM,0,PITCH_NORM)
client_cmd(id,"spk %s",sound_present)
if(random_num(0,100) <= get_pcvar_num(pcvar_m4a1_chance))
{
if(get_pcvar_num(pcvar_m4a1))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_m4a1")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_ak47_chance))
{
if(get_pcvar_num(pcvar_ak47))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_ak47")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_awp_chance))
{
if(get_pcvar_num(pcvar_awp))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_awp")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_g3sg1_chance))
{
if(get_pcvar_num(pcvar_g3sg1))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_g3sg1")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_m3_chance))
{
if(get_pcvar_num(pcvar_m3))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_m3")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_xm1014_chance))
{
if(get_pcvar_num(pcvar_xm1014))
{
fm_strip_user_weapons(id)
fm_give_item(id,"weapon_knife")
fm_give_item(id,"weapon_xm1014")
fm_give_item(id,"weapon_deagle")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_flare_chance))
{
if(get_pcvar_num(pcvar_flare))
{
fm_give_item(id,"weapon_smokegrenade")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else if(random_num(0,100) <= get_pcvar_num(pcvar_nades_chance))
{
if(get_pcvar_num(pcvar_nades))
{
fm_give_item(id,"weapon_hegrenade")
fm_give_item(id,"weapon_flashbang")
fm_give_item(id,"weapon_smokegrenade")
}else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
}
else{
client_print(id,print_chat,"%L",LANG_PLAYER,"NO_PRESENT")
}
return FMRES_IGNORED
}
//Think forward
public forward_think(ent)
{
new class[20]
pev(ent,pev_classname,class,sizeof class - 1)
if(!equali(class,"present"))
return FMRES_IGNORED
if(pev(ent,pev_effects) & EF_NODRAW)
{
new Float:origin[3]
pev(ent,pev_origin,origin)
engfunc(EngFunc_EmitSound,ent,CHAN_AUTO,sound_respawn,1.0,ATTN_NORM,0,PITCH_NORM)
func_make_blast(origin)
set_pev(ent,pev_solid,SOLID_BBOX)
set_pev(ent,pev_effects, pev(ent,pev_effects) & ~EF_NODRAW)
}
return FMRES_IGNORED
}
//From frostnade by Avalanche
public func_make_blast(Float:fOrigin[3])
{
if(!get_pcvar_num(pcvar_blast))
return
new origin[3]
FVecIVec(fOrigin,origin)
new Float:rgbF[3], rgb[3]
func_get_rgb(rgbF)
FVecIVec(rgbF,rgb)
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(TE_BEAMCYLINDER)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2] + 385)
write_short(g_explo)
write_byte(0)
write_byte(0)
write_byte(4)
write_byte(60)
write_byte(0)
write_byte(rgb[0])
write_byte(rgb[1])
write_byte(rgb[2])
write_byte(100)
write_byte(0)
message_end()
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(TE_DLIGHT)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
write_byte(floatround(240.0/5.0))
write_byte(rgb[0])
write_byte(rgb[1])
write_byte(rgb[2])
write_byte(8)
write_byte(60)
message_end()
}
//From frostnade by Avalanche
public func_get_rgb(Float:rgb[3])
{
static color[12], parts[3][4]
get_pcvar_string(pcvar_blast_color,color,11)
parse(color,parts[0],3,parts[1],3,parts[2],3)
rgb[0] = floatstr(parts[0])
rgb[1] = floatstr(parts[1])
rgb[2] = floatstr(parts[2])
}