Raised This Month: $51 Target: $400
 12% 

[HELP] CSO All Star Kart Rider


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devilsquare
Junior Member
Join Date: Sep 2013
Old 11-25-2019 , 17:05   [HELP] CSO All Star Kart Rider
Reply With Quote #1

Hi guys! I need help with Lie Flat because it's not working

OBS: I want to climb the ramps correctly!

Requirements

AMX Mod X v1.9 or higher

Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <engine>
#include <xs>

#define PLUGIN_NAME "[CSO] Kart Rider"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "CSO LTDA"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define is_user_valid_connected(%0) (is_user_valid(%0) && is_user_connected(%0))
#define is_user_valid_alive(%0) (is_user_valid_connected(%0) && is_user_alive(%0))

#define NPC_CLASSNAME "npc_vehicle"
#define NPC_MINS Float:{-13.342067, -14.700000, -17.500000}
#define NPC_MAXS Float:{16.240000, 14.700000, 15.630000}
#define NPC_SPEED 300.0

#define CAM_CLASSNAME "npc_camera"
#define CAM_MINS Float:{-1.0, -1.0, -1.0}
#define CAM_MAXS Float:{1.0, 1.0, 1.0}

enum { ANIM_IDLE1 = 0, ANIM_BOOSTER_IDLE, ANIM_BOOSTER_ON, ANIM_MOVE, ANIM_CHANGEA, ANIM_CHANGEB, ANIM_BACKWARD, MAX_ANIMATION }

new g_Model[][] = { "models/allstar/allstarkartriderct/allstarkartrider_under.mdl", "models/rpgrocket.mdl" }
new g_Sound[MAX_ANIMATION][] = {
	"allstar/allstarkartrider/idle.wav",
	"allstar/allstarkartrider/move.wav",
	"allstar/allstarkartrider/move_end.wav",
	"allstar/allstarkartrider/move_slow.wav",
	"allstar/allstarkartrider/move_slow_end.wav",
	"allstar/allstarkartrider/move_slow_start.wav",
	"allstar/allstarkartrider/move_start.wav"
}

new g_NPC[MAX_PLAYERS + 1], g_CAM[MAX_PLAYERS + 1]

public plugin_precache() {
	new i
	
	for (i = 0; i < sizeof(g_Model); i++) precache_model(g_Model[i]);
	for (i = 0; i < sizeof(g_Sound); i++) precache_sound(g_Sound[i]);
}

public plugin_init() {
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	
	RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
	
	register_forward(FM_Think, "fw_Think")
	//register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", 1)
	
	register_think(CAM_CLASSNAME, "cam_think")
	
	register_clcmd("say /npc", "clcmd_npc")
	register_clcmd("say_team /npc", "clcmd_npc")
}

public fw_PlayerSpawn_Post(id) {
	if (!is_user_valid_alive(id) || !pev_valid(g_NPC[id])) return HAM_IGNORED;
	
	set_pev(id, pev_takedamage, DAMAGE_NO)
	set_pev(id, pev_solid, SOLID_NOT)
	set_pev(id, pev_movetype, MOVETYPE_NOCLIP)
	set_pev(id, pev_rendermode, kRenderTransTexture)
	
	if (is_valid_ent(g_CAM[id])) attach_view(id, g_CAM[id]);
	else create_cam(id);
	
	return HAM_IGNORED
}

public clcmd_npc(id) {
	if (!is_user_valid_alive(id)) return PLUGIN_CONTINUE;
	
	if (!pev_valid(g_NPC[id])) {
		set_pev(id, pev_takedamage, DAMAGE_NO)
		set_pev(id, pev_solid, SOLID_NOT)
		set_pev(id, pev_movetype, MOVETYPE_NOCLIP)
		set_pev(id, pev_rendermode, kRenderTransTexture)
		
		g_NPC[id] = create_npc(id)
		g_CAM[id] = create_cam(id)
	}
	else client_print_color(id, print_team_default, "^4[CSO]^1 Voce ja esta usando o ^3Kart");
	
	return PLUGIN_HANDLED
}

public create_npc(id) {
	new Float:vOrigin[3]; pev(id, pev_origin, vOrigin);
	new Float:vAngles[3]; pev(id, pev_angles, vAngles);
	
	vAngles[0] = 0.0
	
	new iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if (!pev_valid(iEnt)) return 0;
	
	set_pev(iEnt, pev_classname, NPC_CLASSNAME)
	set_pev(iEnt, pev_owner, id)
	
	engfunc(EngFunc_SetModel, iEnt, g_Model[0])
	engfunc(EngFunc_SetSize, iEnt, NPC_MINS, NPC_MAXS)
	
	set_pev(iEnt, pev_origin, vOrigin)
	set_pev(iEnt, pev_angles, vAngles)
	set_pev(iEnt, pev_solid, SOLID_BBOX)
	set_pev(iEnt, pev_movetype, MOVETYPE_PUSHSTEP)
	set_anim(iEnt, ANIM_IDLE1)
	set_pev(iEnt, pev_nextthink, get_gametime())
	
	return iEnt
}

