AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Dragon Fly Help (https://forums.alliedmods.net/showthread.php?t=296424)

gcz 04-20-2017 13:28

Dragon Fly Help
 
1 Attachment(s)
:oops: i want to create motions dragon fly look like this photo

https://forums.alliedmods.net/attach...3&d=1492708758



https://forums.alliedmods.net/showthread.php?t=174017
Code:

                        pev(ent, mCenterOrigin, origin)
                        pev(ent, mCurrentAngle, angle)       
                               
                        angle += 0.1
                       
                        set_pev(ent, mCurrentAngle, angle)
                        set_pev(ent, pev_angles, angle)
                        set_pev(ent, pev_v_angle, angle)
                       
                        radius = 60.0        // get_pcvar_float(g_cvarRadius)
                       
                        toOrigin[0] = origin[0] + radius*(floatsin(0.99*angle) + 0.7*floatcos(3.01*angle))
                        toOrigin[1] = origin[1] + radius*(floatcos(1.01*angle) + 0.1*floatcos(15.03*angle))
                        toOrigin[2] = origin[2]
                       
                        pev(ent, pev_origin, origin)
                        xs_vec_sub(toOrigin, origin, toOrigin)
                        dist = vector_length(toOrigin)
                        xs_vec_normalize(toOrigin, toOrigin)
                        xs_vec_mul_scalar(toOrigin, dist / 0.1, toOrigin)        // THINK_DELAY
                        set_pev(ent, pev_velocity, toOrigin)




Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

#define ZOMBIE_PLAGUE

#if defined ZOMBIE_PLAGUE
        #include <zombieplague>
        #define GIVE_BONUS(%1) zp_set_user_ammo_packs(%1, zp_get_user_ammo_packs(%1) + get_pcvar_num(g_cvarBonus))
#else
        #include <cstrike>
        #define GIVE_BONUS(%1) cs_set_user_money(%1, cs_get_user_money(%1) + get_pcvar_num(g_cvarBonus))
#endif

#define PLUGIN "Floating Mosquito"
#define VERSION "0.1.0"
#define AUTHOR "PomanoB"

#define THINK_DELAY 0.1

#define mCenterOrigin        pev_vuser1
#define mCurrentAngle        pev_fuser1
#define mNextStageTime        pev_fuser2
#define mCurrentStage        pev_iuser1

new g_allocString

new g_configFile[64]

new Array:g_mosquitos

new g_mainMenu

new g_cvarBonus, g_cvarHP, g_cvarRadius

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_clcmd("say /mosquito", "cmdShowMenu", ADMIN_CFG, " - display mosquito menu")
       
        register_forward(FM_Think, "fwdThink")
       
        RegisterHam(Ham_TakeDamage, "func_breakable", "fwdBreakableTakeDamage", 1)
       
        register_event("HLTV", "roundStart", "a", "1=0", "2=0")
       
        g_allocString = engfunc(EngFunc_AllocString, "func_breakable")
       
        g_mosquitos = ArrayCreate(1, 1)
       
        g_cvarBonus = register_cvar("zp_floating_mosquitos_bonus", "5")
        g_cvarHP = register_cvar("zp_floating_mosquitos_hp", "1.0")
        g_cvarRadius = register_cvar("zp_floating_mosquitos_radius", "60.0")
       
        g_mainMenu = menu_create("Create mosquito", "mainMenuHandler")
        menu_additem(g_mainMenu, "Add mosquito", "")
        menu_additem(g_mainMenu, "Remove mosquito", "")
        menu_additem(g_mainMenu, "Remove all mosquito", "")
        menu_additem(g_mainMenu, "Write config file", "")
}

public plugin_precache()
{
        precache_model("models/dragonfly.mdl")
       
        precache_model("models/fleshgibs.mdl")
        precache_sound("debris/bustflesh1.wav")
        precache_sound("debris/bustflesh2.wav")
        precache_sound("debris/flesh1.wav")
        precache_sound("debris/flesh2.wav")
        precache_sound("debris/flesh3.wav")
        precache_sound("debris/flesh4.wav")
        precache_sound("debris/flesh5.wav")
        precache_sound("debris/flesh6.wav")
        precache_sound("debris/flesh7.wav")
       
        precache_sound("mosquito_buzzing.wav")
}

public plugin_cfg()
{
        get_configsdir(g_configFile, charsmax(g_configFile))
       
        add(g_configFile, charsmax(g_configFile), "/zp_floating_mosquito")
       
        if (!dir_exists(g_configFile) && mkdir(g_configFile) != 0)
        {
                log_amx("Failed to create directory!!!!")
                return
        }
       
        new mapName[32]
        get_mapname(mapName, charsmax(mapName))
       
        format(g_configFile, charsmax(g_configFile), "%s/%s.ini", g_configFile, mapName)
       
        if (file_exists(g_configFile))
        {
                new file = fopen(g_configFile, "rt")
                if (file)
                {
                        ArrayClear(g_mosquitos)
                        new line[64], coordX[10], coordY[10], coordZ[10], ent, Float:origin[3]
                        while (!feof(file))
                        {
                                fgets(file, line, charsmax(line))
                                trim(line)
                                if (strlen(line) > 0 && line[0] != ';' && line[0] != '/')
                                {
                                        parse(line, coordX, 9, coordY, 9, coordZ, 9)
                                       
                                        origin[0] = str_to_float(coordX)
                                        origin[1] = str_to_float(coordY)
                                        origin[2] = str_to_float(coordZ)
                                       
                                        ent = createMosquito()
                                        startMosquito(ent, origin)
                                       
                                        ArrayPushCell(g_mosquitos, ent)
                                }
                        }
                       
                        fclose(file)
                }
        }
        else
                log_amx("Cant find cfg file for this map!!!!!")
}

