AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   another system than looping task as thinking ent(s) (https://forums.alliedmods.net/showthread.php?t=157131)

Doc-Holiday 05-16-2011 20:03

another system than looping task as thinking ent(s)
 
Not really sure what this means but the idea is

im using set_task with "b" flag to create a bleeding function in my plugin.

Conor told me
"Consider another system than looping task as thinking ent(s)"

I have no idea what he means but i have tried while loops. but that just happens really fast lol.. i need to be able to put a delay in set via cvar.

thats why i used

PHP Code:

set_task(get_pcvar_float(delay), "Function""id"__"b"); 

and if settask is all i can use then how can i copy "Float:Direction" , to a global variable to put in

ExecuteHamB(Ham_TraceBleed, id, dmg, Float:Direction, trace, dmgbits);

Exolent[jNr] 05-16-2011 20:22

Re: another system than looping task as thinking ent(s)
 
https://forums.alliedmods.net/showthread.php?t=43049

Doc-Holiday 05-16-2011 20:52

Re: another system than looping task as thinking ent(s)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1470733)

I always forget about the tut section THANKS!

ConnorMcLeod 05-17-2011 02:01

Re: another system than looping task as thinking ent(s)
 
In a private plugin i've never finished so i've never released, i'm using 1 entity per player (so players don't beel at the same time as in gore plugin and next bleed time is randomized) :

But you could manage with only 1 thinking entity ;)

PHP Code:

UTIL_CreateFollowingEnt(id)
{
    static 
iEntHamHook:Think
    iEnt 
engfunc(EngFunc_CreateNamedEntityg_iInfoTarget)

    if(
pev_valid(iEnt))
    {
        
set_pev(iEntpev_aimentid)
        
set_pev(iEntpev_movetypeMOVETYPE_FOLLOW)

        
set_pev(iEntpev_ownerid)

        
set_pev(iEntpev_nextthinkget_gametime() + random_float(1.04.0))

        
g_iBleeding[id] = iEnt

        set_pev
(iEntpev_iuser1BLEED_ENT)

        if( !
Think )
        {
            
Think RegisterHamFromEntity(Ham_ThinkiEnt"Think_Bleed")
        }
    }
}

public 
Think_Bleed(iEnt)
{
    if( 
pev(iEntpev_iuser1) == BLEED_ENT && UTIL_Bleed(iEnt) )
    {
        
set_pev(iEntpev_nextthinkget_gametime() + random_float(2.06.0))
    }
}

RemoveBleed(id)
{
    new 
iBleed g_iBleeding[id]
    if( 
pev_validiBleed ) )
    {
        
set_pev(iBleedpev_flagsFL_KILLME)
        
g_iBleeding[id] = 0
    
}
}

UTIL_Bleed(iEnt)
{
    new 
id pev(iEntpev_owner)

    if( !
IsAlive[id] )
    {
        if(
g_iBleeding[id]) // o_O
        
{
            
set_pev(g_iBleeding[id], pev_flagsFL_KILLME)
            
g_iBleeding[id] = 0
        
}
        return 
0
    
}

    new 
trace_handled
    
new Float:flFractionFloat:fDirection[3]
    new 
Float:start[3], Float:dest[3]

    
trace_handled create_tr2()
    
pev(idpev_originstart)

    
dest[0] = start[0]
    
dest[1] = start[1]
    
dest[2] = start[2] - 9999.0
                
    engfunc
(EngFunc_TraceLinestartdestIGNORE_MONSTERSidtrace_handled)
    
get_tr2(trace_handledTR_flFractionflFraction)
    if( 
flFraction != 1.0 )
    {
        
fDirection[0] = random_float(-1.01.0)
        
fDirection[1] = random_float(-1.01.0)
        
fDirection[2] = random_float(-1.00.0)
        
ExecuteHam(Ham_TraceBleedid50.0fDirectiontrace_handledDMG_BULLET)
        
UTIL_BloodStream(startfDirection7050 get_user_health(id))
    }
    
free_tr2(trace_handled)
    return 
1



Doc-Holiday 05-17-2011 05:27

Re: another system than looping task as thinking ent(s)
 
Quote:

Originally Posted by ConnorMcLeod (Post 1470815)
In a private plugin i've never finished so i've never released, i'm using 1 entity per player (so players don't beel at the same time as in gore plugin and next bleed time is randomized) :

But you could manage with only 1 thinking entity ;)

PHP Code:

UTIL_CreateFollowingEnt(id)
{
    static 
iEntHamHook:Think
    iEnt 
engfunc(EngFunc_CreateNamedEntityg_iInfoTarget)

    if(
pev_valid(iEnt))
    {
        
set_pev(iEntpev_aimentid)
        
set_pev(iEntpev_movetypeMOVETYPE_FOLLOW)

        
set_pev(iEntpev_ownerid)

        
set_pev(iEntpev_nextthinkget_gametime() + random_float(1.04.0))

        
g_iBleeding[id] = iEnt

        set_pev
(iEntpev_iuser1BLEED_ENT)

        if( !
Think )
        {
            
Think RegisterHamFromEntity(Ham_ThinkiEnt"Think_Bleed")
        }
    }
}

