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

Time limit on script


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CarbonDioxide
Member
Join Date: Apr 2012
Old 04-25-2012 , 16:26   Time limit on script
Reply With Quote #1

Hello all,
I have this code which is supposed to modify the bcm plugin so its xpblock gives xp every 6 mins, but the problem is the script I have now gives xp multiple times per second, which is a problem!
This is the script:
PHP Code:
ActionXPBlock(ident)  
{  
    if ( 
cs_get_user_team(id) == CS_TEAM_T )  
    {  
        if ( !
g_xpblock_used[id] )  
        {  
            new 
property[5];  
            
GetProperty(ent1property);  
            
hnsxp_add_user_xp(idstr_to_num(property));  
            
g_xpblock_used[id] = true;  
              
            
set_hudmessage(025500.010.1800.01.00.250.252);  
            
show_hudmessage(id"You got %i more XP!"str_to_num(property));  
        }  
    }  
        else  
        {  
            
set_hudmessage(025500.010.1800.01.00.250.252);  
            
show_hudmessage(id"Only Terrorists can take XP Block!");  
    }  

If someone could add a time limit of 360 secs, or even guide me so I do it myself(even though I do not know a lot of scripting..), I would really appreciate it.. : )

Keep up the good work,
CarbonDioxide
CarbonDioxide is offline
kapzz
Member
Join Date: Mar 2012
Location: Mars
Old 04-25-2012 , 20:07   Re: Time limit on script
Reply With Quote #2

i can't see any problem, maybe g_xpblock_used is being reseted somewhere , post all the code.

Last edited by kapzz; 04-25-2012 at 20:08.
kapzz is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 04-26-2012 , 06:44   Re: Time limit on script
Reply With Quote #3

Add a global variable and set it's value with get_gametime() on successful touch and check the difference between the current time and that's from the variable.

It should be something like this:

PHP Code:
if((get_gametime() - variable_name) > 360.0//360 seconds have passed since the last use? 
{
//success
//code, code, code...
 
variable_name get_gametime() //set the current time for the next check

__________________

Last edited by <VeCo>; 04-26-2012 at 06:46.
<VeCo> is offline
Old 04-26-2012, 09:02
CarbonDioxide
This message has been deleted by CarbonDioxide.
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 04-26-2012 , 09:13   Re: Time limit on script
Reply With Quote #4

try this,
PHP Code:
if (g_xpblock_used == true)
{
    return 
PLUGIN_HANDLED

__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.
Bilal Pro is offline
CarbonDioxide
Member
Join Date: Apr 2012
Old 04-26-2012 , 11:43   Re: Time limit on script
Reply With Quote #5

Quote:
Originally Posted by <VeCo> View Post
Add a global variable and set it's value with get_gametime() on successful touch and check the difference between the current time and that's from the variable.

It should be something like this:

PHP Code:
if((get_gametime() - variable_name) > 360.0//360 seconds have passed since the last use? 
{
//success
//code, code, code...
 
variable_name get_gametime() //set the current time for the next check

I have set the variable name to "xpblock_use" but I get an error, should I include something?

The error:
PHP Code:
ErrorUndefined symbol "xpblock_use" on line 1585 
CarbonDioxide is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 04-26-2012 , 11:55   Re: Time limit on script
Reply With Quote #6

Actually, a variable won't be useful here, so it's better to use one of the fuser private entity data.

Go to CreateBlock function:

Find this:

PHP Code:
    entity_set_vector(entEV_VEC_anglesangles); 
    
entity_set_size(entsize_minsize_max); 
    
entity_set_int(entEV_INT_bodyblock_type); 
Add after:

PHP Code:
entity_set_float(ent,EV_FL_fuser1,-360.0); 
Go to ActionXPBlock function.

Make it like this:

PHP Code:
ActionXPBlock(ident

    if ( 
cs_get_user_team(id) == CS_TEAM_T 
    { 
     if((
get_gametime() - entity_get_float(ent,EV_FL_fuser1)) > 360.0)
 {
      new 
property[5]; 
      
GetProperty(ent1property); 
      
hnsxp_add_user_xp(idstr_to_num(property)); 
      
g_xpblock_used[id] = true
 
      
set_hudmessage(025500.010.1800.01.00.250.252); 
      
show_hudmessage(id"You got %i more XP!"str_to_num(property)); 
 
      
entity_set_float(ent,EV_FL_fuser1,get_gametime());
 }
    } else { 
            
set_hudmessage(025500.010.1800.01.00.250.252); 
            
show_hudmessage(id"Only Terrorists can take XP Block!"); 
    } 

I haven't tested it, but it should work.
__________________

Last edited by <VeCo>; 04-26-2012 at 13:05.
<VeCo> is offline
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 04-26-2012 , 12:31   Re: Time limit on script
Reply With Quote #7

oops sorry forgot the index... was sleepy
PHP Code:
if (g_xpblock_used[id] == true)
{
    return 
PLUGIN_HANDLED

this should work 100%
__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.

Last edited by Bilal Pro; 04-26-2012 at 12:32.
Bilal Pro is offline
CarbonDioxide
Member
Join Date: Apr 2012
Old 04-26-2012 , 16:32   Re: Time limit on script
Reply With Quote #8

Ok guys, I made it, thank you all a lot !!
CarbonDioxide 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 03:31.


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