AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ball plugin (https://forums.alliedmods.net/showthread.php?t=278905)

MapCreator 02-10-2016 14:36

Ball plugin
 
Hi everybody. Need help. Sorry for bad english. There is ball plugin. I need that ball rolled only on the ground. It must not jump or smething else. It just must roll on the ground. I could make that when player on the floor and kicks ball, then boll roll on the floor,even player will look up the ball will roll on the floor. Added vVelocity[2] = 0.0 in function KickBall. But when i jump and kick ball it rolls with jumping. Here is source code:
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun> 
#include <engine> 
#include <hamsandwich>

new Shayba
new TrailSprite
new Float:g_vOrigin[3]

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"
}

public 
plugin_init()
{
    
register_plugin("Jail Hockey" "1.0" "MapCreator")
    
register_think("JAILSHAYBA""FwdThinkShayba")
    
register_touch("JAILSHAYBA""player""FwdTouchPlayer")
    
    for(new 
isizeof szEntityi++)
        
register_touch("JAILSHAYBA"szEntity[i], "FwdTouchWorld")
    
    
register_clcmd("say /hm""hockey_menu")
}

public 
plugin_precache()
{
    
precache_model("models/jail/ball_new.mdl")
    
precache_sound("jail/bounce.wav")
    
TrailSprite precache_model("sprites/laserbeam.spr")
}

public 
hockey_menu(id)
{
    new 
menu
    menu 
menu_create("\yМеню Хоккей:\r""hockey_menu_choice")
    
menu_additem(menu"Установить шайбу""1"0)
    
menu_additem(menu"Удалить шайбу""1"0)
    
menu_additem(menu"Загрузить шайбу""1"0)
    
menu_setprop(menuMPROP_NEXTNAME"Далее")
    
menu_setprop(menuMPROP_BACKNAME"Назад")
    
menu_setprop(menuMPROP_EXITNAME"Выход")
    
menu_display(idmenu)
    return 
PLUGIN_HANDLED
}

public 
hockey_menu_choice(idmenuitem)
{
    if(
item == MENU_EXIT)
        return 
PLUGIN_HANDLED
    
    
new dst[32], data[6], accesscallback
    menu_item_getinfo
(menuitemaccessdatacharsmax(data), dstcharsmax(dst), callback)
    
menu_destroy(menu)
    
get_user_name(iddstcharsmax(dst))
    new 
key str_to_num(data)
    switch(
key)
    {
        case 
1:
        {
            if(
pev_valid(Shayba))
                return 
PLUGIN_CONTINUE
            CreateShayba
(id)
        }
        case 
2:
        {
            new 
entity
            
while((entity find_ent_by_class(entity"JAILSHAYBA")) > 0)
                
remove_entity(entity)
            
client_print(idprint_chat"Successfully removed the shayba!")
        }
        case 
3:
        {
            if(
is_valid_ent(Shayba))
            {
                
entity_set_vector(ShaybaEV_VEC_velocityFloat:{0.00.00.0})
                
entity_set_origin(Shaybag_vOrigin)
                
                
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
                
entity_set_size(ShaybaFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
                
entity_set_int(ShaybaEV_INT_iuser10)
                
client_print(idprint_chat"Successfully loaded shayba")
            }
        }
    }
    return 
PLUGIN_HANDLED
}

public 
FwdThinkShayba(iEntity)
{
    if(!
is_valid_ent(Shayba))
        return 
PLUGIN_HANDLED
    
    entity_set_float
(iEntityEV_FL_nextthinkget_gametime() + 0.01)
    new 
iOwner
    iOwner 
pev(iEntitypev_iuser1)
    if(
iOwner 0)
    {
        if(!
is_user_alive(iOwner))
            
entity_set_int(iEntityEV_INT_iuser10)
        else
        {
            new 
ownerButton pev(iOwner,pev_button)

            if(
ownerButton IN_USE)
                return 
KickShayba(iOwner)
            else if(
ownerButton IN_ATTACK2)
                return 
KickShayba(iOwner)
            else if(
ownerButton IN_ATTACK)
                return 
KickShayba(iOwner)

            new 
Float:fVelocity[3]
            
pev(iOwnerpev_velocityfVelocity)
            if(
vector_length(fVelocity) > 20.0)
            {
                new 
Float:fAngles[3]
                
vector_to_angle(fVelocityfAngles)
                
fAngles[0] = 0.0
                set_pev
(iEntitypev_anglesfAngles)
                
set_pev(iEntitypev_sequence1)
            }
            else 
set_pev(iEntitypev_sequence0)

            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]
            
vReturn[2] -= (entity_get_int(iOwnerEV_INT_flags) & FL_DUCKING) ? 10 30
            entity_set_vector
(iEntityEV_VEC_velocityvVelocity)
            
entity_set_origin(iEntityvReturn)
        }
    }
    else
    {
        new 
Float:fVelocity[3]
        
pev(iEntitypev_velocityfVelocity)
        if(
fVelocity[2] > 0.0)
            
fVelocity[2] = 0.0
        
if(vector_length(fVelocity) > 20.0)
        {
            new 
Float:fAngles[3]
            
vector_to_angle(fVelocityfAngles)
            
fAngles[0] = 0.0
            set_pev
(iEntitypev_anglesfAngles)
            
set_pev(iEntitypev_sequence1)
        }
        else 
set_pev(iEntitypev_sequence0)
    }
    return 
PLUGIN_CONTINUE
}