public create_cam(id) {
	new Float:vOrigin[3]; entity_get_vector(id, EV_VEC_origin, vOrigin);
	new Float:vAngles[3]; entity_get_vector(id, EV_VEC_angles, vAngles);
	new Float:vAngle[3]; entity_get_vector(id, EV_VEC_v_angle, vAngle);
	new iEntity = create_entity("info_target")
	
	if (!is_valid_ent(iEntity)) return 0;
	
	entity_set_string(iEntity, EV_SZ_classname, CAM_CLASSNAME)
	entity_set_edict(iEntity, EV_ENT_owner, id)
	entity_set_model(iEntity, g_Model[1])
	entity_set_size(iEntity, CAM_MINS, CAM_MAXS)
	entity_set_origin(iEntity, vOrigin)
	entity_set_vector(iEntity, EV_VEC_angles, vAngles)
	entity_set_vector(iEntity, EV_VEC_v_angle, vAngle)
	entity_set_int(iEntity, EV_INT_rendermode, kRenderTransTexture)
	entity_set_int(iEntity, EV_INT_solid, SOLID_NOT)
	entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NOCLIP)
	entity_set_float(iEntity, EV_FL_nextthink, halflife_time())
	attach_view(id, iEntity)
	
	return iEntity
}

public fw_Think(ent) {
	if (!pev_valid(ent)) return FMRES_IGNORED;
	
	static szClassName[MAX_NAME_LENGTH]; pev(ent, pev_classname, szClassName, charsmax(szClassName));
	
	if (!equali(szClassName, NPC_CLASSNAME)) return FMRES_IGNORED;
	
	new iOwner = pev(ent, pev_owner)
	
	if (!is_user_valid_alive(iOwner)) return FMRES_IGNORED;
	
	new iButton = pev(iOwner, pev_button)
	static Float:vAngles[3]; lie_flat(ent, vAngles);
	
	if (iButton & IN_FORWARD) {
		if (iButton & IN_MOVELEFT) vAngles[1] += 0.4;
		else if (iButton & IN_MOVERIGHT) vAngles[1] -= 0.4;
		
		set_pev(ent, pev_angles, vAngles)
		
		static Float:vAngle[3]; angle_vector(vAngles, ANGLEVECTOR_FORWARD, vAngle);
		
		xs_vec_mul_scalar(vAngle, NPC_SPEED, vAngle)
		
		static Float:vVelocity[3]; pev(ent, pev_velocity, vVelocity);
		
		vAngle[2] = vVelocity[2]
		
		set_pev(ent, pev_velocity, vAngle)
		
		if (pev(ent, pev_movetype) != MOVETYPE_PUSHSTEP) {
			emit_sound(ent, CHAN_BODY, g_Sound[6], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
			set_pev(ent, pev_movetype, MOVETYPE_PUSHSTEP)
		}
		
		set_anim(ent, ANIM_MOVE)
		emit_sound(ent, CHAN_BODY, g_Sound[1], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
	}
	else if (iButton & IN_BACK) {
		if (iButton & IN_MOVELEFT) vAngles[1] -= 0.4;
		else if (iButton & IN_MOVERIGHT) vAngles[1] += 0.4;
		
		set_pev(ent, pev_angles, vAngles)
		
		static Float:vAngle[3]; angle_vector(vAngles, ANGLEVECTOR_FORWARD, vAngle);
		
		xs_vec_mul_scalar(vAngle, -NPC_SPEED, vAngle)
		
		static Float:vVelocity[3]; pev(ent, pev_velocity, vVelocity);
		
		vAngle[2] = vVelocity[2]
		
		set_pev(ent, pev_velocity, vAngle)
		
		if (pev(ent, pev_movetype) != MOVETYPE_PUSHSTEP) {
			emit_sound(ent, CHAN_BODY, g_Sound[5], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
			set_pev(ent, pev_movetype, MOVETYPE_PUSHSTEP)
		}
		
		set_anim(ent, ANIM_BACKWARD)
		emit_sound(ent, CHAN_BODY, g_Sound[3], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
	}
	else {
		set_pev(ent, pev_angles, vAngles)
		set_pev(ent, pev_velocity, Float:{0.0, 0.0, 0.0})
		
		if (pev(ent, pev_movetype) != MOVETYPE_NONE) {
			new iOldButton = pev(iOwner, pev_oldbuttons)
			
			if (iOldButton & IN_FORWARD) emit_sound(ent, CHAN_BODY, g_Sound[2], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
			else if (iOldButton & IN_BACK) emit_sound(ent, CHAN_BODY, g_Sound[4], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
			
			set_pev(ent, pev_movetype, MOVETYPE_NONE)
		}
		
		set_anim(ent, ANIM_IDLE1)
		emit_sound(ent, CHAN_BODY, g_Sound[0], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
	}
	
	set_pev(ent, pev_gravity, 1.0)
	set_pev(ent, pev_nextthink, get_gametime())
	
	return FMRES_IGNORED
}

/*public fw_AddToFullPack_Post(es, e, ent, id) {
	if (!pev_valid(ent) || !is_user_valid_alive(id)) return FMRES_IGNORED;
	
	static szClassName[MAX_NAME_LENGTH]; pev(ent, pev_classname, szClassName, charsmax(szClassName));
	
	if (!equali(szClassName, NPC_CLASSNAME)) return FMRES_IGNORED;
	
	new iOwner = pev(ent, pev_owner)
	
	if (id == iOwner) {
		set_es(es, ES_RenderMode, kRenderTransAlpha)
		set_es(es, ES_RenderAmt, 150)
	}
	
	return FMRES_IGNORED
}*/

public cam_think(entity) {
	if (!is_valid_ent(entity)) return PLUGIN_CONTINUE;
	
	new iOwner = entity_get_edict(entity, EV_ENT_owner)
	
	if (!is_user_valid_alive(iOwner) || !pev_valid(g_NPC[iOwner])) return PLUGIN_CONTINUE;
	
	new iButton = entity_get_int(iOwner, EV_INT_button)
	static Float:vAngle[3], Float:vNewOrigin[3]
	static Float:vOrigin[3]; pev(g_NPC[iOwner], pev_origin, vOrigin);
	
	if (iButton & IN_FORWARD) pev(g_NPC[iOwner], pev_angles, vAngle);
	else entity_get_vector(iOwner, EV_VEC_v_angle, vAngle);
	
	for (new Float:i = 100.0; i >= 0.0; i -= 0.1) {
		vNewOrigin[0] = floatcos(vAngle[1], degrees) * -i
		vNewOrigin[1] = floatsin(vAngle[1], degrees) * -i
		vNewOrigin[2] = i - (i / 4)
		vNewOrigin[0] += vOrigin[0]
		vNewOrigin[1] += vOrigin[1]
		vNewOrigin[2] += vOrigin[2]
		
		if (PointContents(vNewOrigin) != CONTENTS_SOLID && PointContents(vNewOrigin) != CONTENTS_SKY) break;
	}
	
	vAngle[0] = 20.0
	
	entity_set_origin(entity, vNewOrigin)
	entity_set_vector(entity, EV_VEC_angles, vAngle)
	entity_set_vector(entity, EV_VEC_v_angle, vAngle)
	entity_set_float(entity, EV_FL_nextthink, halflife_time())
	
	return PLUGIN_CONTINUE
}

public client_disconnected(id) {
	if (is_valid_ent(g_CAM[id])) {
		remove_entity(g_CAM[id])
		g_CAM[id] = 0
	}
	if (pev_valid(g_NPC[id])) {
		engfunc(EngFunc_RemoveEntity, g_NPC[id])
		g_NPC[id] = 0
	}
}

stock set_anim(ent, sequence, Float:framerate = 1.0) {
	set_pev(ent, pev_frame, 0.0)
	set_pev(ent, pev_framerate, framerate)
	set_pev(ent, pev_sequence, sequence)
	set_pev(ent, pev_animtime, get_gametime())
}

stock lie_flat(ent, Float:angles[3]) { // by Nomexous
	if (pev(ent, pev_flags) & ~FL_ONGROUND) return false;
	
	pev(ent, pev_angles, angles)
	
	angles[0] = 0.0
	angles[2] = 0.0
	
	static Float:vOrigin[3]; pev(ent, pev_origin, vOrigin);
	static Float:vVector[3]; xs_vec_sub(vOrigin, Float:{0.0, 0.0, 10.0}, vVector);
	
	engfunc(EngFunc_TraceLine, vOrigin, vVector, IGNORE_MONSTERS, ent, 0)
	
	static Float:fFraction; get_tr2(0, TR_flFraction, fFraction);
	
	if (fFraction == 1.0) return false;
	
	static Float:vAngle[3]; angle_vector(angles, ANGLEVECTOR_FORWARD, vAngle);
	static Float:vPlaneNormal[3]; get_tr2(0, TR_vecPlaneNormal, vPlaneNormal);
	
	if (vPlaneNormal[2] == 1.0) return false;
	
	static Float:vRight[3]; xs_vec_cross(vAngle, vPlaneNormal, vRight);
	static Float:vForward[3]; xs_vec_cross(vPlaneNormal, vRight, vForward);
	
	vector_to_angle(vForward, angles)
	
	static Float:vAngles[3]; vector_to_angle(vRight, vAngles);
	
	angles[2] = -1.0 * vAngles[0]
	
	return true
}
RESOURCE HERE

Thanks in advance!
__________________
By Eclipse*

Last edited by devilsquare; 11-25-2019 at 17:17.
devilsquare is offline
Reply



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 11:42.


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