AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Time limit on script (https://forums.alliedmods.net/showthread.php?t=183713)

CarbonDioxide 04-25-2012 16:26

Time limit on script
 
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

kapzz 04-25-2012 20:07

Re: Time limit on script
 
i can't see any problem, maybe g_xpblock_used is being reseted somewhere , post all the code.

<VeCo> 04-26-2012 06:44

Re: Time limit on script
 
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



Bilal Pro 04-26-2012 09:13

Re: Time limit on script
 
try this,
PHP Code:

if (g_xpblock_used == true)
{
    return 
PLUGIN_HANDLED



CarbonDioxide 04-26-2012 11:43

Re: Time limit on script
 
Quote:

Originally Posted by <VeCo> (Post 1696681)
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 


<VeCo> 04-26-2012 11:55

Re: Time limit on script
 
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.

Bilal Pro 04-26-2012 12:31

Re: Time limit on script
 
oops sorry forgot the index... was sleepy :D
PHP Code:

if (g_xpblock_used[id] == true)
{
    return 
PLUGIN_HANDLED


this should work 100%

CarbonDioxide 04-26-2012 16:32

Re: Time limit on script
 
Ok guys, I made it, thank you all a lot !!


All times are GMT -4. The time now is 07:49.

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