public 
Think_Bleed(iEnt)
{
    if( 
pev(iEntpev_iuser1) == BLEED_ENT && UTIL_Bleed(iEnt) )
    {
        
set_pev(iEntpev_nextthinkget_gametime() + random_float(2.06.0))
    }
}

RemoveBleed(id)
{
    new 
iBleed g_iBleeding[id]
    if( 
pev_validiBleed ) )
    {
        
set_pev(iBleedpev_flagsFL_KILLME)
        
g_iBleeding[id] = 0
    
}
}

UTIL_Bleed(iEnt)
{
    new 
id pev(iEntpev_owner)

    if( !
IsAlive[id] )
    {
        if(
g_iBleeding[id]) // o_O
        
{
            
set_pev(g_iBleeding[id], pev_flagsFL_KILLME)
            
g_iBleeding[id] = 0
        
}
        return 
0
    
}

    new 
trace_handled
    
new Float:flFractionFloat:fDirection[3]
    new 
Float:start[3], Float:dest[3]

    
trace_handled create_tr2()
    
pev(idpev_originstart)

    
dest[0] = start[0]
    
dest[1] = start[1]
    
dest[2] = start[2] - 9999.0
                
    engfunc
(EngFunc_TraceLinestartdestIGNORE_MONSTERSidtrace_handled)
    
get_tr2(trace_handledTR_flFractionflFraction)
    if( 
flFraction != 1.0 )
    {
        
fDirection[0] = random_float(-1.01.0)
        
fDirection[1] = random_float(-1.01.0)
        
fDirection[2] = random_float(-1.00.0)
        
ExecuteHam(Ham_TraceBleedid50.0fDirectiontrace_handledDMG_BULLET)
        
UTIL_BloodStream(startfDirection7050 get_user_health(id))
    }
    
free_tr2(trace_handled)
    return 
1




lol i wish there was more documentation on this type stuff Hawks Tut kinda just tells you how to do it and why its better but no matter what i do i cant figure out how to do it...

Not to many examples out there.

Owyn 05-17-2011 06:47

Re: another system than looping task as thinking ent(s)
 
RegisterHamFromEntity(Ham_Think, iEnt, "Think_Bleed")
so this would register all Thinks from info_target entities and call Think_Bleed() on each of it thinking?
btw, does
RegisterHamFromEntity() also not accept any non-standard entity classnames like RegisterHam()?

PHP Code:

set_pev(iEntpev_iuser1BLEED_ENT)
if( 
pev(iEntpev_iuser1) == BLEED_ENT

in which case Entity would change it's id so you need to make checks like above but not just if(EntID == MyEntID)?

fysiks 05-17-2011 20:10

Re: another system than looping task as thinking ent(s)
 
Quote:

Originally Posted by Doc-Holiday (Post 1470869)
Hawks Tut kinda just tells you how to do it and why its better

Well, that sounds like a great tutorial to me, one that tells you how to do it and justifies using it.

Doc-Holiday 05-18-2011 01:25

Re: another system than looping task as thinking ent(s)
 
Quote:

Originally Posted by fysiks (Post 1471306)
Well, that sounds like a great tutorial to me, one that tells you how to do it and justifies using it.

i agree lol.. but its just not alot of examples out there and I'm not very good with scripting so i have to read up on plenty of things before i actually understand it lol...


ive been playing with it but haven't figured it out yet it takes time.... i only code like once a month lol... work/school takes to much time

Hunter-Digital 05-18-2011 02:03

Re: another system than looping task as thinking ent(s)
 
What haven't you figure out ?

A basic global entity think:
Code:

#include <amxmodx>
#include <engine>

public plugin_init()
{
    new ent = create_entity("info_target") /* creates "info_target", the most commonly used entity classname for custom entity creation */

    if(ent) /* if entity was succesfully created */
    {
        entity_set_string(ent, EV_SZ_classname, "globalThink") /* this changes entity's classname from info_target to globalThink wich is an invented entity */

        entity_set_float(ent, EV_FL_nextthink, get_gametime()) /* this sets when the entity's next think call occurs, and get_gametime() means NOW */

        register_think("globalThink", "ent_think") /* hook entity's thinking process and call ent_think() when that occurs */
    }
}

public ent_think(ent) /* ent is the entity's id that called the function, there can be more than one entity for one classname, that's why I invented a new classname, so only one triggers */
{
    server_print("[debug] globalThink :: gametime=%f", get_gametime()) /* just to see it works, prints gametime to server when this triggers */

    entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.05) /* Set when the entity's next think call occurs, that is in 0.05 seconds */
}

There you go, a commented simple example :}

The rest of Connor's code is just to make bleeding work efficiently, so just use that and figure it out when you have time to learn.

Doc-Holiday 05-18-2011 15:53

Re: another system than looping task as thinking ent(s)
 
@Hunter

It takes time bro... lol the only time i even try to create plugins is when i need something for my servers that isnt already out there. So i dont play with it often. other then that the only code i play with is Small basic and i do that with my 8 and 10 year old lil bros.

I start school again on July 4th which will finally get me going into programing classes. fucking general ed blows!!!!!. So i should be able to start playing with code more and actually understanding it lol.. i know very lil enough to get me by with pawn. but the classes I'm taking are mainly C++ and what not my major is Computer Forensics.

But thanks.. i just haven't had time to really get into this.


All times are GMT -4. The time now is 04:29.

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