Parachute plugins combine

Coding Help/Re-API Supported
Post Reply
User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

Parachute plugins combine

#1

Post by ArminC » 6 years ago

HI! I got 2 plugins, one is an older parachute plugin but good, with models and another one newer with reapi, and it says that's more eficient but it don't have that parachute models. So can you add the reapi code to the older parachute plugin? Thanks! (I don't wana mess the plugin because it has the parachute opening, closing.... and I don't know where to copy+paste the pice of that code)

Base Parachute Plugin (older):

Code: Select all

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

#define _PLUGIN           "Parachute"
#define _VERSION          "1.0"
#define _AUTHOR           "H.RED.ZONE"

#define PARACHUTE_MODEL   "models/arminc/parachute.mdl"

#define MAX_PLAYERS    32

#define MarkUserHasParachute(%0)	g_bitHasParachute |= (1<<(%0&31))
#define ClearUserHasParachute(%0)	g_bitHasParachute &= ~(1<<(%0&31))
#define HasUserParachute(%0)		g_bitHasParachute & (1<<(%0&31))

new g_bitHasParachute 

new g_iUserParachute[MAX_PLAYERS+1]

new Float:g_flEntityFrame[MAX_PLAYERS+1]

new g_iModelIndex
new g_pCvarFallSpeed

new const PARACHUTE_CLASS[] = "parachute"

enum {
	deploy,
	idle,
	detach
}

public plugin_init() {
	register_plugin(_PLUGIN, _VERSION, _AUTHOR)

	g_pCvarFallSpeed = register_cvar("parachute_fallspeed", "30")

	register_forward(FM_CmdStart, "fw_Start")
	
	RegisterHam(Ham_Spawn, "player", "Ham_CBasePlayer_Spawn_Post", 1)
	RegisterHam(Ham_Killed, "player", "Ham_CBasePlayer_Killed_Post", 1)
}

public plugin_precache() {
	g_iModelIndex = precache_model(PARACHUTE_MODEL)
}

public client_putinserver(id) {
	if(HasUserParachute(id)) {
		new iEnt = g_iUserParachute[id]
		if(iEnt) {
			RemoveUserParachute(id, iEnt)
		}
		ClearUserHasParachute(id)
	}
}

public client_disconnected(id) {
	if(HasUserParachute(id)) {
		new iEnt = g_iUserParachute[id]
		if(iEnt) {
			RemoveUserParachute(id, iEnt)
		}
		ClearUserHasParachute(id)
	}
}

public Ham_CBasePlayer_Killed_Post(id) {
	if(HasUserParachute(id)) {
		new iEnt = g_iUserParachute[id]
		if(iEnt) {
			RemoveUserParachute(id, iEnt)
		}
		ClearUserHasParachute(id)
	}
}

public Ham_CBasePlayer_Spawn_Post(id) {
	if(is_user_alive(id)) {
		if(HasUserParachute(id)) {
			new iEnt = g_iUserParachute[id]
			if(iEnt) {
				RemoveUserParachute(id, iEnt)
			}
		}
		MarkUserHasParachute(id)
	}
}

RemoveUserParachute(id, iEnt) {
	engfunc(EngFunc_RemoveEntity, iEnt)
	g_iUserParachute[id] = 0
}

CreateParachute(id) {
	static iszInfoTarget
	if(!iszInfoTarget) {
		iszInfoTarget = engfunc(EngFunc_AllocString, "info_target")
	}

	new iEnt = engfunc(EngFunc_CreateNamedEntity, iszInfoTarget)
	if(iEnt > 0) {
		static iszClass = 0
		if(!iszClass) {
			iszClass = engfunc(EngFunc_AllocString, PARACHUTE_CLASS)
		}
		set_pev_string(iEnt, pev_classname, iszClass)
		set_pev(iEnt, pev_aiment, id)
		set_pev(iEnt, pev_owner, id)
		set_pev(iEnt, pev_movetype, MOVETYPE_FOLLOW)

		static iszModel = 0
		if(!iszModel) {
			iszModel = engfunc(EngFunc_AllocString, PARACHUTE_MODEL)
		}
		set_pev_string(iEnt, pev_model, iszModel)
		set_pev(iEnt, pev_modelindex, g_iModelIndex)

		set_pev(iEnt, pev_sequence, deploy)
		set_pev(iEnt, pev_gaitsequence, 1)
		set_pev(iEnt, pev_frame, 0.0)
		g_flEntityFrame[id] = 0.0
		g_iUserParachute[id] = iEnt
		MarkUserHasParachute(id)
		new Float:fVecOrigin[3]
		pev(id, pev_origin, fVecOrigin)
		
		return iEnt
	}
	return 0
}

