Raised This Month: $32 Target: $400
 8% 

Solved Making an entity levitate and player follow it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-17-2018 , 15:01   Making an entity levitate and player follow it
Reply With Quote #1

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!

Last edited by edon1337; 07-18-2018 at 19:19.
edon1337 is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 07-17-2018 , 15:24   Re: Making an entity levitate and player follow it
Reply With Quote #2

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).
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 07-17-2018 at 15:25.
Ghosted is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-17-2018 , 16:32   Re: Making an entity levitate and player follow it
Reply With Quote #3

Movetype_noclip

>>

movetype_fly


Also remove EngFunc_DropToFloor
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-17-2018 at 16:33.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-17-2018 , 16:55   Re: Making an entity levitate and player follow it
Reply With Quote #4

Quote:
Originally Posted by Ghosted View Post
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 View Post
Movetype_noclip

>>

movetype_fly


Also remove EngFunc_DropToFloor
Still the same
__________________

Last edited by edon1337; 07-17-2018 at 17:00.
edon1337 is offline
maqi
Senior Member
Join Date: Apr 2017
Location: Serbia
Old 07-17-2018 , 19:30   Re: Making an entity levitate and player follow it
Reply With Quote #5

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

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
__________________
stuff

Last edited by maqi; 07-17-2018 at 19:38.
maqi is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 07-17-2018 , 20:30   Re: Making an entity levitate and player follow it
Reply With Quote #6

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)

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 07-17-2018 at 20:38.
EFFx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-18-2018 , 06:43   Re: Making an entity levitate and player follow it
Reply With Quote #7

Quote:
Originally Posted by maqi View Post
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

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
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 View Post
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
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-18-2018 , 07:20   Re: Making an entity levitate and player follow it
Reply With Quote #8

Edon

"constantly changing the velocity."

This doesnt make sense.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-18-2018 , 08:04   Re: Making an entity levitate and player follow it
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
Edon

"constantly changing the velocity."

This doesnt make sense.
Don't you need to keep adding velocity to something that you want to move?
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-18-2018 , 08:16   Re: Making an entity levitate and player follow it
Reply With Quote #10

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.
__________________

Last edited by klippy; 07-18-2018 at 08:18.
klippy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:45.


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