public 
UpdateShayba(id)
{
    if(!
id || get_user_flags(id) & ADMIN_KICK)
    {
        if(
is_valid_ent(Shayba))
        {
            
entity_set_vector(ShaybaEV_VEC_velocityFloat:{0.00.00.0})
            
entity_set_origin(Shaybag_vOrigin)
            
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
            
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
            
entity_set_int(ShaybaEV_INT_iuser10)
        }
    }
    return 
PLUGIN_HANDLED
}

public 
KickShayba(id)
{
    static 
Float:vOrigin[3]
    
entity_get_vector(ShaybaEV_VEC_originvOrigin)
    
    if(
PointContents(vOrigin) != CONTENTS_EMPTY)
        return 
PLUGIN_HANDLED

    
new Float:vVelocity[3]
    
velocity_by_aim(id400vVelocity)
    
    
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
    
entity_set_int(ShaybaEV_INT_iuser10)
    
vVelocity[2] = 0.0
    entity_set_vector
(ShaybaEV_VEC_velocityvVelocity)
    
    return 
PLUGIN_CONTINUE
}

public 
FwdTouchPlayer(Shaybaid)
{
    if(
is_user_bot(id))
        return 
PLUGIN_CONTINUE
    
    
static owner 
    owner 
pev(Shaybapev_iuser1)
    
    if(
owner == 0)
    {
        
entity_set_int(ShaybaEV_INT_iuser1id)
        
set_user_maxspeed(id200.0)
    }
    return 
PLUGIN_CONTINUE
}

public 
FwdTouchWorld(ShaybaWorld)
{
    static 
Float:velocity[3]
    
entity_get_vector(ShaybaEV_VEC_velocityvelocity)
    
    if(
floatround(vector_length(velocity)) > 10)
    {
        
velocity[0] *= 0.85
        velocity
[1] *= 0.85
        velocity
[2] *= 0.85
        
        entity_set_vector
(ShaybaEV_VEC_velocityvelocity)
        
emit_sound(ShaybaCHAN_ITEM"jail/bounce.wav"1.0ATTN_NORM0PITCH_NORM)
    }

    return 
PLUGIN_CONTINUE
}

public 
CreateShayba(id)
{
    new 
Float:vOrigin[3] = {0.00.00.0}
    
Shayba create_entity("info_target")
    if(
is_valid_ent(Shayba))
    {
        
entity_set_string(ShaybaEV_SZ_classname"JAILSHAYBA")
        
entity_set_int(ShaybaEV_INT_solidSOLID_TRIGGER)
        
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
        
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
        
entity_set_float(ShaybaEV_FL_framerate0.0)
        
entity_set_int(ShaybaEV_INT_sequence0)
        
entity_set_float(ShaybaEV_FL_nextthinkget_gametime() + 0.05)
        
entity_set_model(Shayba"models/jail/ball_new.mdl")
        
client_print(idprint_chat"Successfully created shayba!")
        
        if(
id 0)
        {
            new 
iOrigin[3]
            
get_user_origin(idiOrigin3)
            
IVecFVec(iOriginvOrigin)
            
vOrigin[2] += 5.0
            entity_set_origin
(ShaybavOrigin)
        }
        else
            
entity_set_origin(ShaybavOrigin)
        
        
g_vOrigin vOrigin
        
return Shayba
    
}
    return -
1;



Mario AR. 02-14-2016 23:42

Re: Ball plugin
 
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun> 
#include <engine> 
#include <hamsandwich>
#include <xs>

new const Float:CREATE_DIST 200.0;

new 
Shayba
new TrailSprite
new Float:g_vOrigin[3]

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"
}

