Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <engine>
- #include <fakemeta_util>
- #include <hamsandwich>
- #define PLUGIN "Ghost"
- #define VERSION "1.0"
- #define AUTHOR "Unknown"
- new const MODEL_GHOST[][] = {
- "models/GlobalKnifeHW/ghost.mdl",
- "models/GlobalKnifeHW/ghost2.mdl"
- }
- #define GHOST_CLASS "ent_ghost"
- #define MAIN_ORIGIN1 pev_iuser1
- #define MAIN_ORIGIN2 pev_iuser2
- #define MAIN_ORIGIN3 pev_iuser3
- #define NEXT_ORIGIN1 pev_fuser1
- #define NEXT_ORIGIN2 pev_fuser2
- #define NEXT_ORIGIN3 pev_fuser3
- #define TOOK_NEXT pev_iuser4
- #define NEXT_FADE pev_fuser4
- #define THINK_RATE 0.075
- #define GHOST_SPEED 50.0
- new Float: MIN_X = 300.0,Float:MAX_X = 1000.0;
- new Float: MIN_Y = 300.0,Float:MAX_Y = 1000.0;
- new Float: MIN_Z = -100.0,Float:MAX_Z = 100.0;
- new bool:g_save_cpl
- enum{
- No = 0,
- Yes = 1
- }
- static Array:g_cp_id, Array:g_cp_origin_x, Array:g_cp_origin_y, Array:g_cp_origin_z
- public plugin_precache()
- {
- for(new i=0;i < sizeof(MODEL_GHOST);i++)
- precache_model(MODEL_GHOST[i])
- }
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- g_cp_id = ArrayCreate()
- g_cp_origin_x = ArrayCreate()
- g_cp_origin_y = ArrayCreate()
- g_cp_origin_z = ArrayCreate()
- register_clcmd("ghost_menu", "ghosts_menu", ADMIN_RCON)
- register_think(GHOST_CLASS, "fw_ghost_think")
- get_maps_cfg()
- set_lights("c")
- }
- public fw_ghost_think(ent)
- {
- if(!pev_valid(ent))
- return
- static took_next;
- render_it(ent)
- light_it_up(ent)
- took_next = pev(ent,TOOK_NEXT)
- if(!took_next)
- {
- static Float:x,Float:y,Float:z;
- static xi,yi,zi;
- xi= pev(ent,MAIN_ORIGIN1)
- yi = pev(ent,MAIN_ORIGIN2)
- zi = pev(ent,MAIN_ORIGIN3)
- x = float(xi)+random_float(MIN_X,MAX_X)
- y = float(yi)+random_float(MIN_Y,MAX_Y)
- z = float(zi)+random_float(MIN_Z,MAX_Z)
- set_pev(ent,NEXT_ORIGIN1,x)
- set_pev(ent,NEXT_ORIGIN2,y)
- set_pev(ent,NEXT_ORIGIN3,z)
- set_pev(ent,TOOK_NEXT,Yes)
- }
- else
- {
- static Float:next_coord[3];
- pev(ent,NEXT_ORIGIN1,next_coord[0])
- pev(ent,NEXT_ORIGIN2,next_coord[1])
- pev(ent,NEXT_ORIGIN3,next_coord[2])
- move_ent(ent,next_coord,GHOST_SPEED)
- }
- set_pev(ent, pev_nextthink, halflife_time() + 0.075)
- }
- public light_it_up(ent)
- {
- static Float:origin[3]
- message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
- write_byte(TE_DLIGHT) // TE id
- write_coord(floatround(origin[0])); // x
- write_coord(floatround(origin[1])); // y
- write_coord(floatround(origin[2])); // z
- write_byte(40) // radius
- write_byte(100) // r
- write_byte(100) // g
- write_byte(100) // b
- write_byte(2) // life
- write_byte(0) // decay rate
- message_end()
- }
- public render_it(ent)
- {
- new Float:next_fade;
- next_fade = 255.0 // incase
- pev(ent,NEXT_FADE,next_fade)
- if(255.0 > next_fade)
- {
- next_fade += 1.0
- if(next_fade > 255.0)
- {
- next_fade = 255.0
- set_pev(ent,NEXT_FADE,255.0)
- client_print(0,print_console,"%f",next_fade)
- }
- }
- else if(next_fade >= 254.0)
- {
- next_fade -= 1.0
- if(50.0 > next_fade)
- {
- next_fade = 10.0
- set_pev(ent,NEXT_FADE,10.0)
- client_print(0,print_console,"%f",next_fade)
- }
- }
- set_rendering(ent,kRenderFxNone,0,0,0,kRenderNormal,floatround(next_fade))
- }
- public plugin_end() // dunno if this is needed but let's just put it, if it causes problems then remove it.
- {
- remove_ghosts()
- }
- stock remove_ghosts()
- {
- new ghost = -1;
- while((ghost=find_ent_by_class(ghost,GHOST_CLASS)))
- {
- if(pev_valid(ghost))
- remove_entity(ghost)
- }
- }
- public move_ent(ent, Float:VicOrigin[3], Float:speed)
- {
- static Float:fl_Velocity[3]
- static Float:EntOrigin[3]
- pev(ent, pev_origin, EntOrigin)
- turn_to_origin(ent, EntOrigin, VicOrigin)
- static Float:distance;
- distance = get_distance_f(EntOrigin, VicOrigin)
- if (25.0 > distance)
- set_pev(ent,TOOK_NEXT,No)
- new Float:fl_Time = distance / speed
- fl_Velocity[0] = (VicOrigin[0] - EntOrigin[0]) / fl_Time
- fl_Velocity[1] = (VicOrigin[1] - EntOrigin[1]) / fl_Time
- fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time
- entity_set_vector(ent, EV_VEC_velocity, fl_Velocity)
- }
- public turn_to_origin(ent, Float:Ent_Origin[3], Float:Vic_Origin[3])
- {
- new Float:newAngle[3]
- entity_get_vector(ent, EV_VEC_angles, newAngle)
- new Float:x = Vic_Origin[0] - Ent_Origin[0]
- new Float:z = Vic_Origin[1] - Ent_Origin[1]
- new Float:radians = floatatan(z/x, radian)
- newAngle[1] = radians * (180 / 3.14)
- if (Vic_Origin[0] < Ent_Origin[0])
- newAngle[1] -= 180.0
- entity_set_vector(ent, EV_VEC_angles, newAngle)
- }
- public get_maps_cfg()
- {
- new map[32]
- get_mapname(map, charsmax(map))
- formatex(map, charsmax(map),"%s.ini",map)
- new cfgDir[64], i_Dir, i_File[128]
- get_configsdir(cfgDir, charsmax(cfgDir))
- formatex(cfgDir, charsmax(cfgDir), "%s/ghost", cfgDir)
- i_Dir = open_dir(cfgDir, i_File, charsmax(i_File))
- if(i_Dir)
- {
- while(next_file(i_Dir, i_File, charsmax(i_File)))
- {
- if (i_File[0] == '.')
- continue
- if(equal(map, i_File))
- {
- format(i_File,128,"%s/%s",cfgDir, i_File)
- get_checkpoints(i_File)
- break
- }
- }
- }
- }
- public set_maps_cfg()
- {
- new map[32]
- get_mapname(map, charsmax(map))
- formatex(map, charsmax(map),"%s.ini",map)
- new cfgDir[64], i_File[128]
- get_configsdir(cfgDir, charsmax(cfgDir))
- formatex(cfgDir, charsmax(cfgDir), "%s/ghost", cfgDir)
- formatex(i_File, charsmax(i_File),"%s/%s",cfgDir, map)
- if(!dir_exists(cfgDir))
- if(!mkdir(cfgDir))
- return
- delete_file(i_File)
- static cp_count; cp_count = ArraySize(g_cp_id)
- if(!cp_count)
- return
- for(new i=0; i<cp_count; i++)
- {
- new text[128], Float:fOrigin[3], ent = ArrayGetCell(g_cp_id, i)
- pev(ent, pev_origin, fOrigin)
- format(text, charsmax(text),"^"%f^" ^"%f^" ^"%f^"",fOrigin[0], fOrigin[1], fOrigin[2])
- write_file(i_File, text, i)
- }
- }
- public get_checkpoints(i_File[128])
- {
- new file = fopen(i_File,"rt")
- while(file && !feof(file))
- {
- new sfLineData[512]
- fgets(file, sfLineData, charsmax(sfLineData))
- if(sfLineData[0] == ';')
- continue
- if(equal(sfLineData,""))
- continue
- new i_origins[3][32], Float: fOrigins[3]
- parse(sfLineData, i_origins[0], 31, i_origins[1], 31, i_origins[2], 31)
- fOrigins[0] = str_to_float(i_origins[0])
- fOrigins[1] = str_to_float(i_origins[1])
- fOrigins[2] = str_to_float(i_origins[2])
- create_checkpoint(fOrigins)
- }
- fclose(file)
- }
- public ghosts_menu(id)
- {
- static cp_count; cp_count = ArraySize(g_cp_id)
- new menu_name[90]
- format(menu_name, 90, "\rGhostMenu")
- new i_menu = menu_create(menu_name, "menu_handler")
- menu_additem(i_menu, "\wAdd ghost", "1", 0)
- if(!cp_count)
- {
- menu_additem(i_menu, "\dDelete Previous added", "2", 0)
- menu_additem(i_menu, "\dDelete all", "3", 0)
- }
- else
- {
- menu_additem(i_menu, "\wDelete Previous added", "2", 0)
- menu_additem(i_menu, "\wDelete all", "3", 0)
- }
- if(!g_save_cpl)
- menu_additem(i_menu, "\dSave changes", "4", 0)
- else menu_additem(i_menu, "\wSave changes", "4", 0)
- menu_setprop(i_menu, MPROP_EXIT, MEXIT_ALL)
- menu_setprop(i_menu, MPROP_EXITNAME, "\yExit")
- menu_display(id, i_menu, 0)
- return PLUGIN_HANDLED
- }
- public menu_handler(id, menu, item)
- {
- if (item == MENU_EXIT)
- {
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- static cp_count; cp_count = ArraySize(g_cp_id)
- switch(item)
- {
- case 0:
- {
- g_save_cpl = true
- static Float:fOrigins[3]
- fm_get_aim_origin(id, fOrigins)
- fOrigins[2]+=60
- create_checkpoint(fOrigins)
- ghosts_menu(id)
- }
- case 1:
- {
- if(!cp_count)
- {
- client_print(id, print_chat, "No ghosts on this map")
- ghosts_menu(id)
- return PLUGIN_HANDLED
- }
- g_save_cpl = true
- client_print(id, print_chat, "Ghost has been deleted")
- remove_entity(ArrayGetCell(g_cp_id, cp_count-1))
- ArrayDeleteItem(g_cp_id, cp_count-1)
- ArrayDeleteItem(g_cp_origin_x, cp_count-1)
- ArrayDeleteItem(g_cp_origin_y, cp_count-1)
- ArrayDeleteItem(g_cp_origin_z, cp_count-1)
- if(cp_count-1)
- {
- set_pev(ArrayGetCell(g_cp_id, cp_count-2), pev_body, 2)
- set_pev(ArrayGetCell(g_cp_id, cp_count-2), pev_skin, 0)
- }
- ghosts_menu(id)
- }
- case 2:
- {
- if(!cp_count)
- {
- client_print(id, print_chat, "No ghosts on this map")
- ghosts_menu(id)
- return PLUGIN_HANDLED
- }
- g_save_cpl = true
- client_print(id, print_chat, "Deleted %d ghosts", cp_count)
- for(new i=0; i<cp_count; i++)
- remove_entity(ArrayGetCell(g_cp_id, i))
- ArrayClear(g_cp_id)
- ArrayClear(g_cp_origin_x)
- ArrayClear(g_cp_origin_y)
- ArrayClear(g_cp_origin_z)
- ghosts_menu(id)
- }
- case 3:
- {
- if(!g_save_cpl)
- {
- ghosts_menu(id)
- return PLUGIN_HANDLED
- }
- g_save_cpl = false
- set_maps_cfg()
- client_print(id, print_chat, "Saved")
- ghosts_menu(id)
- }
- }
- return PLUGIN_HANDLED
- }
- public create_checkpoint(Float: fOrigins[3])
- {
- static ent; ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
- if(!pev_valid(ent)) return
- ArrayPushCell(g_cp_id, ent)
- ArrayPushCell(g_cp_origin_x, fOrigins[0])
- ArrayPushCell(g_cp_origin_y, fOrigins[1])
- ArrayPushCell(g_cp_origin_z, fOrigins[2])
- engfunc(EngFunc_SetModel, ent, MODEL_GHOST[random_num(0,(sizeof(MODEL_GHOST)-1))])
- set_pev(ent, pev_origin, fOrigins)
- set_pev(ent, pev_solid, SOLID_NOT)
- set_pev(ent, pev_movetype, MOVETYPE_NOCLIP)
- set_pev(ent, pev_sequence, 0)
- set_pev(ent, pev_gaitsequence, 0)
- set_pev(ent, pev_framerate, 1.0)
- set_pev(ent, pev_classname, GHOST_CLASS)
- set_pev(ent,NEXT_FADE,255.0)
- new Float:origin[3];
- pev(ent, pev_origin, origin)
- set_pev(ent,MAIN_ORIGIN1,floatround(origin[0]))
- set_pev(ent,MAIN_ORIGIN2,floatround(origin[1]))
- set_pev(ent,MAIN_ORIGIN3,floatround(origin[2]))
- set_pev(ent,TOOK_NEXT,No)
- entity_set_size(ent,Float:{-45.0, -45.0, -45.0}, Float:{45.0, 45.0, 45.0})
- set_pev(ent, pev_nextthink, halflife_time() + THINK_RATE)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement