Русское сообщество по скриптингу

Выдать мяч определенному игроку

Все вопросы по скриптингу для AMXX, помощь в редактировании плагинов.

Модераторы: Subb98, liFe iS GoOD

Правила форума
1. Запрещено материться и оскорблять других участников форума.
2. Запрещен флуд, оффтоп, дабл постинг во всех разделах форума, кроме раздела "Болтовня".
3. Запрещено взламывать сайт/форум или наносить любой вред проекту.
4. Запрещено рекламировать другие ресурсы.
5. Запрещено создавать темы без информативного названия. Название темы должно отображать ее смысл.

В данном разделе форума разрешено создавать темы, касающие только скриптинга для AMX Mod X.

Правила при создании новой темы:
1. При вставке кода плагина необходимо использовать тег [code=php].
2. Любые изображения должны быть загружены, как вложения к вашему сообщению.
3. При описании проблемы или запросе на помощь в редактировании плагина обязательно выкладывайте исходник sma плагина.

Выдать мяч определенному игроку

Сообщение butkov34 » 27 май 2020, 20:53

Как можно сделать так, чтобы мяч появлялся не по прицелу, а у игрока (пускай его id = iPlayer)?
Код: Выделить всё
public spawn_ball(idtype)
{
    new 
classname[32]
    
PlayerControlBall 0
    TochBallBlock 
false
    
if(is_valid_ent(Ball))
        
entity_get_string(BallEV_SZ_classnameclassnamecharsmax(classname))
    if(
equal("BallSimpleJB"classname) && TypeBall == type)
    {
        
entity_set_vector(BallEV_VEC_velocityFloat:{0.00.00.0})
        
entity_set_origin(Ballg_vOrigin)
        
entity_set_int(BallEV_INT_movetypeMOVETYPE_BOUNCE)
        
entity_set_size(BallFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
        
entity_set_int(BallEV_INT_iuser10)
    }
    else
        
create_ball(idtype)

Весь плагин
Код: Выделить всё
#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] =
{
    {
255255255},
    {
00255},
    {
1500255},
    {
2551500},
    {
120120120},
    {
02550},
    {
25500}
}

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=0i<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=1i<=32i++)
    {
        
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], iKeysiLen formatex(szMenucharsmax(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(idiKeysszMenu, -1"Show_FootBallMenu")
}

public 
Handle_FootBallMenu(idkey)
{
    new 
name[32]
    
get_user_name(idnamecharsmax(name))
    
    switch(
key)
    {
        case 
0:
        {
            
spawn_ball(id0)
            if(
FootballStartemit_sound(0CHAN_AUTO"soccer/grab_ball.wav"1.0ATTN_NORM0PITCH_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 
8client_cmd(id"cmd_minigame")
    }
    return 
PLUGIN_HANDLED
}

public 
client_prethink(id)
{
    new 
iOwner
    
if(is_user_alive(id)) 
    {
        if(
entity_get_int(idEV_INT_button) & IN_USE)
        {
            if(
pev_valid(Ball))
                
iOwner pev(Ballpev_iuser1)
            if(
iOwner == id)
                
KickBall(id0)
        }
        else if(
entity_get_int(idEV_INT_button) & IN_RELOAD)
        {
            new 
iOwner
            
if(pev_valid(Ball))
                
iOwner pev(Ballpev_iuser1)
            if(
iOwner == id)
                
KickBall(id1)
        }
        else if(
entity_get_int(idEV_INT_button) & IN_ATTACK2)
        {
            new 
iOwner
            
if(pev_valid(Ball))
                
iOwner pev(Ballpev_iuser1)
            if(
iOwner == id)
                
KickBall(id2)
        }
        else if(
entity_get_int(idEV_INT_button) & IN_ATTACK)
        {
            if(
TypeBall != 1)
            {
                new 
iOwner
                
if(pev_valid(Ball))
                    
iOwner pev(Ballpev_iuser1)
                if(
iOwner == id)
                    
KickBall(id3)
            }
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
create_ball(idtype)
{
    new 
Float:vOrigin[3] = {0.00.00.0}, rand random_num(01)
    
Ball create_entity("info_target")
    
TypeBall type
    
if(is_valid_ent(Ball))
    {
        
entity_set_string(BallEV_SZ_classname"BallSimpleJB")
        
entity_set_int(BallEV_INT_solidSOLID_TRIGGER)
        
entity_set_int(BallEV_INT_movetypeMOVETYPE_BOUNCE)
        
entity_set_size(BallFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
        
entity_set_float(BallEV_FL_framerate0.0)
        
entity_set_int(BallEV_INT_sequence0)
        
entity_set_float(BallEV_FL_nextthinkget_gametime() + 0.01)
        if(
rand == && TypeBall == 0)
            
entity_set_model(Ball"models/soccer/ball.mdl")
        else if(
rand == && TypeBall == 0)
            
entity_set_model(Ball"models/soccer/ball.mdl")
        if(
TypeBall == 1)
            
set_pev(Ballpev_gravity0.6)
        if(
id 0)
        {
            new 
iOrigin[3]
            
get_user_origin(idiOrigin3)
            
IVecFVec(iOriginvOrigin)
            
vOrigin[2] += 5.0;
            
entity_set_origin(BallvOrigin)
        }
        
g_vOrigin vOrigin
        
return Ball
    
}
    return -
1
}

public 
spawn_ball(idtype)
{
    new 
classname[32]
    
PlayerControlBall 0
    TochBallBlock 
false
    
if(is_valid_ent(Ball))
        
entity_get_string(BallEV_SZ_classnameclassnamecharsmax(classname))
    if(
equal("BallSimpleJB"classname) && TypeBall == type)
    {
        
entity_set_vector(BallEV_VEC_velocityFloat:{0.00.00.0})
        
entity_set_origin(Ballg_vOrigin)
        
entity_set_int(BallEV_INT_movetypeMOVETYPE_BOUNCE)
        
entity_set_size(BallFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
        
entity_set_int(BallEV_INT_iuser10)
    }
    else
        
create_ball(idtype)
}

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(idtype)
{
    new 
Float:vOrigin[3], Float:vVelocity[3], arg[2]
    
entity_get_vector(BallEV_VEC_originvOrigin)    
    if(
PointContents(vOrigin) != CONTENTS_EMPTY)
        return 
PLUGIN_HANDLED
    
if(type == 3)
        
velocity_by_aim(idfloatround(BallSpeed 0.3), vVelocity)
    else
        
velocity_by_aim(idBallSpeedvVelocity)
    
entity_set_size(BallFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
    
entity_set_int(BallEV_INT_iuser10)
    if(
type == 2)
        
vVelocity[2] = vOrigin[2]
    if(
type == 3)
        
vVelocity[2] = 700.0
    entity_set_vector
(BallEV_VEC_velocityvVelocity)
    
emit_sound(BallCHAN_WEAPON"soccer/kick_ball.wav"1.0ATTN_NORM0PITCH_NORM)
    if(
type == 1)
    {
        
arg[0] = id
        PlayerControlBall 
id
        set_task
(0.1"control_ball"0arg)
    }
    
arg[0] = id
    arg
[1] = Ball
    ball_trail_remove
(Ball)
    
ball_trail(0arg)
    return 
PLUGIN_CONTINUE
}

public 
FwdTouchWorld(BallWorld)
{
    new 
Float:vVelocity[3]
    
entity_get_vector(BallEV_VEC_velocityvVelocity)
    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
(BallEV_VEC_velocityvVelocity)
        
emit_sound(BallCHAN_ITEM"jb_mod/bounce.wav"1.0ATTN_NORM0PITCH_NORM)
    }
    return 
PLUGIN_CONTINUE
}

public 
control_ball(taskarg[])
{
    if(
PlayerControlBall 0)
    {
        new 
Float:NewVelocity[3], Float:OldVelocity[3]
        
velocity_by_aim(PlayerControlBallfloatround(BallSpeed 0.85), NewVelocity)
        
entity_get_vector(BallEV_VEC_velocityOldVelocity)
        
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
(BallEV_VEC_velocityNewVelocity)
        
set_task(0.1"control_ball"0arg)
        
set_task(0.5"control_ball_remove")
    }
}

public 
FwdTouchPlayer(Ballid)
{
    new 
arg[2]
    if(!
TochBallBlock || (Ball == IDBall[id]))
    {
        
TochBallBlock true
        entity_set_int
(BallEV_INT_iuser1id)
        
entity_set_int(BallEV_INT_iuser2id)
        
set_task(1.0"donttouch_ball")
    }
    
arg[0] = id
    arg
[1] = Ball
    ball_trail_remove
(Ball)
    
ball_trail(0arg)
    
PlayerControlBall 0
    
return PLUGIN_CONTINUE
}

public 
FwdThinkBall(iEntity)
{
    
entity_set_float(iEntityEV_FL_nextthinkhalflife_time() + 0.01)
    new 
iOwner
    iOwner 
pev(iEntitypev_iuser1)
    if(
iOwner 0)
    {
        if(!
is_user_alive(iOwner))
            
entity_set_int(iEntityEV_INT_iuser10)
        else
        {
            new 
Float:vAngles[3], Float:vReturn[3], Float:vOwnerOrigin[3]
            new const 
Float:vVelocity[3] = {1.01.00.0}
            
entity_get_vector(iOwnerEV_VEC_originvOwnerOrigin)
            
entity_get_vector(iOwnerEV_VEC_v_anglevAngles)
            
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(iOwnerEV_INT_flags) & FL_DUCKING) ? 10 30
            
else
                
vReturn[2] -= (entity_get_int(iOwnerEV_INT_flags) & FL_DUCKING) ? 9
            entity_set_vector
(iEntityEV_VEC_velocityvVelocity)
            
entity_set_origin(iEntityvReturn)
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
control_ball_remove()
{
    
PlayerControlBall 0
}

public 
ball_trail(taskarg[2])
{
    new 
classname[32], i=0
    
if(is_user_connected(arg[0]))
        if(
entity_get_int(arg[0], EV_INT_body) == 2)
            
entity_get_int(arg[0], EV_INT_skin)
    
message_begin(MSG_BROADCASTSVC_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_classnameclassnamecharsmax(classname))
    if(
equal("BallSimpleJB"classname))
        
set_rendering(arg[1], kRenderFxGlowShellTrailColor[i][0], TrailColor[i][1], TrailColor[i][2], kRenderNormal20)
    
set_task(0.1"ball_trail"1528164arg)
}

public 
ball_trail_remove(Ball)
{
    
remove_task(1528164)
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
    
write_byte(99)
    
write_short(Ball)
    
message_end()
}

public 
create_object(idtype)
{
    new 
Float:position[3], Float:mins[3] = {-32.0, -32.0, -32.0}, Float:maxs[3] = {32.032.032.0}
    new 
ent fm_create_entity("info_target")
    
pev(idpev_originposition)
    if(
type == || type == 1)
        
set_pev(entpev_classname"Gate")
    
fm_entity_set_origin(entposition)
    
set_pev(entpev_movetypeMOVETYPE_FLY)
    
set_pev(entpev_solidSOLID_TRIGGER)
    
fm_entity_set_size(entminsmaxs)
    
Object[EditObject] = ent
    
return PLUGIN_HANDLED
}

stock fm_entity_set_size(ent, const Float:mins[3], const Float:maxs[3])
{
    return 
engfunc(EngFunc_SetSizeentminsmaxs)
}

stock fm_create_entity(const classname[])
{
    return 
engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringclassname))
}

stock fm_entity_set_origin(ent, const Float:origin[3])
{
    new 
Float:mins[3], Float:maxs[3]
    
pev(entpev_minsmins)
    
pev(entpev_maxsmaxs)
    
engfunc(EngFunc_SetSizeentminsmaxs)
    return 
engfunc(EngFunc_SetOriginentorigin)
И сразу еще один вопрос, если мяч попал в игрока как этот момент можно отловить?
Аватара пользователя
butkov34
 
Сообщения: 57
Зарегистрирован: 17 апр 2020, 12:14
Благодарил (а): 9 раз.
Поблагодарили: 1 раз.
Языки программирования: Я ничего не знаю

Вернуться в Скриптинг

Кто сейчас на конференции

Сейчас этот форум просматривают: Yandex [Bot] и гости: 21