Raised This Month: $ Target: $400
 0% 

SH icemanv2 error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
12114
Senior Member
Join Date: Jan 2006
Old 10-29-2012 , 16:45   SH icemanv2 error
Reply With Quote #1

Hi all, this http://forums.alliedmods.net/showthread.php?t=31766 superhero plugin keeps spamming up my server with errors:
[AMXX] Run time error 11: divide

this is the line that does it (line 185):
Code:
aimvec[0]=user_origin[0]+(unitsinfront*distance2[0])/sqrt(distance2[0]*distance2[0]+distance2[1]*distance2[1])
the whole .sma
Code:
// Ice Man - Based from Iron Man, with modifications by me, Kojiro.

/* CVARS - copy and paste to shconfig.cfg

//Ice Man
iceman2_level 0
iceman2_timer 0.1			//How often (seconds) to run the loop
iceman2_maxspeed 425		//Max Speed
iceman2_armorfuel 1			//Uses armor as fuel
iceman2_fuelcost 4			//How much armor does it cost per firing
iceman2_armor 100			//How much armor does ironman start with?

*/

#include <amxmod>
#include <Vexd_Utilities>
#include <amxmodx> 
#include <fun> 
#include <cstrike>
#include <engine> 
#include <superheromod> 

// GLOBAL VARIABLES
new gHeroName[]="Ice Man"
new bool:g_hasIceManPower[SH_MAXSLOTS+1]
new g_jetPackRunning[SH_MAXSLOTS+1]
new g_endLocation[SH_MAXSLOTS+1][3]
new g_spriteFire
new ice[32]

