AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Repeating a function (https://forums.alliedmods.net/showthread.php?t=233035)

Starman 01-08-2014 19:07

[HELP] Repeating a function
 
Hi all, I need help because I'm trying to do something "I" complicated this problem and I've tried before, but with no solution, I'll post an example:

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    register_forward(FM_CmdStart, "CmdStart")
}

public CmdStart(Client)
{
    if(is_user_connected(Client))
    {
        client_print(Client, print_chat, "Example...")
    }
}

(Is an example), but when test it so to speak, has created many, many client_prints for every 0.1 seconds or so I think, and this happens to me with almost everything I do in this type of forwards, as PlayerPreThink, PlayerPostThink , FM_CmdStart and FM_Spawn. Tell me if there is a healthier way to do it because I like to create plugins that take these or other types of data without creating many client_prints or temporal entities.

YamiKaitou 01-08-2014 19:14

Re: [HELP] Repeating a function
 
That is because FM_CmdStart is called multiple times per second.

Starman 01-08-2014 19:20

Re: [HELP] Repeating a function
 
Quote:

Originally Posted by YamiKaitou (Post 2083190)
That is because FM_CmdStart is called multiple times per second.

Exactly, but that would have to work forward?

An example would be the print_chat only occur once.

hornet 01-08-2014 19:26

Re: [HELP] Repeating a function
 
It would be much easier if you explain exactly what your trying to do.

Blizzard_87 01-08-2014 19:26

Re: [HELP] Repeating a function
 
Explain what you are trying to accomplish.

Edit. Damn hornet you just beat me to the punch lol

Starman 01-08-2014 19:46

Re: [HELP] Repeating a function
 
Sorry, I knew I had to give an explanation ... This is the code I'm currently doing ...

I'm making something like a fire aura around the character using an entity type "env_sprite" with a sound created by a friend:

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <engine>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new Fire[] = "sprites/fire.spr"

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    register_forward(FM_CmdStart, "CmdStart")
}

public plugin_precache()
{
    precache_model(Fire)
}

public CmdStart(Client)
{
    if(is_user_alive(Client))
    {
        new Entity = create_entity("env_sprite")
       
        new Float:Origin[3] = {0.0, 5.0, 0.0)
       
        entity_get_vector(Client, EV_VEC_origin, Origin)
       
        entity_set_origin(Entity, Origin)
       
        entity_set_model(Entity, Fire)
        entity_set_int(Entity, EV_INT_rendermode, kRenderTransAdd)
        entity_set_float(Entity, EV_FL_renderamt, 255.0)
       
        entity_set_float(Entity, EV_FL_frame, 12.0)
        entity_set_int(Entity, EV_INT_spawnflags, SF_SPRITE_STARTON)
       
        entity_set_int(Entity, EV_INT_solid, SOLID_BBOX)
        entity_set_int(Entity, EV_INT_movetype, MOVETYPE_FLY)
        entity_set_edict(Entity, EV_ENT_owner, Client)
       
        dllfunc(DLLFunc_Spawn, Ent)
       
        if(!is_user_alive(Client))
        {
            remove_entity(Entity)
        }
    }
}

Probably something this misconceived as a rookie but I'm something like this kind of plugins, however, compiles fine, and the entity is created, but when testing the plugin, many entities are created, and at one point gets slow play, and upload mistake ...

PD: I've already try deleting the condition "is_user_alive" ...

hornet 01-08-2014 21:27

Re: [HELP] Repeating a function
 
The problem is that your trying to create a new entity several times per second. When really, you just need one entity per player, and have it follow that player. Easiest and most effective way - when the player spawns.

Also, this is why you never "post an example" of what your trying to do. Always provide any and every relevant detail to your issue to ensure that the users helping you understand what your trying to do and can help provide a solution. And in order to prevent what we have right here, known as the XY Problem.

See how you go with this:
Spoiler


All times are GMT -4. The time now is 10:13.

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