public plugin_end()
{
        ArrayDestroy(g_mosquitos)
}

public mainMenuHandler(id, menu, item)
{
        switch(item)
        {
                case 0:
                {
                        new Float:origin[3], ent
                        pev(id, pev_origin, origin)
                       
                        origin[2] += 64.0
                       
                        ent = createMosquito()
                        startMosquito(ent, origin)
                       
                        ArrayPushCell(g_mosquitos, ent)
                }
                case 1:
                {
                        new Float:origin[3], Float:mOrigin[3], Float:dist
                        new ent, i, j, Float:minDist = 9999.0, minM = 99999
                       
                        pev(id, pev_origin, origin)
                       
                        j = ArraySize(g_mosquitos)
                        for(i = 0; i < j; i++)
                        {
                                ent = ArrayGetCell(g_mosquitos, i)
                               
                                pev(ent, mCenterOrigin, mOrigin)
                               
                                if ((dist = get_distance_f(mOrigin, origin)) < minDist && dist < 500.0)
                                {
                                        minDist = dist
                                        minM = i
                                }
                        }
                       
                        if (0 <= minM < j)
                        {
                                j = ArrayGetCell(g_mosquitos, minM)
                                set_pev(j ,pev_flags, FL_KILLME)
                               
                                ArrayDeleteItem(g_mosquitos, minM)
                        }
                }
                case 2:
                {
                        ArrayClear(g_mosquitos)
                }
                case 3:
                {
                        new file = fopen(g_configFile, "w")
                        if (file)
                        {
                                new ent, i, j = ArraySize(g_mosquitos)
                                new Float:origin[3]
                               
                                for(i = 0; i < j; i++)
                                {
                                        ent = ArrayGetCell(g_mosquitos, i)
                                        pev(ent, mCenterOrigin, origin)
                                       
                                        fprintf(file, "^"%.1f^" ^"%.1f^" ^"%.1f^"^n",
                                                origin[0], origin[1], origin[2])
                                }
                               
                                fclose(file)
                        }
                        else
                                client_print(id, print_chat, "Cant open file %s for writing!!!",
                                        g_configFile)
                }
        }
}

public cmdShowMenu(id, level, cid)
{
        if (cmd_access(id, level, cid, 0))
                menu_display(id, g_mainMenu)
       
        return PLUGIN_HANDLED
}

public createMosquito()
{
        new ent = engfunc(EngFunc_CreateNamedEntity, g_allocString)
        fm_set_kvd(ent, "material", "3", "func_breakable")
        dllfunc(DLLFunc_Spawn, ent)
       
        set_pev(ent, pev_classname, "floating_mosquito")
        engfunc(EngFunc_SetModel, ent, "models/dragonfly.mdl")
        set_pev(ent, pev_solid, SOLID_BBOX)
        set_pev(ent, pev_movetype, MOVETYPE_FLY)
        set_pev(ent, pev_sequence, 1)
        set_pev(ent, pev_animtime, 2.0)
        set_pev(ent, pev_framerate, 1.0)
       
        new Float:mins[3] =  {-4.0, -4.0, -2.0}
        new Float:maxs[3] =  {4.0, 4.0, 2.0}
        set_pev(ent, pev_mins, mins)
        set_pev(ent, pev_maxs, maxs)
        engfunc(EngFunc_SetSize, ent, mins, maxs)
       
        set_pev(ent, pev_health, 1000.0 + get_pcvar_float(g_cvarHP))
       
        set_pev(ent, pev_takedamage, 1.0)
       
        set_pev(ent,pev_flags, FL_MONSTER|FL_MONSTERCLIP)
       
        return ent
}

public startMosquito(ent, Float:origin[3])
{
        new Float:gameTime = get_gametime()
       
        set_pev(ent, pev_health, 1000.0 + get_pcvar_float(g_cvarHP))
       
        set_pev(ent, mCurrentAngle, 0.0)
        set_pev(ent, mNextStageTime, gameTime + 5.0)
        set_pev(ent, mCurrentStage, 1)
        set_pev(ent, mCenterOrigin, origin)
       
        engfunc(EngFunc_SetOrigin, ent, origin)
       
        set_pev(ent, pev_solid, SOLID_BBOX)
        set_pev(ent, pev_effects, 0)
       
        set_pev(ent, pev_nextthink, gameTime + THINK_DELAY)
}

