Raised This Month: $30 Target: $400
 7% 

Problem with task


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 04-29-2020 , 00:23   Problem with task
Reply With Quote #1

Hi everyone, well I'm doing like a mini game that is battle of deagles, the mini game consists of that every 15 seconds the player freezes and gives him a deagle to kill them, after the 15 second has passed he drops the deagle and He gives a knife and so on, when there are only two players left, I remove the tasks and they give them deagle again but with more bullets, the problem is that the task of removing the deagle does not work and drops the deagle and gives me the knife. It is like I removed the task of giving deagle but since this task activates the other it is like in progress and it is removed until when the eight seconds I give to remove the deagle pass. In other words I want to remove the tasks instantly when there are only two players left so that it does not activate after there are only the two players and doesn't affect the mini game, Could someone tell me how can I fix it please? ... Thanks in advance

This is the code:

PHP Code:
#include <amxmodx>
#include <fun>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <cstrike>
#include <dhudmessage>

#define PLUGIN "deagle battle"
#define VERSION "1.0"
#define AUTHOR "kha"

#define flag_get(%1,%2) (%1 & (1 << (%2 & 31)))
#define flag_set(%1,%2) %1 |= (1 << (%2 & 31))
#define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31))

new g_MaxPlayers

#define TASK_GIVEDEAGLE 558
#define TASK_REMOVEDEAGLE 559

new g_IsFrozen
new Float:g_FrozenGravity[33]

new 
Ham:Ham_Player_ResetMaxSpeed Ham_Item_PreFrame

#define GRAVITY_HIGH 999999.9
#define GRAVITY_NONE 0.000001

public plugin_init() 
{
         
register_plugin(PLUGINVERSIONAUTHOR)
    
         
RegisterHam(Ham_Killed"player""fw_PlayerKilled_Post"1)
         
RegisterHam(Ham_Player_ResetMaxSpeed"player""fw_ResetMaxSpeed_Post"1)
         
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")
         
register_event("HLTV","NewRound","a""1=0""2=0")
         
register_logevent("RoundEnd"2"1=Round_End")
    
         
g_MaxPlayers get_maxplayers()
}

public 
NewRound()
{    
         new 
id
         
for (id 1id <= g_MaxPlayersid++)
         {
                  if (!
is_user_alive(id))
                           continue
        
                  
show_menu(id0"^n"1)
                  
strip_user_weapons(id)
                  
give_item(id"weapon_knife")
                  
set_user_health(id500)
                  
set_task(15.0"Task_GiveDeagle"id+TASK_GIVEDEAGLE__"b")
         }
}

public 
fw_ResetMaxSpeed_Post(id)
{
         if (!
is_user_alive(id) || !flag_get(g_IsFrozenid))
                  return
    
         
set_user_maxspeed(id1.0)
}

public 
fw_PlayerPreThink(id)
{
         if (!
is_user_alive(id) || !flag_get(g_IsFrozenid))
                  return
    
         
set_pev(idpev_velocityFloat:{0.0,0.0,0.0})
}