// BECAUSE THIS LOOP IS CALLED SO MUCH - INSTEAD OF READING CVARS OVER AND OVER
// I'LL KEEP IN GLOBAL - FOR ANTI-LAG HOPEFULLY
new Float:gMaxSpeed, gUseFuel, gFuelCost, gIceManArmor
new g_szRocketModel[1][] = { "sprites/bubble.spr" }
new g_Sound[]="roach/rch_smash.wav"
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO IceManv2","1.0","Kojiro")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("iceman2_level", "0" )
	register_cvar("iceman2_timer", "0.1" )
	register_cvar("iceman2_maxspeed", "450" )
	register_cvar("iceman2_armorfuel", "1" )
	register_cvar("iceman2_fuelcost","2")
	register_cvar("iceman2_armor","100")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Ice Man", "Ice Trail - Create a trail of ice to go wherever you want.", true, "iceman2_level" )

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	register_event("ResetHUD","newRound","b") 

	// KEY UP
	register_srvcmd("iceman2_ku",   "iceman2_ku")
	shRegKeyUp(gHeroName, "iceman2_ku")

	// KEY DOWN
	register_srvcmd("iceman2_kd", "iceman2_kd")
	shRegKeyDown(gHeroName, "iceman2_kd")

	// DEATH
	register_event("DeathMsg", "iceman2_death", "a")

	// INIT
	register_srvcmd("iceman2_init", "iceman2_init")
	shRegHeroInit(gHeroName, "iceman2_init")

	//Waits 4 seconds then loads cvars into variables
	set_task(4.0,"loadCVARS")
	
	//Let MOD know about his max armor
	shSetMaxArmor(gHeroName, "iceman2_armor" )

}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
	g_spriteFire = precache_model("sprites/laserbeam.spr")
	precache_sound(g_Sound)
	for( new i = 0; i < 1; i++ )
		precache_model( g_szRocketModel[i] )
}
//----------------------------------------------------------------------------------------------
public loadCVARS()
{
	gMaxSpeed = get_cvar_float("iceman2_maxspeed")
	gUseFuel = get_cvar_num("iceman2_armorfuel")
	gFuelCost = get_cvar_num("iceman2_fuelcost")
	gIceManArmor = get_cvar_num("iceman2_armor")
}
//----------------------------------------------------------------------------------------------
public jetPackFireEffect(origin[3])
{
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(11)
	write_coord(origin[0])
	write_coord(origin[1])
	write_coord(origin[2]-34)
	message_end()
}
//----------------------------------------------------------------------------------------------
public iceman2_init()
{
	// First Argument is an id
	new temp[6]
	read_argv(1,temp,5)
	new id=str_to_num(temp)

	// 2nd Argument is 0 or 1 depending on whether the id has ice man powers
	read_argv(2,temp,5)
	new hasPowers=str_to_num(temp)

	g_hasIceManPower[id] = (hasPowers!=0)

	if ( g_hasIceManPower[id] ) {
		remove_task(id+36485)
		set_task( get_cvar_float("iceman2_timer"), "iceman2_loop", id+36485, "", 0, "b")
	}
	else {
		shRemArmorPower(id)
		remove_task(id+36485)
	}
}
//----------------------------------------------------------------------------------------------
public iceman2_loop(id)
{
	id -= 36485
	new Float:velocity[3]
	new origin[3], userArmor
	new user_origin[3]
	new aimvec[3]
	new Float:b_orig[3] 

	if ( !is_user_alive(id) ) return PLUGIN_HANDLED

	// Increase armor for this guy
	userArmor = get_user_armor(id)
	if ( userArmor < gIceManArmor && g_jetPackRunning[id] == 0 ) {
		set_user_armor(id, userArmor + 1 )
		return PLUGIN_HANDLED
	}

	// OK - We'll make this armor based - but also add armor
	// So you can run out of fuel, but get it back too
	if ( gUseFuel != 0 && gFuelCost > userArmor && g_jetPackRunning[id] == 1 ) {
		playSoundDenySelect(id)
		g_jetPackRunning[id] = 0
		set_user_info(id,"JETPACK_RUN","0")
		client_print(id, print_center, "You ran out of energy.")
		removeMark(id)
		return PLUGIN_HANDLED
	}
	get_user_origin(id, g_endLocation[id],3)
	if (g_jetPackRunning[id] == 1) {

		// Decrement Fuel
		if ( gUseFuel != 0 ) {
			set_user_armor(id, userArmor - gFuelCost )
			emit_sound(id,CHAN_STATIC, g_Sound, 0.1, ATTN_NORM, 0, PITCH_LOW)
		}

		get_user_origin(id, user_origin)

		Entvars_Get_Vector(id, EV_VEC_velocity, velocity)

		new distance
		distance = get_distance( g_endLocation[id], user_origin )
		velocity[0] = (g_endLocation[id][0] - user_origin[0]) * ( 1.0 * gMaxSpeed / distance)
		velocity[1] = (g_endLocation[id][1] - user_origin[1]) * ( 1.0 * gMaxSpeed / distance)
		velocity[2] = (g_endLocation[id][2] - user_origin[2]) * ( 1.0 * gMaxSpeed / distance)

		Entvars_Set_Vector(id, EV_VEC_velocity, velocity)

  		new distance2[2] 

		distance2[0] = g_endLocation[id][0]-user_origin[0] 
		distance2[1] = g_endLocation[id][1]-user_origin[1] 
   
		new unitsinfront = 1

		aimvec[0]=user_origin[0]+(unitsinfront*distance2[0])/sqrt(distance2[0]*distance2[0]+distance2[1]*distance2[1]) 
		aimvec[1]=user_origin[1]+(unitsinfront*distance2[1])/sqrt(distance2[0]*distance2[0]+distance2[1]*distance2[1]) 
		aimvec[2]=user_origin[2]-34
		
		b_orig[0] = float(aimvec[0]); 
		b_orig[1] = float(aimvec[1]); 
		b_orig[2] = float(aimvec[2]); 
		
		ENT_SetOrigin(ice[id], b_orig)


		get_user_origin(id, origin, 1)
		jetPackFireEffect(origin)
	}
	return PLUGIN_CONTINUE
}
//----------------------------------------------------------------------------------------------
// RESPOND TO KEYDOWN
public iceman2_kd()
{

	// First Argument is an id with Iceman Powers!
	new temp[6]
	read_argv(1,temp,5)
	new id=str_to_num(temp)

	if ( !hasRoundStarted() || !is_user_alive(id))
	{
		playSoundDenySelect(id)
		g_jetPackRunning[id] = 0
		set_user_info(id,"JETPACK_RUN","0")
		return PLUGIN_HANDLED 
	}
	g_jetPackRunning[id] = 1
	set_user_info(id,"JETPACK_RUN","1")

	//Reload CVARS to make sure the variables are current
	loadCVARS()
	do_this(id)
	return PLUGIN_HANDLED 
}
//----------------------------------------------------------------------------------------------
public iceman2_death()
{
	new id = read_data(2)

	if ( id < 0 || id > SH_MAXSLOTS ) return

	g_jetPackRunning[id] = 0
	set_user_info(id,"JETPACK_RUN","0")
	removeMark(id)
	
}
//----------------------------------------------------------------------------------------------
// RESPOND TO KEYUP
public iceman2_ku()
{
	// First Argument is an id with Ironman Powers!
	new temp[6]
	read_argv(1,temp,5)
	new id = str_to_num(temp)
	
	if (g_jetPackRunning[id] != 1) return

	g_jetPackRunning[id] = 0
	set_user_info(id,"JETPACK_RUN","0")
	
	removeMark(id)
}
//----------------------------------------------------------------------------------------------
public client_disconnect(id)
{
	// stupid check but lets see
	if ( id <=0 || id > SH_MAXSLOTS ) return

	g_jetPackRunning[id] = 0
	set_user_info(id,"JETPACK_RUN","0")

	// Yeah don't want any left over residuals
	removeMark(id)
	remove_task(id+36485)
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
	// stupid check but lets see
	if ( id <=0 || id > SH_MAXSLOTS ) return

	g_jetPackRunning[id] = 0
	set_user_info(id,"JETPACK_RUN","0")

	// Yeah don't want any left over residuals
	removeMark(id)
	remove_task(id+36485)
}
//----------------------------------------------------------------------------------------------
public removeMark(id)
{
	if( ice[id] ) {
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY, {0,0,0}, ice[id])
		write_byte(99)
		write_short(ice[id])
		message_end()
		
		remove_entity(ice[id])
		ice[id] = 0
		
		set_user_rendering(id)
   }
	return PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