public 
plugin_init()
{
    
register_plugin("Jail Hockey" "1.0" "MapCreator")
    
register_think("JAILSHAYBA""FwdThinkShayba")
    
register_touch("JAILSHAYBA""player""FwdTouchPlayer")
    
    for(new 
isizeof szEntityi++)
        
register_touch("JAILSHAYBA"szEntity[i], "FwdTouchWorld")
    
    
register_clcmd("say /hm""hockey_menu")
}

public 
plugin_precache()
{
    
precache_model("models/jail/ball_new.mdl")
    
precache_sound("jail/bounce.wav")
    
TrailSprite precache_model("sprites/laserbeam.spr")
}

public 
hockey_menu(id)
{
    new 
menu
    menu 
menu_create("\yМеню Хоккей:\r""hockey_menu_choice")
    
menu_additem(menu"Установить шайбу""1"0)
    
menu_additem(menu"Удалить шайбу""1"0)
    
menu_additem(menu"Загрузить шайбу""1"0)
    
menu_setprop(menuMPROP_NEXTNAME"Далее")
    
menu_setprop(menuMPROP_BACKNAME"Назад")
    
menu_setprop(menuMPROP_EXITNAME"Выход")
    
menu_display(idmenu)
    return 
PLUGIN_HANDLED
}

public 
hockey_menu_choice(idmenuitem)
{
    if(
item == MENU_EXIT)
        return 
PLUGIN_HANDLED
    
    
new dst[32], data[6], accesscallback
    menu_item_getinfo
(menuitemaccessdatacharsmax(data), dstcharsmax(dst), callback)
    
menu_destroy(menu)
    
get_user_name(iddstcharsmax(dst))
    new 
key str_to_num(data)
    switch(
key)
    {
        case 
1:
        {
            if(
pev_valid(Shayba))
                return 
PLUGIN_CONTINUE
            CreateShayba
(id)
        }
        case 
2:
        {
            new 
entity
            
while((entity find_ent_by_class(entity"JAILSHAYBA")) > 0)
                
remove_entity(entity)
            
client_print(idprint_chat"Successfully removed the shayba!")
        }
        case 
3:
        {
            if(
is_valid_ent(Shayba))
            {
                
entity_set_vector(ShaybaEV_VEC_velocityFloat:{0.00.00.0})
                
entity_set_origin(Shaybag_vOrigin)
                
                
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
                
entity_set_size(ShaybaFloat:{-15.0, -15.00.0}, Float:{15.015.012.0})
                
entity_set_int(ShaybaEV_INT_iuser10)
                
client_print(idprint_chat"Successfully loaded shayba")
            }
        }
    }
    return 
PLUGIN_HANDLED
}

public 
FwdThinkShayba(iEntity)
{
    if(!
is_valid_ent(Shayba))
        return 
PLUGIN_HANDLED
    
    entity_set_float
(iEntityEV_FL_nextthinkget_gametime() + 0.01)
    new 
iOwner
    iOwner 
pev(iEntitypev_iuser1)
    if(
iOwner 0)
    {
        if(!
is_user_alive(iOwner))
            
entity_set_int(iEntityEV_INT_iuser10)
        else
        {
            new 
ownerButton pev(iOwner,pev_button)

            if(
ownerButton IN_USE)
                return 
KickShayba(iOwner)
            else if(
ownerButton IN_ATTACK2)
                return 
KickShayba(iOwner)
            else if(
ownerButton IN_ATTACK)
                return 
KickShayba(iOwner)

            new 
Float:fVelocity[3]
            
pev(iOwnerpev_velocityfVelocity)
            if(
vector_length(fVelocity) > 20.0)
            {
                new 
Float:fAngles[3]
                
vector_to_angle(fVelocityfAngles)
                
fAngles[0] = 0.0
                set_pev
(iEntitypev_anglesfAngles)
                
set_pev(iEntitypev_sequence1)
            }
            else 
set_pev(iEntitypev_sequence0)

            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] = 0.0;
            
/*
            vReturn[2] = vOwnerOrigin[2]
            vReturn[2] -= (entity_get_int(iOwner, EV_INT_flags) & FL_DUCKING) ? 10 : 30 */
            
entity_set_vector(iEntityEV_VEC_velocityvVelocity)
            
entity_set_origin(iEntityvReturn)
        }
    }
    else
    {
        new 
Float:fVelocity[3]
        
pev(iEntitypev_velocityfVelocity)
        if(
fVelocity[2] > 0.0)
            
fVelocity[2] = 0.0
        
if(vector_length(fVelocity) > 20.0)
        {
            new 
Float:fAngles[3]
            
vector_to_angle(fVelocityfAngles)
            
fAngles[0] = 0.0
            set_pev
(iEntitypev_anglesfAngles)
            
set_pev(iEntitypev_sequence1)
        }
        else 
set_pev(iEntitypev_sequence0)
    }
    return 