public 
fw_PlayerKilled_Post(victimattackershouldgib
{
         
CheckRoundStatus() 
}

CheckRoundStatus()
{
         new 
name1[32], name2[32], iPlayers[32], iNum    
    
         
for(new iPlayer 1iPlayer <= g_MaxPlayersiPlayer++)
         {
                  if(
is_user_alive(iPlayer))
                           
iPlayers[iNum++] = iPlayer
         
}
    
         if(
iNum 3)
         {
                  if(
iNum 1)
                  {    
                           
get_user_name(iPlayers[0], name1charsmax(name1))    
                           
get_user_name(iPlayers[1], name2charsmax(name2))
              
                           for(new 
id 1id g_MaxPlayersid++)
                           {
                                    if(!
is_user_alive(id))
                                             continue
                         
                                    
ApplyFrozenGravity(id)
             
                                    
flag_unset(g_IsFrozenid)
    
                                    
set_pev(idpev_gravityg_FrozenGravity[id])
    
                                    
ExecuteHamB(Ham_Player_ResetMaxSpeedid)
        
                                    
remove_task(id+TASK_GIVEDEAGLE)
                         
                                    
remove_task(id+TASK_REMOVEDEAGLE)
                           }
              
                           
entity_set_float(iPlayers[0], EV_FL_health100.0)
                           
entity_set_float(iPlayers[1], EV_FL_health100.0)
            
                           
strip_user_weapons(iPlayers[0])
                           
strip_user_weapons(iPlayers[1])
            
                           
give_item(iPlayers[0], "weapon_deagle")
                           
cs_set_user_bpammo(iPlayers[0], CSW_DEAGLE200
               
                           
give_item(iPlayers[1], "weapon_deagle")
                           
cs_set_user_bpammo(iPlayers[1], CSW_DEAGLE200)
            
                           
set_dhudmessage(5020550, -1.00.2006.03.00.50.13)
                           
show_dhudmessage(0"%s^n- VS -^n%s"name1name2)               
                  }
                  else
                  {               
                           
get_user_name(iPlayers[0], name1charsmax(name1))
           
                           
set_dhudmessage(5020550, -1.00.2006.03.00.50.13)
                           
show_dhudmessage(0"%s is the winner!"name1)
                  }
         } 
}

public 
Task_GiveDeagle(id)
{
         
id -= TASK_GIVEDEAGLE
    
         flag_set
(g_IsFrozenid)
    
         
ApplyFrozenGravity(id)
    
         
ExecuteHamB(Ham_Player_ResetMaxSpeedid)
     
         
set_dhudmessage(02550, -1.00.2006.03.00.50.13)
         
show_dhudmessage(id"KILL NOW!")
    
         
strip_user_weapons(id)
         
give_item(id"weapon_deagle")
    
         
set_task(8.0"Task_RemoveDeagle"id+TASK_REMOVEDEAGLE)
}

public 
Task_RemoveDeagle(id)
{
         
id -= TASK_REMOVEDEAGLE
    
         
for(new id 1id g_MaxPlayersid++)
         {
                  if(!
is_user_alive(id))
                           continue
          
                  
flag_unset(g_IsFrozenid)
    
                  
set_pev(idpev_gravityg_FrozenGravity[id])
                
                  
ExecuteHamB(Ham_Player_ResetMaxSpeedid)
          
                  
set_dhudmessage(02550, -1.00.2006.03.00.50.13)
                  
show_dhudmessage(id"Time finished^nPrepare for the next battle!")
    
                  
strip_user_weapons(id)
                  
give_item(id"weapon_knife")
         }


ApplyFrozenGravity(id)
{
         new 
Float:gravity get_user_gravity(id)
    
         if (
gravity == GRAVITY_HIGH || gravity == GRAVITY_NONE)
                  return
    
         
g_FrozenGravity[id] = gravity
    
         
if (pev(idpev_flags) & FL_ONGROUND)
                  
set_user_gravity(idGRAVITY_HIGH// set really high
         
else
                  
set_user_gravity(idGRAVITY_NONE// no gravity
}

public 
RoundEnd() 
{
         for(new 
id 1id <= g_MaxPlayers; ++id)
         {
                  if(!
is_user_alive(id))
                           continue
        
                  if (
flag_get(g_IsFrozenid))
                  {
                           
ApplyFrozenGravity(id)
             
                           
flag_unset(g_IsFrozenid)
    
                           
set_pev(idpev_gravityg_FrozenGravity[id])
    
                           
ExecuteHamB(Ham_Player_ResetMaxSpeedid)

                           
remove_task(id+TASK_GIVEDEAGLE)

                           
remove_task(id+TASK_REMOVEDEAGLE)
                  }
         }


Last edited by wicho; 04-29-2020 at 00:30.
wicho is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 04-29-2020 , 02:33   Re: Problem with task
Reply With Quote #2

PHP Code:
#define TASK_GIVEDEAGLE 558
#define TASK_REMOVEDEAGLE 559 
->
PHP Code:
#define TASK_GIVEDEAGLE 558
#define TASK_REMOVEDEAGLE 659 
Your tasks are too close to eachother and causing overlaps. Tasks need a minimum of MAXPLAYERS distance from eachother to prevent remove_task() from one task affecting another.

Last edited by safetymoose; 04-29-2020 at 02:37.
safetymoose is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 04-29-2020 , 03:06   Re: Problem with task
Reply With Quote #3

So the other task should be 590
wicho is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 04-29-2020 , 03:25   Re: Problem with task
Reply With Quote #4

Quote:
Originally Posted by wicho View Post
So the other task should be 590
591

Can be anything you want as long as it doesnt interfiere with another task. I simply go up by 100 for each task.

Last edited by safetymoose; 04-29-2020 at 03:31.
safetymoose is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 04-29-2020 , 17:56   Re: Problem with task
Reply With Quote #5

For player tasks:
PHP Code:
enum (+= 33)
{
    
g_iIDTaskBurn 32,
    
g_iIDTaskCheckConnected

For entity tasks:
PHP Code:
enum (+= 10001)
{
    
g_iIDTaskSoundRepeat 10000,
    
g_iIDTaskSoundPlayDelay,
    
g_iIDTaskSpriteRepeat,
    
g_iIDTaskDisableFireNadeZP,
    
g_iIDTaskFireDamageCoolDown,
    
g_iIDTaskExposureTimeDecrease,
    
g_iIDTaskAd

__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-29-2020 , 18:46   Re: Problem with task
Reply With Quote #6

georgik57, with that you will end up with the below. Removing the "(+= #)" and starting the enum at the appropriate start value will make it work as you intend (g_iIDTaskBurn = 33, g_iIDTaskSoundRepeat = 10001).

Code:
g_iIDTaskBurn = 32
g_iIDTaskCheckConnected = 65
Code:
g_iIDTaskSoundRepeat = 10000
g_iIDTaskSoundPlayDelay = 20001
__________________

Last edited by Bugsy; 04-29-2020 at 18:47.
Bugsy is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 04-29-2020 , 19:38   Re: Problem with task
Reply With Quote #7

Thanks.
So if I declare the initial starting value, it will auto add that value to every entry?
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-29-2020 , 20:57   Re: Problem with task
Reply With Quote #8

Setting a value for the first entry is where the enum will start at. If you do not define an incrementing rule, it will increment +1 for each entry.
PHP Code:
enum 
{
    
val1//0
    
val2//1
    
val3//2
}

//or

enum 
{
    
val1 33//33
    
val2//34
    
val3//35
}

//or

enum (+= 5)
{
    
val1 35//35
    
val2//40
    
val3//45

Also useful for defining constants for bit-fields
PHP Code:
enum (<<=1)
{
    
val1 1,//1    or    1<<0
    
val2,    //2    or    1<<1
    
val3,    //4    or    1<<2
    
val4,    //8    or    1<<3
    
val5     //16    or    1<<4

__________________

Last edited by Bugsy; 04-29-2020 at 21:00.
Bugsy is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 04-30-2020 , 11:00   Re: Problem with task
Reply With Quote #9

Then my code is correct. That's what I intended it to do.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-30-2020 , 13:15   Re: Problem with task
Reply With Quote #10

Explain your logic behind this then:

Code:
g_iIDTaskBurn = 32
g_iIDTaskCheckConnected = 65    //Why jump from 32 to 65?
Code:
g_iIDTaskSoundRepeat = 10000
g_iIDTaskSoundPlayDelay = 20001    //Why jump from 10000 to 20001?
g_iIDTaskSpriteRepeat = 30002
g_iIDTaskDisableFireNadeZP = 40003
g_iIDTaskFireDamageCoolDown= 50004
g_iIDTaskExposureTimeDecrease = 60005
g_iIDTaskAd= 70006
__________________

Last edited by Bugsy; 04-30-2020 at 13:21.
Bugsy 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 01:47.


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