public fw_Start(id) {
	if(~HasUserParachute(id) || !is_user_alive(id)) {
		return
	}

	new Float:flFrame
	new iEnt = g_iUserParachute[id]

	if(iEnt > 0 && pev(id, pev_flags) & FL_ONGROUND) {

		if(pev(iEnt, pev_sequence) != detach) {
			set_pev(iEnt, pev_sequence, detach)
			set_pev(iEnt, pev_gaitsequence, 1)
			set_pev(iEnt, pev_frame, 0.0)
			g_flEntityFrame[id] = 0.0
			set_pev(iEnt, pev_animtime, 0.0)
			set_pev(iEnt, pev_framerate, 0.0)
			return
		}

		pev(iEnt, pev_frame, flFrame)
		if(flFrame > 252.0) {
			RemoveUserParachute(id, iEnt)
			return
		}

		flFrame += 2.0

		g_flEntityFrame[id] = flFrame
		set_pev(iEnt, pev_frame, flFrame)

		return
	}

	if(pev(id, pev_button) & IN_USE) {
		new Float:fVecVelocity[3], Float:fVelocity_z
		pev(id, pev_velocity, fVecVelocity)
		fVelocity_z = fVecVelocity[2]

		if(fVelocity_z < 0.0) {
			if(iEnt <= 0) {
				iEnt = CreateParachute(id)
			}

			fVelocity_z = floatmin(fVelocity_z + 15.0, -get_pcvar_float(g_pCvarFallSpeed))
			fVecVelocity[2] = fVelocity_z
			set_pev(id, pev_velocity, fVecVelocity)

			if(pev(iEnt, pev_sequence) == deploy) {
				flFrame = g_flEntityFrame[id]++

				if(flFrame > 100.0) {
					set_pev(iEnt, pev_animtime, 0.0)
					set_pev(iEnt, pev_framerate, 0.4)
					set_pev(iEnt, pev_sequence, idle)
					set_pev(iEnt, pev_gaitsequence, 1)
					set_pev(iEnt, pev_frame, 0.0)
					g_flEntityFrame[id] = 0.0
				}
				else {
					set_pev(iEnt, pev_frame, flFrame)
				}
			}
		}
		else if(iEnt > 0) {
			RemoveUserParachute(id, iEnt)
		}
	}
	else if(iEnt > 0 && pev(id, pev_oldbuttons) & IN_USE) {
		RemoveUserParachute(id, iEnt)
	}
}
and the ReAPI Parachute (1)

Code: Select all

#include <zombie_escape>

// Variables
new bool:g_bGiveParachute[33];

// Cvars
new cvar_fall_speed, cvar_give_all;

public plugin_init()
{
	register_plugin("[ReAPI/ZE] Parachute", "1.1", "ReHLDS Team/Raheem");
	RegisterHookChain(RG_PM_AirMove, "PM_AirMove", false);
	
	// Cvars
	cvar_fall_speed = register_cvar("ze_fall_speed", "90");
	cvar_give_all = register_cvar("ze_give_all_parachute", "1");
}

public plugin_natives()
{
	register_native("ze_give_user_parachute", "native_ze_give_user_parachute", 1)
	register_native("ze_remove_user_parachute", "native_ze_remove_user_parachute", 1)
}

public PM_AirMove(const playerIndex)
{
	if (get_pcvar_num(cvar_give_all) == 1 || g_bGiveParachute[playerIndex])
	{
		if (!(get_entvar(playerIndex, var_button) & IN_USE)
		|| get_entvar(playerIndex, var_waterlevel) > 0) {
			return;
		}
		new Float:flVelocity[3];
		get_entvar(playerIndex, var_velocity, flVelocity);
		if (flVelocity[2] < 0.0)
		{
			flVelocity[2] = (flVelocity[2] + 40.0 < -100.0) ? flVelocity[2] + 40.0 : -get_pcvar_float(cvar_fall_speed);
			set_entvar(playerIndex, var_sequence, ACT_WALK);
			set_entvar(playerIndex, var_gaitsequence, ACT_IDLE);
			set_pmove(pm_velocity, flVelocity);
			set_movevar(mv_gravity, 80.0);
		}
	}
}

public native_ze_give_user_parachute(id)
{
	g_bGiveParachute[id] = true
}

public native_ze_remove_user_parachute(id)
{
	g_bGiveParachute[id] = false
}
or ReAPI (2)

Code: Select all

#include <amxmodx>
#include <reapi>
#include <engine>

new pFallSpeed = 100

new bool:g_is_alive[33]

public plugin_init()
{
	register_plugin("Parachute for ALL [ReAPI]", "3.0", "Leo_[BH]")

	RegisterHookChain(RG_CBasePlayer_PreThink, "RG_client_PreThink");
	
	RegisterHookChain(RG_CBasePlayer_Killed, "RG_Player_Killed", 0);
	RegisterHookChain(RG_CBasePlayer_Spawn, "RG_Spawn_Post", 1);
}

public RG_client_PreThink(id)
{
	if(!g_is_alive[id]) return;

	new Float:fallspeed = pFallSpeed * -1.0

	new button = get_entvar(id, EntVars:var_button); // get_user_button(id)
	new oldbutton = get_entvar(id, EntVars:var_oldbuttons); // get_user_oldbutton(id)

	if (get_entvar(id, EntVars:var_gravity) == 0.1) set_entvar(id, EntVars:var_gravity, 1.0)

	if (button & IN_USE) 
	{
		new Float:velocity[3]
		entity_get_vector(id, EV_VEC_velocity, velocity)

		if (velocity[2] < 0.0) 
		{
			set_entvar(id, EntVars:var_gravity, 0.1)

			velocity[2] = (velocity[2] + 40.0 < fallspeed) ? velocity[2] + 40.0 : fallspeed
			entity_set_vector(id, EV_VEC_velocity, velocity)
		}
	}
	else if ((oldbutton & IN_USE)) 
	{
		set_entvar(id, EntVars:var_gravity, 1.0)
	}
}

public RG_Spawn_Post(id)
{
	if(is_user_alive(id))
	{
		g_is_alive[id] = true
	}
}
public RG_Player_Killed(victim, attacker)
{
	g_is_alive[victim] = false
}
public client_disconnected(id)
{
	g_is_alive[id] = false
}

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: Bing [Bot] and 1 guest