Raised This Month: $51 Target: $400
 12% 

Making an entity think


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-02-2006 , 15:59   Making an entity think
Reply With Quote #1

Before I begin: Yes, I know this would be easier with engine, but I don't want to use engine, I want to use fakemeta, please respond with code that uses fakemeta, not engine


Ok, like the title says, I'm trying to make an entity think, I've done dllfunc(DLLFunc_Think, ent) and all that, but I still won't work. The forward is being called (I've set up some logging as you see), which means it works, its just that my entity won't think :/


Code that creates the entity:

Code:
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));          dllfunc(DLLFunc_Spawn, ent);         set_pev(ent, pev_classname, "rpg_rocket");     set_pev(ent, pev_movetype, 5);     set_pev(ent, pev_solid, 2);     set_pev(ent, pev_owner, id);     set_pev(ent, pev_origin, origin);     set_pev(ent, pev_nextthink, engfunc(EngFunc_Time) + 0.1);         engfunc(EngFunc_SetSize, ent, Float:{0.1,0.1,0.1}, Float:{0.1,0.1,0.1});     engfunc(EngFunc_SetModel, ent, "models/rpgrocket.mdl");     engfunc(EngFunc_SetOrigin, ent, origin);

Think code (Yes, forward is registered or else logging wouldn't work):
Code:
public Forward_Think(ent) {         new classname[32];     pev(ent, pev_classname, classname, 31);         log_amx("Think: %s", classname);         if (!equal(classname, "rpg_rocket"))         return;         new owner = pev(ent, pev_owner);     new RocketMode:mode = gRocketMode[owner];         new Float:velocity[3];         switch (mode)     {                 case MODE_RC:         {                         velocity_by_aim(owner, RPG_ROCKET_SPEED, velocity);             pev(ent, pev_velocity, velocity);                     }                 case MODE_HEAT:         {                         new target = pev(ent, pev_target);                         if (is_user_alive(target))             {                                 new Float:origin[3];                 new Float:entOrigin[3];                 new Float:velocity[3];                 new Float:speed;                                 pev(target, pev_origin, origin);                 pev(ent, pev_origin, entOrigin);                                 speed = (float(RPG_ROCKET_SPEED)/ 100.0);                                 velocity[0] = (origin[0] - entOrigin[0]) * speed;                 velocity[1] = (origin[1] - entOrigin[1]) * speed;                 velocity[2] = (origin[2] - entOrigin[2]) * speed;                                 set_pev(ent, pev_velocity, velocity);                             }             else // Lets see if we can find another target...             {                                 new origin[3];                 pev(owner, pev_origin, origin);                                 new players[32];                 new player;                 new numFound;                                 get_players(players, numFound, "a");                             new closestPlayer;                 new lastClosestDist = 99999;                             new i;                 for (i = 0; i < numFound; i++)                 {                                         player = players[i];                                         new checkOrigin[3];                     pev(player, pev_origin, checkOrigin);                                         if (get_distance(origin, checkOrigin) < lastClosestDist)                         closestPlayer = player;                                         }                                 if (is_user_alive(closestPlayer))                     set_pev(ent, pev_target, closestPlayer);                 else // Oh well, lets explode                 {                                         Explode(ent);                     return;                                     }                             }                     }             }         new Float:angles[3];     vector_to_angle(velocity, angles);     pev(ent, pev_angles, angles);         new smokeOrigin[3];     pev(ent, pev_origin, smokeOrigin);         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)            write_byte(TE_SPRITE)      // additive sprite, plays 1 cycle     write_coord(smokeOrigin[0])     write_coord(smokeOrigin[1])     write_coord(smokeOrigin[2])  // coord, coord, coord (position)     write_short(gSprRocketTrail)    // short (sprite index)     write_short(20)   // byte (scale in 0.1's)     write_short(255)        // byte (brightness)     message_end()         set_pev(ent, pev_nextthink, engfunc(EngFunc_Time) + 0.1);     dllfunc(DLLFunc_Think, ent);     }

After, posting this, I realized that I wasn't returning any of the FMRES_* return constants, would that have anything to do with it?

Thank you for any and all help.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 08-02-2006 at 16:02.
Zenith77 is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 08-02-2006 , 16:35   Re: Making an entity think
Reply With Quote #2

?
Code:
#include <amxmodx> #include <fakemeta> new g_ent public plugin_init() {     g_ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))     new Float:gametime = get_gametime()     server_print("Entity %d is created, think task is started at gametime %f", g_ent, gametime)     set_pev(g_ent, pev_nextthink, gametime + 3.0)     register_forward(FM_Think, "forward_think") } public forward_think(ent) {     if (ent == g_ent)         server_print("Entity %d is thinking, gametime is %f", ent, get_gametime()) } // Output: // Entity 131 is created, think task is started at gametime 1.000000 // Entity 131 is thinking, gametime is 4.000000
VEN is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 08-02-2006 , 16:47   Re: Making an entity think
Reply With Quote #3

Or, if you like the "pure" FM
Code:
new Float:gametime global_get(glb_time, gametime)

engfunc(EngFunc_Time) is a total server uptime.
VEN is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-02-2006 , 18:33   Re: Making an entity think
Reply With Quote #4

I can't really use a global veriable, considering the entity is created everytime the user presses attack (it creates a rocket)
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 08-03-2006 , 04:22   Re: Making an entity think
Reply With Quote #5

If you don't like to use global_get(glb_time, ...) you can use get_gametime from the core, it's the same things. halflie_time is the same as get_gametime so i'm not talking about engine. There are no other way.
VEN is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 08-03-2006 , 15:13   Re: Making an entity think
Reply With Quote #6

lol, sorry to confuse you, I was talking about the gEnt thing, which even then, I was wrong. Entity now thinks, when I use global_get() (or get_gametime()) .

Code:
L 08/03/2006 - 15:14:56: [rpg.amxx] Think: rpg_rocket
*edit*:
One more question, do I really need to call this

Code:
dllfunc(DLLFunc_Think, ent);

when I want the entity to think?
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 08-03-2006 at 15:16.
Zenith77 is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 08-04-2006 , 06:13   Re: Making an entity think
Reply With Quote #7

Quote:
I was talking about the gEnt thing
Yes, i see now. I posted the code just to show how to create entity thinking. It was just an example to show the idea.

DLLFunc_Think forces immediate entity think and it's not hookable through FM_Think so i'd say "no", unless you want immediate think.
VEN is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 01-28-2011 , 08:22   Re: Making an entity think
Reply With Quote #8

http://forums.alliedmods.net/showpos...0&postcount=18

I only have trouble, when I am using DLLFunc_Spawn and pev_nextthink, because then the entity is not paying attention to my pev_nextthink settings.
Lulu the hero is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-28-2011 , 08:31   Re: Making an entity think
Reply With Quote #9

I think you test wrongly because I've tested your plugin and whatever I use DLLFunc_Spawn or not, the entity is thinking. Also, spawing for info_target does nothing since it's like a dummy entity.
__________________
Arkshine 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 15:55.


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