public make_trail(id,origin2[3])
{
	//Spawning ice below player    
  	new Float: Origin[3]
  	new Float: vAngle[3]
  	new Float: Velocity[3]
  	
	remove_entity(ice[id])

	Entvars_Get_Vector(id, EV_VEC_origin , Origin)
	Entvars_Get_Vector(id, EV_VEC_v_angle, vAngle)
     
	ice[id] = create_entity("info_target")
	
	entity_set_string(ice[id], EV_SZ_classname, "ice_sheet") 

	ENT_SetModel(ice[id], g_szRocketModel[0])

	new Float:MinBox[3] 
	new Float:MaxBox[3] 
	MinBox[0] = -1.0 
	MinBox[1] = -1.0 
	MinBox[2] = -1.0 
	MaxBox[0] = 1.0 
	MaxBox[1] = 1.0 
	MaxBox[2] = 1.0 
	Entvars_Set_Vector(ice[id], EV_VEC_mins, MinBox) 
	Entvars_Set_Vector(ice[id], EV_VEC_maxs, MaxBox)
   
	ENT_SetOrigin(ice[id], Origin)
	Entvars_Set_Vector(ice[id], EV_VEC_angles, vAngle)

	entity_set_int(ice[id], EV_INT_solid, 0) 
	entity_set_int(ice[id], EV_INT_movetype, 5)
	Entvars_Set_Edict(ice[id], EV_ENT_owner, id)
   
	VelocityByAim(id, 0 , Velocity)
	Entvars_Set_Vector(ice[id], EV_VEC_velocity ,Velocity)
   
	if ( !is_user_alive(id) ) return PLUGIN_HANDLED
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
	write_byte(22) 
	write_short(ice[id]) 
	write_short(g_spriteFire) 
	write_byte(35) 
	write_byte(25) 
	write_byte(100) 
	write_byte(100) 
	write_byte(250) 
	write_byte(3000) 
	message_end()

	set_user_rendering(id,kRenderFxGlowShell,50,50,250, kRenderNormal, 16)
	
	return PLUGIN_CONTINUE
}
//-----------------------------------------------------------------------------------------------
public do_this(id)
{
	new user_origin[3]
	new origin2[3]
	
	get_user_origin(id, origin2, 1)
	make_trail(id,origin2)
	get_user_origin(id, user_origin)
	get_user_origin(id, g_endLocation[id], 3)
}
//---------------------------------------------------------------------------------------------- 
public newRound(id)
{

  if (!g_hasIceManPower[id]) return PLUGIN_CONTINUE

  if (ice[id]) 
  {
		remove_entity(ice[id])
		ice[id] = 0
		g_jetPackRunning[id] = 0
		set_user_info(id,"JETPACK_RUN","0")
		set_user_rendering(id)
  }
  return PLUGIN_CONTINUE
}
//----------------------------------------------------------------------------------------------
any ideas? thanks

Last edited by 12114; 10-29-2012 at 18:33.
12114 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 17:18.


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