- Код: Выделить всё
public spawn_ball(id, type)
{
new classname[32]
PlayerControlBall = 0
TochBallBlock = false
if(is_valid_ent(Ball))
entity_get_string(Ball, EV_SZ_classname, classname, charsmax(classname))
if(equal("BallSimpleJB", classname) && TypeBall == type)
{
entity_set_vector(Ball, EV_VEC_velocity, Float:{0.0, 0.0, 0.0})
entity_set_origin(Ball, g_vOrigin)
entity_set_int(Ball, EV_INT_movetype, MOVETYPE_BOUNCE)
entity_set_size(Ball, Float:{-15.0, -15.0, 0.0}, Float:{15.0, 15.0, 12.0})
entity_set_int(Ball, EV_INT_iuser1, 0)
}
else
create_ball(id, type)
}
Весь плагин
- Код: Выделить всё
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fun>
new const szEntity[][] =
{
"worldspawn",
"func_wall",
"func_door",
"func_door_rotating",
"func_wall_toggle",
"func_breakable",
"func_pushable",
"func_train",
"func_illusionary",
"func_button",
"func_rot_button",
"func_rotating"
}
new const TrailColor[][3] =
{
{255, 255, 255},
{0, 0, 255},
{150, 0, 255},
{255, 150, 0},
{120, 120, 120},
{0, 255, 0},
{255, 0, 0}
}
new Float:g_vOrigin[3]
new IDBall[33]
new bool:FootballStart
new bool:TochBallBlock
new EditObject
new PlayerControlBall
new SpriteTrailBall
new BallSpeed
new TypeBall
new Ball
new Object[5]
public plugin_init()
{
register_logevent("round_end", 2, "1=Round_End")
register_logevent("round_start", 2, "0=World triggered", "1=Round_Start")
for(new i=0; i<sizeof(szEntity); i++)
register_touch("BallSimpleJB", szEntity[i], "FwdTouchWorld")
register_forward(FM_PlayerPreThink, "client_prethink")
register_touch("BallSimpleJB", "player", "FwdTouchPlayer")
register_think("BallSimpleJB", "FwdThinkBall")
register_clcmd("football_ball", "ClCmd_FootBallMenu")
register_menucmd(register_menuid("Show_FootBallMenu"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9), "Handle_FootBallMenu")
}
public plugin_precache()
{
SpriteTrailBall = precache_model("sprites/ball.spr")
}
public round_start()
{
remove_task(1528162)
for(new i=1; i<=32; i++)
{
IDBall[i] = 0
}
FootballStart = false
TochBallBlock = false
Ball = 0
TypeBall = 0
BallSpeed = 1000
PlayerControlBall = 0
EditObject = 0
}
public round_end()
{
delete_ball()
}
public ClCmd_FootBallMenu(id)
{
new szMenu[512], iKeys, iLen = formatex(szMenu, charsmax(szMenu), "\yУправление мячом^n^n")
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[1] \wУстановить мяч^n")
iKeys |= (1<<0)
if(is_valid_ent(Ball) && TypeBall == 0)
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[2] \wУдалить мяч^n")
iKeys |= (1<<1)
}
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[2] \dУдалить мяч^n")
if(BallSpeed <= 4900)
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[3] \wУвеличить скорость мяча^n")
iKeys |= (1<<2)
}
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[3] \dУвеличить скорость мяча^n")
if(BallSpeed >= 200)
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[4] \wУменьшить скорость мяча^n^n^n^n^n^n")
iKeys |= (1<<3)
}
else iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[4] \dУменьшить скорость мяча^n^n^n^n^n^n")
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[9] \wНазад^n")
iKeys |= (1<<8)
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y[0] \wВыход")
iKeys |= (1<<9)
return show_menu(id, iKeys, szMenu, -1, "Show_FootBallMenu")
}
public Handle_FootBallMenu(id, key)
{
new name[32]
get_user_name(id, name, charsmax(name))
switch(key)
{
case 0:
{
spawn_ball(id, 0)
if(FootballStart) emit_sound(0, CHAN_AUTO, "soccer/grab_ball.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
ClCmd_FootBallMenu(id)
}
case 1:
{
if(is_valid_ent(Ball) && TypeBall == 0)
{
delete_ball()
ClCmd_FootBallMenu(id)
}
}
case 2:
{
if(BallSpeed <= 4900)
{
BallSpeed = BallSpeed + 100
ClCmd_FootBallMenu(id)
}
}
case 3:
{
if(BallSpeed >= 200)
{
BallSpeed = BallSpeed - 100
ClCmd_FootBallMenu(id)
}
}
case 8: client_cmd(id, "cmd_minigame")
}
return PLUGIN_HANDLED
}
public client_prethink(id)
{
new iOwner
if(is_user_alive(id))
{
if(entity_get_int(id, EV_INT_button) & IN_USE)
{
if(pev_valid(Ball))
iOwner = pev(Ball, pev_iuser1)
if(iOwner == id)
KickBall(id, 0)
}
else if(entity_get_int(id, EV_INT_button) & IN_RELOAD)
{
new iOwner
if(pev_valid(Ball))
iOwner = pev(Ball, pev_iuser1)
if(iOwner == id)
KickBall(id, 1)
}
else if(entity_get_int(id, EV_INT_button) & IN_ATTACK2)
{
new iOwner
if(pev_valid(Ball))
iOwner = pev(Ball, pev_iuser1)
if(iOwner == id)
KickBall(id, 2)
}
else if(entity_get_int(id, EV_INT_button) & IN_ATTACK)
{
if(TypeBall != 1)
{
new iOwner
if(pev_valid(Ball))
iOwner = pev(Ball, pev_iuser1)
if(iOwner == id)
KickBall(id, 3)
}
}
}
return PLUGIN_CONTINUE
}
public create_ball(id, type)
{
new Float:vOrigin[3] = {0.0, 0.0, 0.0}, rand = random_num(0, 1)
Ball = create_entity("info_target")
TypeBall = type
if(is_valid_ent(Ball))
{
entity_set_string(Ball, EV_SZ_classname, "BallSimpleJB")
entity_set_int(Ball, EV_INT_solid, SOLID_TRIGGER)
entity_set_int(Ball, EV_INT_movetype, MOVETYPE_BOUNCE)
entity_set_size(Ball, Float:{-15.0, -15.0, 0.0}, Float:{15.0, 15.0, 12.0})
entity_set_float(Ball, EV_FL_framerate, 0.0)
entity_set_int(Ball, EV_INT_sequence, 0)
entity_set_float(Ball, EV_FL_nextthink, get_gametime() + 0.01)
if(rand == 0 && TypeBall == 0)
entity_set_model(Ball, "models/soccer/ball.mdl")
else if(rand == 1 && TypeBall == 0)
entity_set_model(Ball, "models/soccer/ball.mdl")
if(TypeBall == 1)
set_pev(Ball, pev_gravity, 0.6)
if(id > 0)
{
new iOrigin[3]
get_user_origin(id, iOrigin, 3)
IVecFVec(iOrigin, vOrigin)
vOrigin[2] += 5.0;
entity_set_origin(Ball, vOrigin)
}
g_vOrigin = vOrigin
return Ball
}
return -1
}
public spawn_ball(id, type)
{
new classname[32]
PlayerControlBall = 0
TochBallBlock = false
if(is_valid_ent(Ball))
entity_get_string(Ball, EV_SZ_classname, classname, charsmax(classname))
if(equal("BallSimpleJB", classname) && TypeBall == type)
{
entity_set_vector(Ball, EV_VEC_velocity, Float:{0.0, 0.0, 0.0})
entity_set_origin(Ball, g_vOrigin)
entity_set_int(Ball, EV_INT_movetype, MOVETYPE_BOUNCE)
entity_set_size(Ball, Float:{-15.0, -15.0, 0.0}, Float:{15.0, 15.0, 12.0})
entity_set_int(Ball, EV_INT_iuser1, 0)
}
else
create_ball(id, type)
}
public delete_ball()
{
TochBallBlock = false
PlayerControlBall = 0
new iEntity
while((iEntity = find_ent_by_class(iEntity, "BallSimpleJB")) > 0)
{
remove_entity(iEntity)
ball_trail_remove(iEntity)
}
}
public donttouch_ball()
{
TochBallBlock = false
}
public KickBall(id, type)
{
new Float:vOrigin[3], Float:vVelocity[3], arg[2]
entity_get_vector(Ball, EV_VEC_origin, vOrigin)
if(PointContents(vOrigin) != CONTENTS_EMPTY)
return PLUGIN_HANDLED
if(type == 3)
velocity_by_aim(id, floatround(BallSpeed * 0.3), vVelocity)
else
velocity_by_aim(id, BallSpeed, vVelocity)
entity_set_size(Ball, Float:{-15.0, -15.0, 0.0}, Float:{15.0, 15.0, 12.0})
entity_set_int(Ball, EV_INT_iuser1, 0)
if(type == 2)
vVelocity[2] = vOrigin[2]
if(type == 3)
vVelocity[2] = 700.0
entity_set_vector(Ball, EV_VEC_velocity, vVelocity)
emit_sound(Ball, CHAN_WEAPON, "soccer/kick_ball.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
if(type == 1)
{
arg[0] = id
PlayerControlBall = id
set_task(0.1, "control_ball", 0, arg)
}
arg[0] = id
arg[1] = Ball
ball_trail_remove(Ball)
ball_trail(0, arg)
return PLUGIN_CONTINUE
}
public FwdTouchWorld(Ball, World)
{
new Float:vVelocity[3]
entity_get_vector(Ball, EV_VEC_velocity, vVelocity)
if(floatround(vector_length(vVelocity)) > 10)
{
PlayerControlBall = 0
TochBallBlock = false
vVelocity[0] *= 0.85
vVelocity[1] *= 0.85
vVelocity[2] *= 0.85
entity_set_vector(Ball, EV_VEC_velocity, vVelocity)
emit_sound(Ball, CHAN_ITEM, "jb_mod/bounce.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
return PLUGIN_CONTINUE
}
public control_ball(task, arg[])
{
if(PlayerControlBall > 0)
{
new Float:NewVelocity[3], Float:OldVelocity[3]
velocity_by_aim(PlayerControlBall, floatround(BallSpeed * 0.85), NewVelocity)
entity_get_vector(Ball, EV_VEC_velocity, OldVelocity)
NewVelocity[0] = (OldVelocity[0] + NewVelocity[0] * 0.3) * 0.85
NewVelocity[1] = (OldVelocity[1] + NewVelocity[1] * 0.3) * 0.85
NewVelocity[2] = OldVelocity[2] * 0.85
entity_set_vector(Ball, EV_VEC_velocity, NewVelocity)
set_task(0.1, "control_ball", 0, arg)
set_task(0.5, "control_ball_remove")
}
}
public FwdTouchPlayer(Ball, id)
{
new arg[2]
if(!TochBallBlock || (Ball == IDBall[id]))
{
TochBallBlock = true
entity_set_int(Ball, EV_INT_iuser1, id)
entity_set_int(Ball, EV_INT_iuser2, id)
set_task(1.0, "donttouch_ball")
}
arg[0] = id
arg[1] = Ball
ball_trail_remove(Ball)
ball_trail(0, arg)
PlayerControlBall = 0
return PLUGIN_CONTINUE
}
public FwdThinkBall(iEntity)
{
entity_set_float(iEntity, EV_FL_nextthink, halflife_time() + 0.01)
new iOwner
iOwner = pev(iEntity, pev_iuser1)
if(iOwner > 0)
{
if(!is_user_alive(iOwner))
entity_set_int(iEntity, EV_INT_iuser1, 0)
else
{
new Float:vAngles[3], Float:vReturn[3], Float:vOwnerOrigin[3]
new const Float:vVelocity[3] = {1.0, 1.0, 0.0}
entity_get_vector(iOwner, EV_VEC_origin, vOwnerOrigin)
entity_get_vector(iOwner, EV_VEC_v_angle, vAngles)
vReturn[0] = (floatcos(vAngles[1], degrees) * 55.0) + vOwnerOrigin[0]
vReturn[1] = (floatsin(vAngles[1], degrees) * 55.0) + vOwnerOrigin[1]
vReturn[2] = vOwnerOrigin[2]
if(TypeBall == 0)
vReturn[2] -= (entity_get_int(iOwner, EV_INT_flags) & FL_DUCKING) ? 10 : 30
else
vReturn[2] -= (entity_get_int(iOwner, EV_INT_flags) & FL_DUCKING) ? 3 : 9
entity_set_vector(iEntity, EV_VEC_velocity, vVelocity)
entity_set_origin(iEntity, vReturn)
}
}
return PLUGIN_CONTINUE
}
public control_ball_remove()
{
PlayerControlBall = 0
}
public ball_trail(task, arg[2])
{
new classname[32], i=0
if(is_user_connected(arg[0]))
if(entity_get_int(arg[0], EV_INT_body) == 2)
i = entity_get_int(arg[0], EV_INT_skin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(22)
write_short(arg[1])
write_short(SpriteTrailBall)
write_byte(10)
write_byte(8)
write_byte(TrailColor[i][0])
write_byte(TrailColor[i][1])
write_byte(TrailColor[i][2])
write_byte(255)
message_end()
if(is_valid_ent(arg[1]))
entity_get_string(arg[1], EV_SZ_classname, classname, charsmax(classname))
if(equal("BallSimpleJB", classname))
set_rendering(arg[1], kRenderFxGlowShell, TrailColor[i][0], TrailColor[i][1], TrailColor[i][2], kRenderNormal, 20)
set_task(0.1, "ball_trail", 1528164, arg)
}
public ball_trail_remove(Ball)
{
remove_task(1528164)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(99)
write_short(Ball)
message_end()
}
public create_object(id, type)
{
new Float:position[3], Float:mins[3] = {-32.0, -32.0, -32.0}, Float:maxs[3] = {32.0, 32.0, 32.0}
new ent = fm_create_entity("info_target")
pev(id, pev_origin, position)
if(type == 0 || type == 1)
set_pev(ent, pev_classname, "Gate")
fm_entity_set_origin(ent, position)
set_pev(ent, pev_movetype, MOVETYPE_FLY)
set_pev(ent, pev_solid, SOLID_TRIGGER)
fm_entity_set_size(ent, mins, maxs)
Object[EditObject] = ent
return PLUGIN_HANDLED
}
stock fm_entity_set_size(ent, const Float:mins[3], const Float:maxs[3])
{
return engfunc(EngFunc_SetSize, ent, mins, maxs)
}
stock fm_create_entity(const classname[])
{
return engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, classname))
}
stock fm_entity_set_origin(ent, const Float:origin[3])
{
new Float:mins[3], Float:maxs[3]
pev(ent, pev_mins, mins)
pev(ent, pev_maxs, maxs)
engfunc(EngFunc_SetSize, ent, mins, maxs)
return engfunc(EngFunc_SetOrigin, ent, origin)
}