AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about noclip (https://forums.alliedmods.net/showthread.php?t=74554)

point.blank 07-20-2008 21:38

Question about noclip
 
Is it possible to have noclip and NOT be able to go through walls, to simulate something similar to flying?

Exolent[jNr] 07-20-2008 21:45

Re: Question about noclip
 
This is just a code snippet, not a working plugin.
You should add checks to see if player is able to use this and other stuff.
This is very generic and not advanced.
It only goes the direction the player is aiming, instead of following the player's keys.
I could probably find out how to match the keys, but I decided to be lazy until you asked for it :P

PHP Code:

#include <amxmodx>
#include <fakemeta>

public plugin_init()
{
    
register_forward(FM_PlayerPreThink"FwdPlayerPreThink"0);
}

public 
FwdPlayerPreThink(plr)
{
    if( !
is_user_alive(plr) )
    {
        return 
FMRES_IGNORED;
    }
    
    new 
Float:maxspeed;
    
pev(plrpev_maxspeedmaxspeed);
    
    new 
Float:velocity[3];
    
velocity_by_aim(plrfloatround(maxspeed), velocity);
    
    
set_pev(plrpev_velocityvelocity);
    
    return 
FMRES_IGNORED;



donnie.yang 07-21-2008 04:42

Re: Question about noclip
 
bind "key" +hook

Exolent[jNr] 07-21-2008 04:53

Re: Question about noclip
 
Not all servers have the hook mod.

Prajch 08-19-2008 01:35

Re: Question about noclip
 
You could set their gravity to 0 and then set their velocity with velocityByAim in their prethink, whenever they're holding IN_FORWARD (and when they aren't, set it to 0).

You'll have to simulate strafing and moving backwards too. Moving backwards would be the same but with a negative velocity. For strafing, it's a little more complicated. You'll have to use angle_vector ( Float:vector[3], FRU, Float:vReturn[3] ).

The first parameter is an array containing their view angles; you can get it with something like this if you use Fakemeta:

Code:

new Float:viewAngles[3]
 pev(id, pev_v_angle, viewAngles)

FRU (stands for forward right up I'm guessing) is one of three values: ANGLEVECTOR_FORWARD (or 1), ANGLEVECTOR_RIGHT (or 2) and ANGLEVECTOR_UP (or 3). Then you create another array and use it as the third parameter; it'll store the components of a unit vector pointing in whatever direction you chose (a unit vector is a directed line with a length of 1).

So for example, if you want to simulate a left strafe movement, you check if the player is holding IN_MOVELEFT, then you use ANGLEVECTOR_RIGHT as your "FRU" value and get a vector pointing in that direction. Then you can set their velocity in the left direction by doing something like this:

Code:

angleVector[0] = -angleVector[0] * desiredVelocity
angleVector[1] = -angleVector[1] * desiredVelocity
angleVector[2] = -angleVector[2] * desiredVelocity
set_pev(id, pev_velocity, angleVector)

You set it as negative because left is the opposite direction of right, and you have to multiply each component by some number, otherwise it'll set their velocity to 1 in that direction (since it's a unit vector).

danielkza 08-19-2008 12:48

Re: Question about noclip
 
What about MOVETYPE_FLY? Did somebody test it?

Exolent[jNr] 08-19-2008 15:12

Re: Question about noclip
 
Player pev_movetype values are restricted to MOVETYPE_WALK and MOVETYPE_NOCLIP.

cs1.7 11-19-2008 03:42

Re: Question about noclip
 
Quote:

Originally Posted by Prajch (Post 671897)
You could set their gravity to 0 and then set their velocity with velocityByAim in their prethink, whenever they're holding IN_FORWARD (and when they aren't, set it to 0).

You'll have to simulate strafing and moving backwards too. Moving backwards would be the same but with a negative velocity. For strafing, it's a little more complicated. You'll have to use angle_vector ( Float:vector[3], FRU, Float:vReturn[3] ).

The first parameter is an array containing their view angles; you can get it with something like this if you use Fakemeta:

Code:

new Float:viewAngles[3]
 pev(id, pev_v_angle, viewAngles)

FRU (stands for forward right up I'm guessing) is one of three values: ANGLEVECTOR_FORWARD (or 1), ANGLEVECTOR_RIGHT (or 2) and ANGLEVECTOR_UP (or 3). Then you create another array and use it as the third parameter; it'll store the components of a unit vector pointing in whatever direction you chose (a unit vector is a directed line with a length of 1).

So for example, if you want to simulate a left strafe movement, you check if the player is holding IN_MOVELEFT, then you use ANGLEVECTOR_RIGHT as your "FRU" value and get a vector pointing in that direction. Then you can set their velocity in the left direction by doing something like this:

Code:

angleVector[0] = -angleVector[0] * desiredVelocity
angleVector[1] = -angleVector[1] * desiredVelocity
angleVector[2] = -angleVector[2] * desiredVelocity
set_pev(id, pev_velocity, angleVector)

You set it as negative because left is the opposite direction of right, and you have to multiply each component by some number, otherwise it'll set their velocity to 1 in that direction (since it's a unit vector).



omg Prajch

that was a Genius idea!
Mind posting the full code?
i'm going to try to code it right now myself but it will take years for me, especially with the angle_vector part.

IN_LEFT
and IN_RIGHT has to be simulated, too.


Many many +karmas for this code, i promise.


All times are GMT -4. The time now is 05:38.

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