AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Making an entity levitate and player follow it (https://forums.alliedmods.net/showthread.php?t=309215)

edon1337 07-17-2018 15:01

Making an entity levitate and player follow it
 
Hi,

What needs to be done so an entity can levitate in the sky and move towards a destination and all the players to be in that entity and move along with it? Basically the entity is an airplane.

Just as new round starts the entity should be spawned and all the players put in it and to follow it.
Here's a demonstration picture: https://ibb.co/e6RVUJ

Here's the code I made but it just spawns the Airplane but it doesn't move, and I don't get attached to the airplane, so I just fall down.

PHP Code:

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

#define AIRPLANE_CLASSNAME "ent_airplane"

new bool:g_bPlayerInPlane33 ];

new 
g_iAirPlaneEnt;

public 
plugin_init( )
{
    
register_logevent"OnNewRound"2"1=Round_Start" );

    
RegisterHamHam_Think"info_target""@HamThinkInfoTarget_Pre");
    
RegisterHamHam_Player_Jump"player""@HamPlayerJump_Post");
    
RegisterHamHam_Player_PreThink"player""@HamThinkPlayer_Pre");
}

public @
HamPlayerJump_Postid )
{
    if( ! 
g_bPlayerInPlaneid ] )
    return 
HAM_IGNORED;

    
set_pevidpev_movetypeMOVETYPE_TOSS );
    
set_pevidpev_gravity10.0 );

    
g_bPlayerInPlaneid ] = false;
        
    return 
HAM_IGNORED;
}


public 
OnNewRound( )
{
    
MakeAirPlane( );
}

public @
HamThinkInfoTarget_PreiEnt )
{
    if( ! 
pev_validiEnt ) )
    return 
HAM_IGNORED;
    
    new 
szClassName32 ];
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) );

    static 
Float:fVelocity]; 
    
peviEntpev_velocityfVelocity );
    
    if( 
equalszClassNameAIRPLANE_CLASSNAME ) )
    {
        
set_peviEntpev_nextthinkget_gametime( ) + 0.01 );
        
        
velocity_by_aimiEnt1fVelocity );
    }
    
    return 
HAM_IGNORED;
}

public @
HamThinkPlayer_Preid )
{
    if( ! 
is_user_aliveid ) )
    return 
HAM_IGNORED;
        
    if( 
g_bPlayerInPlaneid ] )
    {
        new 
Float:fAirPlaneLocation];
        
pevg_iAirPlaneEntpev_originfAirPlaneLocation );
        
        
set_pevidpev_originfAirPlaneLocation );
    }
    
    return 
HAM_IGNORED;
}

MakeAirPlane( )
{  
    new 
Float:fOrigin] = { 3753.0, -23.03316.0 };
    new 
Float:fAngle] = { -20.3, -175.90.0 };
    
    
g_iAirPlaneEnt create_entity"info_target" );
    
    
set_pevg_iAirPlaneEntpev_classnameAIRPLANE_CLASSNAME );
    
engfuncEngFunc_SetModelg_iAirPlaneEnt"models/AirPlane.mdl" );
    
set_pevg_iAirPlaneEntpev_solidSOLID_BBOX );
    
set_pevg_iAirPlaneEntpev_movetypeMOVETYPE_NOCLIP );
    
set_pevg_iAirPlaneEntpev_originfOrigin );
    
    
engfuncEngFunc_DropToFloorg_iAirPlaneEnt );
    
    
set_pevg_iAirPlaneEntpev_nextthinkget_gametime( ) + 0.01 );
    
    new 
szPlayers32 ], iNumiTempID;
    
get_playersszPlayersiNum"a" );
    
    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];
        
        
set_peviTempIDpev_solidSOLID_NOT );
        
set_peviTempIDpev_originfOrigin );
        
set_peviTempIDpev_anglesfAngle );
    }


Thanks for any help!

