Raised This Month: $ Target: $400
 0% 

How to create circle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Smilex_Gamer
Senior Member
Join Date: Apr 2017
Location: Portugal
Old 09-30-2019 , 12:01   Re: How to create circle
Reply With Quote #1

Okay, checking if the player is inside the circle is done (at least, it's more accurate now).
Later I'll try make the circle be in the XY plane.

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
#define GAP 2 // this is for checking if the player is inside the circle. Because the maxs and mins are the sprites themselves, this gap is for decreasing the area where the player is inside the circle (eg. if the circle is in the XZ plane, this will decrease 
#define SPR_LENGHT 2 // sprite lenght. current sprite "laserbeam" is around 2. this lenght is for increasing the area where the player is inside the circle (eg. if the circle is in the XZ plane, this will increase the Y maxs and mins)

new Float:Maxs_Origin[4096][3], Float:Mins_Origin[4096][3];

public 
plugin_precache() g_sprite precache_model("sprites/laserbeam.spr");

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
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");
    
register_clcmd("inside_circle""inside_circle");
}

public 
handler_command2(idlevelcid)
{
    if(!
cmd_access(idlevelcid1)) return 1;
    
    new 
ent = -1target_circle 0Float:wanted_distance 250.0Float:fOrigin[3], Float:fOrigin2[3], Float:z;
    
pev(idpev_originfOrigin);
    while( (
ent find_ent_by_class(ent"health_circle")) > )
    {
        
pev(entpev_originfOrigin2);
        if( (
z=get_distance_f(fOriginfOrigin2)) <= wanted_distance )
        {
            
target_circle entwanted_distance z;
        }
    }
    
    if(
target_circle 0)
    {
        
set_entity_flags(target_circleFL_KILLMEtrue);
        
console_print(id"The health circle nearby was removed!");
    }
    else
    {
        
console_print(id"No health circles were found!");
    }
    return 
1;
}