public fwdThink(ent)
{
        static classname[32], Float:currTime, Float:dist, Float:toOrigin[3], Float:radius
        pev(ent, pev_classname, classname, 31)
       
        if (equal(classname, "floating_mosquito"))
        {
                static Float:origin[3], Float:angle
                currTime = get_gametime()
               
                if (pev(ent, mNextStageTime) < currTime)
                {
                        set_pev(ent, mCurrentStage, !(pev(ent, mCurrentStage)))
                        set_pev(ent, mNextStageTime, currTime + 5.0)
                }
                else
                if (pev(ent, mCurrentStage))
                {
                        pev(ent, mCenterOrigin, origin)
                        pev(ent, mCurrentAngle, angle)       
                               
                        angle += 0.1
                       
                        set_pev(ent, mCurrentAngle, angle)
                        set_pev(ent, pev_angles, angle)
                        set_pev(ent, pev_v_angle, angle)
                       
                        radius = get_pcvar_float(g_cvarRadius)
                       
                        toOrigin[0] = origin[0] + radius*(floatsin(0.99*angle) + 0.7*floatcos(3.01*angle))
                        toOrigin[1] = origin[1] + radius*(floatcos(1.01*angle) + 0.1*floatcos(15.03*angle))
                        toOrigin[2] = origin[2]
                       
                        pev(ent, pev_origin, origin)
                        xs_vec_sub(toOrigin, origin, toOrigin)
                        dist = vector_length(toOrigin)
                        xs_vec_normalize(toOrigin, toOrigin)
                        xs_vec_mul_scalar(toOrigin, dist / THINK_DELAY, toOrigin)
                        set_pev(ent, pev_velocity, toOrigin)
                }
                else
                        set_pev(ent, pev_velocity, Float:{0.0, 0.0, 0.0})
                       
                set_pev(ent, pev_nextthink, currTime + THINK_DELAY)
               
                engfunc(EngFunc_EmitSound, ent, CHAN_VOICE, "mosquito_buzzing.wav", VOL_NORM, ATTN_IDLE, 0, PITCH_NORM)
        }
}

public fwdBreakableTakeDamage(ent, idinflictor, idattacker, Float:damage, damagebits)
{
        static classname[32], Float:health, name[32]
        pev(ent, pev_classname, classname, 31)
       
        if (equal(classname, "floating_mosquito"))
        {
                pev(ent, pev_health, health)
                if (health <= 1000.0)
                {
                        set_pev(ent, pev_nextthink, get_gametime() + 999999.0)
                        set_pev(ent, pev_solid, SOLID_NOT)
                        set_pev(ent, pev_effects, EF_NODRAW)
                       
                        if (is_user_connected(idattacker))
                        {
                                get_user_name(idattacker, name, charsmax(name))
                               
                                set_hudmessage(255, 0, 0, 0.14, 0.20, 0, 6.0, 3.0)
                                show_hudmessage(0, "%s killed infected mosquitos!!!",
                                        name)
                               
                                GIVE_BONUS(idattacker)
                        }
                }
        }
}

public roundStart()
{
        new ent, i, j = ArraySize(g_mosquitos)
        new Float:gameTime = get_gametime()
       
        for(i = 0; i < j; i++)
        {
                ent = ArrayGetCell(g_mosquitos, i)
               
                set_pev(ent, pev_nextthink, gameTime + THINK_DELAY)
                set_pev(ent, pev_solid, SOLID_BBOX)
                set_pev(ent, pev_effects, 0)
               
                set_pev(ent, pev_health, 1000.0 + get_pcvar_float(g_cvarHP))
        }
}

stock fm_set_kvd(entity, const key[], const value[], const classname[] = "") {
        if (classname[0])
                set_kvd(0, KV_ClassName, classname);
        else {
                new class[32];
                pev(entity, pev_classname, class, sizeof class - 1);
                set_kvd(0, KV_ClassName, class);
        }

        set_kvd(0, KV_KeyName, key);
        set_kvd(0, KV_Value, value);
        set_kvd(0, KV_fHandled, 0);

        return dllfunc(DLLFunc_KeyValue, entity, 0);
}


stock showBBox(ent, timeToShow)
{
        static Float:origin[3], Float:mins[3], Float:maxs[3]
        pev(ent, pev_origin, origin)
        pev(ent, pev_mins, mins)
        pev(ent, pev_maxs, maxs)
       
        xs_vec_add(origin, mins, mins)
        xs_vec_add(origin, maxs, maxs)
       
        message_begin(MSG_ALL, SVC_TEMPENTITY)
        write_byte(TE_BOX)
        engfunc(EngFunc_WriteCoord, mins[0])
        engfunc(EngFunc_WriteCoord, mins[1])
        engfunc(EngFunc_WriteCoord, mins[2])
        engfunc(EngFunc_WriteCoord, maxs[0])
        engfunc(EngFunc_WriteCoord, maxs[1])
        engfunc(EngFunc_WriteCoord, maxs[2])
        write_short(timeToShow)
        write_byte(255)
        write_byte(0)
        write_byte(0)
        message_end()
}



All times are GMT -4. The time now is 18:01.

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