PLUGIN_CONTINUE
}

public 
UpdateShayba(id)
{
    if(!
id || get_user_flags(id) & ADMIN_KICK)
    {
        if(
is_valid_ent(Shayba))
        {
            
entity_set_vector(ShaybaEV_VEC_velocityFloat:{0.00.00.0})
            
entity_set_origin(Shaybag_vOrigin)
            
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
            
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
            
entity_set_int(ShaybaEV_INT_iuser10)
        }
    }
    return 
PLUGIN_HANDLED
}

public 
KickShayba(id)
{
    static 
Float:vOrigin[3]
    
entity_get_vector(ShaybaEV_VEC_originvOrigin)
    
    if(
PointContents(vOrigin) != CONTENTS_EMPTY)
        return 
PLUGIN_HANDLED

    
new Float:vVelocity[3]
    
velocity_by_aim(id400vVelocity)
    
    
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
    
entity_set_int(ShaybaEV_INT_iuser10)
    
vVelocity[2] = 0.0
    entity_set_vector
(ShaybaEV_VEC_velocityvVelocity)
    
    return 
PLUGIN_CONTINUE
}

public 
FwdTouchPlayer(Shaybaid)
{
    if(
is_user_bot(id))
        return 
PLUGIN_CONTINUE
    
    
static owner 
    owner 
pev(Shaybapev_iuser1)
    
    if(
owner == 0)
    {
        
entity_set_int(ShaybaEV_INT_iuser1id)
        
set_user_maxspeed(id200.0)
    }
    return 
PLUGIN_CONTINUE
}

public 
FwdTouchWorld(ShaybaWorld)
{
    static 
Float:velocity[3]
    
entity_get_vector(ShaybaEV_VEC_velocityvelocity)
    
    if(
floatround(vector_length(velocity)) > 10)
    {
        
velocity[0] *= 0.85
        velocity
[1] *= 0.85
        velocity
[2] *= 0.85
        
        entity_set_vector
(ShaybaEV_VEC_velocityvelocity)
        
emit_sound(ShaybaCHAN_ITEM"jail/bounce.wav"1.0ATTN_NORM0PITCH_NORM)
    }

    return 
PLUGIN_CONTINUE
}

public 
CreateShayba(id)
{
    new 
Float:vOrigin[3] = {0.00.00.0}
    
Shayba create_entity("info_target")
    if(
is_valid_ent(Shayba))
    {
        
entity_set_string(ShaybaEV_SZ_classname"JAILSHAYBA")
        
entity_set_int(ShaybaEV_INT_solidSOLID_TRIGGER)
        
entity_set_int(ShaybaEV_INT_movetypeMOVETYPE_BOUNCE)
        
entity_set_size(ShaybaFloat:{-4.0, -4.0, -4.0}, Float:{4.04.04.0})
        
entity_set_float(ShaybaEV_FL_framerate0.0)
        
entity_set_int(ShaybaEV_INT_sequence0)
        
entity_set_float(ShaybaEV_FL_nextthinkget_gametime() + 0.05)
        
entity_set_model(Shayba"models/jail/ball_new.mdl")
        
client_print(idprint_chat"Successfully created shayba!")
        
        if(
id 0)
        {
            new 
Float:vOriginp[3];
            
entity_get_vector(idEV_VEC_originvOrigin);
            
entity_get_vector(idEV_VEC_anglesvOriginp);
            
angle_vector(vOriginpANGLEVECTOR_FORWARDvOriginp);
            
vOriginp[2] = 0.0;
            
xs_vec_normalize(vOriginpvOriginp);
            
xs_vec_mul_scalar(vOriginpCREATE_DISTvOriginp);
            
vOriginp[2] = entity_get_int(idEV_INT_flags) & FL_DUCKING ? -18.0 : -36.0;
            
xs_vec_add(vOriginpvOriginvOrigin);

            
entity_set_origin(ShaybavOrigin)
        }
        else
            
entity_set_origin(ShaybavOrigin)
        
        
g_vOrigin vOrigin
        
return Shayba
    
}
    return -
1;




This may work ONLY IF the ball always stays in the same Z position (means no ladders/slopes).


All times are GMT -4. The time now is 09:27.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.