public 
handler_command(idlevelcid)
{
    if(!
cmd_access(idlevelcid2)) return 1;
    
    new 
szRadius[5], szWidth[5], szAngle_X[5], szAngle_Y[5];
    
read_argv(1szRadiuscharsmax(szRadius));
    
read_argv(2szWidthcharsmax(szWidth));
    
read_argv(3szAngle_Xcharsmax(szAngle_X));
    
read_argv(4szAngle_Ycharsmax(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(entEV_SZ_classname"health_circle");
        
        new 
Float:fAngles[3];
        
        
entity_get_vector(idEV_VEC_originfAngles);
        
entity_set_origin(entfAngles);
        
        
entity_set_int(entEV_INT_iuser4str_to_num(szWidth));
        
entity_set_float(entEV_FL_fuser4floatstr(szRadius));
        
        
fAngles[0] = floatstr(szAngle_X);
        
fAngles[1] = floatstr(szAngle_Y);
        
entity_set_vector(entEV_VEC_anglesfAngles);
        
entity_set_int(entEV_INT_fixangletrue);
        
        
entity_set_int(entEV_INT_solidSOLID_TRIGGER);
        
entity_set_float(entEV_FL_nextthinkget_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:fWidthFloat:fPos[3], i;
    
pev(idpev_anglesfAngles);
    
pev(idpev_originfOrigin)
    
Maxs_Origin[id] = fOrigin;
    
Mins_Origin[id] = fOrigin;
    
fWidth float(pev(idpev_iuser4));
    
pev(idpev_fuser4fRadius[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(fPosfOriginfPos);
    
createline(fOriginfPos25500)
    
    const 
Float:fDivides 30.0;
    static 
Float:fTemp[3], Float:fAngle[3], Float:fVector[3] = { 0.00.00.0 }, Float:fStart[3];
    
    
xs_vec_copy(fAnglesfAngle);
    
fAngle[Y] += 90.0;
    for(
0<= floatround(360.0/fDivides); i++)
    {
        if(
0)
        {
            
xs_vec_copy(fVectorfStart); 
        }
        
        
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(fOriginfTempfVector);
        
        if(
fVector[X] < Mins_Origin[id][X])
        {
            
Mins_Origin[id][X] = fVector[X] + GAP
        
}
        else if(
fVector[X] > Maxs_Origin[id][X])
        {
            
Maxs_Origin[id][X] = fVector[X] - GAP
        
}
        else if(
fVector[Y] < Mins_Origin[id][Y])
        {
            
Mins_Origin[id][Y] = fVector[Y] + GAP
        
}
        else if(
fVector[Y] > Maxs_Origin[id][Y])
        {
            
Maxs_Origin[id][Y] = fVector[Y] - GAP
        
}
        else if(
fVector[Z] < Mins_Origin[id][Z])
        {
            
Mins_Origin[id][Z] = fVector[Z] + GAP
        
}
        else if(
fVector[Z] > Maxs_Origin[id][Z])
        {
            
Maxs_Origin[id][Z] = fVector[Z] - GAP
        
}

        if(
Maxs_Origin[id][X] == Mins_Origin[id][X])
        {
            
Mins_Origin[id][X] -= SPR_LENGHT
            Maxs_Origin
[id][X] += SPR_LENGHT
        
}
        else if(
Maxs_Origin[id][Y] == Mins_Origin[id][Y])
        {
            
Mins_Origin[id][Y] -= SPR_LENGHT
            Maxs_Origin
[id][Y] += SPR_LENGHT
        
}
        else if(
Maxs_Origin[id][Z] == Mins_Origin[id][Z])
        {
            
Mins_Origin[id][Z] -= SPR_LENGHT
            Maxs_Origin
[id][Z] += SPR_LENGHT
        
}

        if(
0)
        {
            
createline(fStartfVector)
        }
    }
    
    
entity_set_float(idEV_FL_nextthinkget_gametime() + 1.0);
}

public 
inside_circle(id)
{
    new 
ent = -1target_circle 0Float:Circle_Origin[3], Float:Player_Origin[3], Float:wanted_distance 250.0Float:z;
    
pev(idpev_originPlayer_Origin);

    while( (
ent find_ent_by_class(ent"health_circle")) > )
    {
        
pev(entpev_originCircle_Origin);
        if( (
z=get_distance_f(Player_OriginCircle_Origin)) <= wanted_distance )
        {
            
target_circle entwanted_distance z;
        }
    }

    if(
target_circle 0)
    {
        if( (
Mins_Origin[target_circle][X] < Player_Origin[X]) && (Player_Origin[X] < Maxs_Origin[target_circle][X]) && (Mins_Origin[target_circle][Y] < Player_Origin[Y]) && (Player_Origin[Y] < Maxs_Origin[target_circle][Y]) && (Mins_Origin[target_circle][Z] < Player_Origin[Z]) && (Player_Origin[Z] < Maxs_Origin[target_circle][Z]) )
        {
            
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;
}

createline(Float:fStart[3], Float:fOrigin[3], r=0g=255b=0)
{
    
message_begin(MSG_ALLSVC_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()


Last edited by Smilex_Gamer; 09-30-2019 at 12:01.
Smilex_Gamer is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-30-2019 , 13:59   Re: How to create circle
Reply With Quote #2

i'm not worried about getting the player in the circle right now but more about drawing the circle.

actually i want to be able to rotate the circle with given inputs...

so i want to be able to create a circle around a vector

i almost done it but remains one thing rotating the vector around the main vector to create a circle point by point.

my goal is to create a circle in vector plane and not just in XY and ZY nor ZX axis's plane...


my latest update.
Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-01-2019 at 03:05.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Smilex_Gamer
Senior Member
Join Date: Apr 2017
Location: Portugal
Old 09-30-2019 , 15:55   Re: How to create circle
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
i'm not worried about getting the player in the circle right now but more about drawing the circle.

actually i want to be able to rotate the circle with given inputs...

so i want to be able to create a circle around a vector

i almost done it but remains one thing rotating the vector around the main vector to create a circle point by point.

my goal is to create a circle in vector plane and not just in XY and ZY nor ZX axis's plane...


my latest update.
Spoiler
I understand that you want to create a circle that you can rotate by the X, Y and Z axis, but unfortunately I'm not used to use vectors and stuff like that, so the best thing I can do to help is the code for checking if the player is inside the circle (although any possible way to check it is to create a "box" where the limits are the circle's limits).
Smilex_Gamer 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:26.


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