Ghosted 07-17-2018 15:24

Re: Making an entity levitate and player follow it
 
You fall cause that airplane is BBOX but has not set size and if u set size you get cube like box. And if your airplane has interior than making such thing is impossible (let players in) except making it with bsp model (maybe).

Natsheh 07-17-2018 16:32

Re: Making an entity levitate and player follow it
 
Movetype_noclip

>>

movetype_fly


Also remove EngFunc_DropToFloor

edon1337 07-17-2018 16:55

Re: Making an entity levitate and player follow it
 
Quote:

Originally Posted by Ghosted (Post 2604341)
You fall cause that airplane is BBOX but has not set size and if u set size you get cube like box. And if your airplane has interior than making such thing is impossible (let players in) except making it with bsp model (maybe).

Yeah, you're right. I'm not planning to actually let players get in the plane, they should just be somewhere attached to it and move along with it.
This is what I'm trying to achieve
https://ibb.co/muCw3d

Quote:

Originally Posted by Natsheh (Post 2604351)
Movetype_noclip

>>

movetype_fly


Also remove EngFunc_DropToFloor

Still the same

maqi 07-17-2018 19:30

Re: Making an entity levitate and player follow it
 
The entity won't move on it's own, you have to set it's velocity. Also do what Natsheh said, or nothing will probably work :D

For attaching the players:
You can try something like attach_view() to simulate what you are trying to achieve. It's a good solution, except the camera won't be movable before jumping ( seet the player origin to the plane and reset the view ). The alternative would be to match the player origin and velocity with the plane, that should work. ( not 100% sure ). Other than that you can try to set the view manually somehow or actually set the origin of a player, but i figure those would be clunky if not done properly.

Also, demonstration 10/10 8)

EFFx 07-17-2018 20:30

Re: Making an entity levitate and player follow it
 
I don't know what you mean with levitate, but you can just set the plane:

- Origin
- View angle (to the direction)
- And pev_velocity

For make players follow the plane, you just need set them the same vectors of the plane and set their gravity and maxspeed to 0. (can't fall and can't move inside the plane).

That's the code I'm using on my Battleground to create the plane:

PHP Code:

public createPlane()
{
    new 
Float:fOrigin[3], Float:fAngle[3], Float:fVelocity[3]
    
getRandomPlaneDirection(fOriginfAnglefVelocity//the code that gets four random directions

    
new iEnt fm_create_entity("info_target")
    
fm_create_ent
    
(
        
iEnt
        
g_szClassNamesData[cTransporter], 
        
g_szModelsData[mTransporter], 
        
fOrigin,
        
fVelocity,
        
fAngle
    
// code to create the plane
    
    
g_bPlaneSpanwed true
    g_iEnt
[pPlaneTransporter] = iEnt
    fOrigin
[2] -= 40.0 // players under the plane.
    
    
new iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"ach")
    for(new 
iid;iNum;i++)
    {
        
id iPlayers[i]
        
        
setInvisibility(idtrue// for players can't be seen by their enemies.
        
client_cmd(id"spk ^"%s^""g_szSoundsData[sTransporter]) // sound of the plane
        
                //here are all vectors for players be able to follow the plane
        
set_pev(idpev_originfOrigin// Same origin of the plane
        
set_pev(idpev_anglesfAngle// Same direction of the plane
        
set_pev(idpev_fixangle1// Fix the angle 
        
set_pev(idpev_velocityfVelocity// Same velocity of the plane
        
set_pev(idpev_gravity0.000001//Can't fall
        
set_pev(idpev_maxspeed0.000001//Can't move

              // some booleans to use later.
        
g_dUserData[id][bIsOnPlane] = true
        g_dUserData
[id][bCanUseParachute] = false
    
}
    
        
// to remove the plane
    
set_task(PLANE_REMOVE_TIME"checkPlaneOrigin"TASK_PLANE)



edon1337 07-18-2018 06:43

Re: Making an entity levitate and player follow it
 
Quote:

Originally Posted by maqi (Post 2604385)
The entity won't move on it's own, you have to set it's velocity. Also do what Natsheh said, or nothing will probably work :D

For attaching the players:
You can try something like attach_view() to simulate what you are trying to achieve. It's a good solution, except the camera won't be movable before jumping ( seet the player origin to the plane and reset the view ). The alternative would be to match the player origin and velocity with the plane, that should work. ( not 100% sure ). Other than that you can try to set the view manually somehow or actually set the origin of a player, but i figure those would be clunky if not done properly.

Also, demonstration 10/10 8)

If you checked the code, you'd see I'm constantly changing the velocity.
I don't need to attach the view, I need to attach the entire entity.
Again, if you checked the code you'd see I'm settings players' origin at plane's origin.

Quote:

Originally Posted by EFFx (Post 2604391)
I don't know what you mean with levitate, but you can just set the plane:

- Origin
- View angle (to the direction)
- And pev_velocity

For make players follow the plane, you just need set them the same vectors of the plane and set their gravity and maxspeed to 0. (can't fall and can't move inside the plane).

That's the code I'm using on my Battleground to create the plane:

PHP Code:

public createPlane()
{
    new 
Float:fOrigin[3], Float:fAngle[3], Float:fVelocity[3]
    
getRandomPlaneDirection(fOriginfAnglefVelocity//the code that gets four random directions

    
new iEnt fm_create_entity("info_target")
    
fm_create_ent
    
(
        
iEnt
        
g_szClassNamesData[cTransporter], 
        
g_szModelsData[mTransporter], 
        
fOrigin,
        
fVelocity,
        
fAngle
    
// code to create the plane
    
    
g_bPlaneSpanwed true
    g_iEnt
[pPlaneTransporter] = iEnt
    fOrigin
[2] -= 40.0 // players under the plane.
    
    
new iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum"ach")
    for(new 
iid;iNum;i++)
    {
        
id iPlayers[i]
        
        
setInvisibility(idtrue// for players can't be seen by their enemies.
        
client_cmd(id"spk ^"%s^""g_szSoundsData[sTransporter]) // sound of the plane
        
                //here are all vectors for players be able to follow the plane
        
set_pev(idpev_originfOrigin// Same origin of the plane
        
set_pev(idpev_anglesfAngle// Same direction of the plane
        
set_pev(idpev_fixangle1// Fix the angle 
        
set_pev(idpev_velocityfVelocity// Same velocity of the plane
        
set_pev(idpev_gravity0.000001//Can't fall
        
set_pev(idpev_maxspeed0.000001//Can't move

              // some booleans to use later.
        
g_dUserData[id][bIsOnPlane] = true
        g_dUserData
[id][bCanUseParachute] = false
    
}
    
        
// to remove the plane
    
set_task(PLANE_REMOVE_TIME"checkPlaneOrigin"TASK_PLANE)



Levitate = stay in air

Thanks I'll check it out

Natsheh 07-18-2018 07:20

Re: Making an entity levitate and player follow it
 
Edon

"constantly changing the velocity."

This doesnt make sense.

edon1337 07-18-2018 08:04

Re: Making an entity levitate and player follow it
 
Quote:

Originally Posted by Natsheh (Post 2604464)
Edon

"constantly changing the velocity."

This doesnt make sense.

Don't you need to keep adding velocity to something that you want to move?

klippy 07-18-2018 08:16

Re: Making an entity levitate and player follow it
 
You aren't changing it though. velocity_by_aim doesn't set the velocity. Also to change entity's (and player's) position use EngFunc_SetOrigin, not pev_origin.
Whether you need to keep adding velocity depends on the movetype. I believe that for MOVETYPE_FLY you don't as it isn't affected by friction, setting it once should be alright.


All times are GMT -4. The time now is 10:13.

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