Raised This Month: $ Target: $400
 0% 

Flashlight times change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
grankee
Member
Join Date: Jun 2008
Old 07-02-2010 , 04:11   Flashlight times change
Reply With Quote #1

Hello!
I need to change time of charging and discharge flashlight battery. This is my code:
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>

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

#define m_iFlashBattery 244
#define TASK_LATARKA 2543
new latarka_on[33],latarka_block[33]
new licznik[33]
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_event("Flashlight","latarka_onoff","b")
    register_message(get_user_msgid("FlashBat"),"latarka_bateria")
    register_impulse(100,"latara")
}
public latara(id)
{
    if(latarka_on[id]&&latarka_block[id])
        return PLUGIN_HANDLED
    return PLUGIN_CONTINUE
}
public latarka_onoff(id)
{
    latarka_on[id]=read_data(1)
    client_print(id,print_chat,"ustawiam latarke na %d",latarka_on[id])
    if(!latarka_on[id])    
        licznik[id]=0
    else
    {
        latarka_block[id]=1
        set_task(1.2,"odblokuj_latarke",id+TASK_LATARKA)
    }
}
public odblokuj_latarke(id)
{
    latarka_block[id-TASK_LATARKA]=0
}
public latarka_bateria(a,b,id)
{
    new procent=get_msg_arg_int(1)
    if(!latarka_on[id])
    {
        if(++licznik[id]%10==0)
        {
            return PLUGIN_CONTINUE
        }
        else
        {
            set_pdata_int(id,m_iFlashBattery,procent>=1?procent-1:0)
            return PLUGIN_HANDLED
        }
    }
    else//rozładowywanie się
    {
        if(procent>8)//
        {
            set_pdata_int(id,m_iFlashBattery,procent-8)
            client_print(id,print_chat,"proc=%d > 8",procent)
        }
        else if(8>=procent>1)
        {
            set_pdata_int(id,m_iFlashBattery,1)
            client_print(id,print_chat,"1<proc=%d <= 8",procent)
        }
        else
            client_print(id,print_chat,"proc=%d",procent)//tu sie  zapetla hmm / in this it is repeat
    }
    return PLUGIN_CONTINUE
}
but sometimes flshlight just dont turn off when battery is empty and event repeat some 5 times per second(i think it's 5)-you must know, battery charging 5 times per second too.
grankee 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 07:10.


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