Senior Member
Join Date: Apr 2017
Location: Portugal
|
09-29-2019
, 19:39
Re: How to create circle
|
#14
|
Quote:
Originally Posted by Natsheh
i have been able to create a circle only in around the Z axis
here's the code
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <amxmisc> #include <engine> #include <fakemeta> #include <xs>
#define PLUGIN "Health circle" #define VERSION "1.0" #define AUTHOR "Natsheh"
new g_sprite;
#define X 0 #define Y 1 #define Z 2
public plugin_precache() g_sprite = precache_model("sprites/laserbeam.spr");
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_clcmd("amx_health_circle", "handler_command", ADMIN_KICK, "<rad> <width> <rotate axis x> <rotate axis y>"); register_clcmd("amx_delete_health_circle", "handler_command2", ADMIN_KICK, "remove health circle nearby!"); register_think("health_circle", "brain_work"); }
public handler_command2(id, level, cid) { if(!cmd_access(id, level, cid, 1)) return 1; new ent = -1, target_circle = 0, Float:wanted_distance = 250.0, Float:fOrigin[3], Float:fOrigin2[3], Float:z; pev(id, pev_origin, fOrigin); while( (ent = find_ent_by_class(ent, "health_circle")) > 0 ) { pev(ent, pev_origin, fOrigin2); if( (z=get_distance_f(fOrigin, fOrigin2)) <= wanted_distance ) { target_circle = ent; wanted_distance = z; } } if(target_circle > 0) { set_entity_flags(target_circle, FL_KILLME, true); console_print(id, "The health circle nearby was removed!"); } else { console_print(id, "No health circles were found!"); } return 1; }
public handler_command(id, level, cid) { if(!cmd_access(id, level, cid, 2)) return 1; new szRadius[5], szWidth[5], szAngle_X[5], szAngle_Y[5]; read_argv(1, szRadius, charsmax(szRadius)); read_argv(2, szWidth, charsmax(szWidth)); read_argv(3, szAngle_X, charsmax(szAngle_X)); read_argv(4, szAngle_Y, charsmax(szAngle_Y)); remove_quotes(szRadius); remove_quotes(szWidth); remove_quotes(szAngle_X); remove_quotes(szAngle_Y); new ent = create_entity("info_target"); if(ent > 0) { entity_set_string(ent, EV_SZ_classname, "health_circle"); new Float:fAngles[3]; entity_get_vector(id, EV_VEC_origin, fAngles); entity_set_origin(ent, fAngles); entity_set_int(ent, EV_INT_iuser4, str_to_num(szWidth)); entity_set_float(ent, EV_FL_fuser4, floatstr(szRadius)); fAngles[0] = floatstr(szAngle_X); fAngles[1] = floatstr(szAngle_Y); entity_set_vector(ent, EV_VEC_angles, fAngles); entity_set_int(ent, EV_INT_fixangle, true); entity_set_int(ent, EV_INT_solid, SOLID_TRIGGER); entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.1); console_print(id, "Health circle has been created!"); } else { console_print(id, "Failed to create the health circle!"); } return 1; }
public brain_work(id) { static Float:fAngles[3], Float:fRadius[3], Float:fOrigin[3], Float:fWidth, Float:fPos[3], i; pev(id, pev_angles, fAngles); pev(id, pev_origin, fOrigin) fWidth = float(pev(id, pev_iuser4)); pev(id, pev_fuser4, fRadius[X]); fRadius[Y] = fRadius[Z] = 0.0; fPos[X] = floatcos(fAngles[X],degrees) * floatcos(fAngles[Y],degrees) * fRadius[X] - floatsin(fAngles[Y],degrees) * fRadius[Y] + floatcos(fAngles[Y],degrees) * floatsin(fAngles[X],degrees) * fRadius[Z]; fPos[Y] = floatsin(fAngles[Y],degrees) * floatcos(fAngles[X],degrees) * fRadius[X] + floatcos(fAngles[Y],degrees) * fRadius[Y] + floatsin(fAngles[Y],degrees) * floatsin(fAngles[X],degrees) * fRadius[Z]; fPos[Z] = -floatsin(fAngles[X],degrees) * fRadius[X] + floatcos(fAngles[Y],degrees) * fRadius[Z]; xs_vec_add(fPos, fOrigin, fPos); createline(fOrigin, fPos, 255, 0, 0) const Float:fDivides = 30.0; static Float:fTemp[3], Float:fAngle[3], Float:fVector[3] = { 0.0, 0.0, 0.0 }, Float:fStart[3]; xs_vec_copy(fAngles, fAngle); fAngle[Y] += 90.0; for(i = 0; i <= floatround(360.0/fDivides); i++) { if(i > 0) { xs_vec_copy(fVector, fStart); } fAngle[X] += fDivides; fTemp[X] = floatcos(fAngle[X],degrees) * floatcos(fAngle[Y],degrees) * fRadius[X] - floatsin(fAngle[Y],degrees) * fRadius[Y] + floatcos(fAngle[Y],degrees) * floatsin(fAngle[X],degrees) * fRadius[Z]; fTemp[Y] = floatsin(fAngle[Y],degrees) * floatcos(fAngle[X],degrees) * fRadius[X] + floatcos(fAngle[Y],degrees) * fRadius[Y] + floatsin(fAngle[Y],degrees) * floatsin(fAngle[X],degrees) * fRadius[Z]; fTemp[Z] = -floatsin(fAngle[X],degrees) * fRadius[X] + floatcos(fAngle[Y],degrees) * fRadius[Z]; xs_vec_add(fOrigin, fTemp, fVector); if(i > 0) { createline(fStart, fVector) } } entity_set_float(id, EV_FL_nextthink, get_gametime() + 1.0); }
createline(Float:fStart[3], Float:fOrigin[3], r=0, g=255, b=0) { message_begin(MSG_ALL, SVC_TEMPENTITY) write_byte(0) write_coord(floatround(fStart[0])) write_coord(floatround(fStart[1])) write_coord(floatround(fStart[2])) write_coord(floatround(fOrigin[0])) write_coord(floatround(fOrigin[1])) write_coord(floatround(fOrigin[2])) write_short(g_sprite) write_byte(0) write_byte(0) write_byte(10) write_byte(15) write_byte(0) write_byte(r) write_byte(g) write_byte(b) write_byte(255) write_byte(0) message_end() }
now i need to be able to rotate the circle also around Y/X direction
|
wow now that's more confusing than before xd this is really difficult tho.
This can still be applied (I guess so):
On plugin_init:
PHP Code:
register_clcmd("inside_circle", "inside_circle", ADMIN_KICK);
Checking if the player is inside the circle:
PHP Code:
public inside_circle(id, level, cid) { if(!cmd_access(id, level, cid, 1)) return 1;
new ent = -1, target_circle = 0, Float:Circle_Origin[3], Float:Player_Origin[3], Float:wanted_distance = 250.0, Float:z; pev(id, pev_origin, Player_Origin);
while( (ent = find_ent_by_class(ent, "health_circle")) > 0 ) { pev(ent, pev_origin, Circle_Origin); if( (z=get_distance_f(Player_Origin, Circle_Origin)) <= wanted_distance ) { target_circle = ent; wanted_distance = z; } }
if(target_circle > 0) { new Float:Radius[3]; pev(target_circle, pev_fuser4, Radius[X]); if( (floatsqroot(get_distance_f(Player_Origin, Circle_Origin))) < floatsqroot(Radius[X]) ) { console_print(id, "Player is inside circle"); } else { console_print(id, "Player is not inside circle"); } } else { console_print(id, "No health circles were found"); } return 1; }
Although this code searchs if the player is inside the circle, sadly it will search in a sphere. So, that is a beginning. The rest I think you can manage to do it (I hope so).
Edit: I think I know how to check it only in a circle but that would require to the circles have a rotation of 0° (or 180°) or 90° (or 270°).
After "if( (floatsqroot(get_distance_f(Player_Origin, Circle_Origin))) < floatsqroot(Radius[X]) )" we can add something like this:
PHP Code:
if( Player_Origin[Y] == Circle_Origin[Y] ) // only if the circle has a Y rotation of 0° or 180°
or...
PHP Code:
if( Player_Origin[X] == Circle_Origin[X] ) // only if the circle has a Y rotation of 90° or 270°
For the current rotations, in theory that should work.
Last edited by Smilex_Gamer; 09-30-2019 at 02:14.
|
|