AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Adding up (https://forums.alliedmods.net/showthread.php?t=140581)

SaM.ThE.MaN 10-14-2010 07:30

Adding up
 
Hi...

I was working on something , like example :

So first we have a number g_Number[33] which is = 500 ...

Then it shows an hud Message : Energy : g_Number[33] which is 500

Then each 5 seconds ... the g_Number[33] is supposed to increase by 10 , which means its supposed to be 511 ... The hud should show 511 ... but it still shows me 500 .. No errors or warnings, everything runs properly..

Guess : My guess is because i have already done this new g_Number[33] = 500 , it only shows 500 , but not sure , Help :D ..

Script :

PHP Code:

#include <amxmodx> 

new g_Number[33] = 500 

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


public plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
     
    
// Tasks 
    
    
set_task(0.1"ShowNumber",_,_,_"b"
    
set_task(5.0"IncreaseNumber",_,_,_"b"


public 
ShowNumber(id

    
set_hudmessage(021300.600.9401.01.0
    
show_hudmessage(id"Number: %i"g_Number[id]) 


public 
IncreaseNumber(id

    if(
is_user_connected(id) ) 
    { 
        
g_Number[id] = g_Number[id] + 10 
    




SpeeDeeR 10-14-2010 08:02

Re: Adding up
 
PHP Code:

  set_task(5.0"IncreaseNumber",_,_,_"b"
public 
IncreaseNumber(id)  
{  
    if(
is_user_connected(id) )  
    {  
        
g_Number[id] = g_Number[id] + 10  
    
}  


Whose index is this ?

SaM.ThE.MaN 10-14-2010 08:09

Re: Adding up
 
Quote:

Originally Posted by SpeeDeeR (Post 1324466)
PHP Code:

  set_task(5.0"IncreaseNumber",_,_,_"b"
public 
IncreaseNumber(id)  
{  
    if(
is_user_connected(id) )  
    {  
        
g_Number[id] = g_Number[id] + 10  
    
}  


Whose index is this ?

what do you mean ...

Ryokin 10-14-2010 08:30

Re: Adding up
 
Quote:

Originally Posted by SaM.ThE.MaN (Post 1324472)
what do you mean ...

there's no index in that func, you need to check
PHP Code:

for (new i=0i<get_maxplayersi++)
{
   if ...



SpeeDeeR 10-14-2010 08:38

Re: Adding up
 
Quote:

Originally Posted by SaM.ThE.MaN (Post 1324472)
what do you mean ...

I mean that the task doesnt execute on specific user, its just executed globally. So you must either set_task in function bound by players index or use the way above.

SaM.ThE.MaN 10-14-2010 08:53

Re: Adding up
 
Quote:

Originally Posted by Ryokin (Post 1324477)
there's no index in that func, you need to check
PHP Code:

for (new i=0i<get_maxplayersi++)
{
   if ...



Added that and am getting an error :
PHP Code:

 ErrorSyntax error in the expression, or invalid function call on line 104 


SaM.ThE.MaN 10-14-2010 09:05

Re: Adding up
 
Ugh he missed this ()

Anyways even when i did this :

PHP Code:

public IncreaseNumber(id)
{
    for(new 
i=0i<get_maxplayers(); i++)
    {
        if(
is_user_connected(id) )
        {
            
g_Number[id] = Number 10
        
}
    }


NO diff ... still the same ...

SpeeDeeR 10-14-2010 10:19

Re: Adding up
 
I must ask you do you have any idea of what you are doing and why should it be done like that ?
This is one way of doing it.
PHP Code:

public IncreaseNumber() 

    for(new 
id=0id<get_maxplayers(); id++) 
    { 
        if(
is_user_connected(id) ) 
            
g_Number[id] += 10
         




SaM.ThE.MaN 10-14-2010 10:37

Re: Adding up
 
Quote:

Originally Posted by SpeeDeeR (Post 1324538)
I must ask you do you have any idea of what you are doing and why should it be done like that ?
This is one way of doing it.
PHP Code:

public IncreaseNumber() 

    for(new 
id=0id<get_maxplayers(); id++) 
    { 
        if(
is_user_connected(id) ) 
            
g_Number[id] = Number 10 
         




nothing is happening O.o

SpeeDeeR 10-14-2010 10:49

Re: Adding up
 
try now


All times are GMT -4. The time now is 10:20.

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