Raised This Month: $ Target: $400
 0% 

[HELP] Repeating a function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Starman
Junior Member
Join Date: Dec 2013
Old 01-08-2014 , 19:07   [HELP] Repeating a function
Reply With Quote #1

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.
Starman is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-08-2014 , 19:14   Re: [HELP] Repeating a function
Reply With Quote #2

That is because FM_CmdStart is called multiple times per second.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Starman
Junior Member
Join Date: Dec 2013
Old 01-08-2014 , 19:20   Re: [HELP] Repeating a function
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
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.
Starman is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 01-08-2014 , 19:26   Re: [HELP] Repeating a function
Reply With Quote #4

It would be much easier if you explain exactly what your trying to do.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 01-08-2014 , 19:26   Re: [HELP] Repeating a function
Reply With Quote #5

Explain what you are trying to accomplish.

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

Last edited by Blizzard_87; 01-08-2014 at 19:27.
Blizzard_87 is offline
Starman
Junior Member
Join Date: Dec 2013
Old 01-08-2014 , 19:46   Re: [HELP] Repeating a function
Reply With Quote #6

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" ...
Starman is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 01-08-2014 , 21:27   Re: [HELP] Repeating a function
Reply With Quote #7

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
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 01-08-2014 at 21:29.
hornet is offline
Reply


Thread Tools
Display Modes

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 10:13.


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