AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   couple questions (https://forums.alliedmods.net/showthread.php?t=144300)

0x00 12-01-2010 18:56

couple questions
 
first of, whats wrong with the following check:

PHP Code:

public function(id)
    if(
cs_get_user_team(id) < 2)
        
// something 

the syntax of such native is pretty simple, i really can't see any mistake. anyway, in sourcepawn you could do the following:

PHP Code:

new string:temp[1024]

public function()
    switch(
something)
    {
        case 
1temp "my text"
        
case 2temp "my text 2"

        
// and so on
    


but you can't do the following on amxx, so please, tell me whats wrong.

PHP Code:

new temp[1024]

public function()
    switch(
something)
    {
        case 
1temp "my text"
        
case 2temp "my text 2"

        
// and so on
    


and the last question, whats wrong with:

PHP Code:

get_randplayer()
{
    
/*
    using get_players() because i really don't
    need to do any check, like teams, etc. so get_maxplayers()
    isnt really needed.
    */

    
new players[get_players() + 1], num
    
    
for(new 1<= get_maxplayers(); x++)
        if(
cs_get_user_team(x) > 1)
            
players[num++] = x
            
    
return (num == 0) ? - players[random_num(0num 1)]


it kept saying that it must be a constant, which does not happen on sourcepawn. ty.

Exolent[jNr] 12-01-2010 19:06

Re: couple questions
 
Quote:

Originally Posted by 0x00 (Post 1361157)
first of, whats wrong with the following check:

PHP Code:

public function(id)
    if(
cs_get_user_team(id) < 2)
        
// something 

That's a tag mismatch error.

the syntax of such native is pretty simple, i really can't see any mistake.

Either change 2 to CS_TEAM_CT, or untag the function.

Quote:

Originally Posted by 0x00 (Post 1361157)
anyway, in sourcepawn you could do the following:

PHP Code:

new temp[1024]

public function()
    switch(
something)
    {
        case 
1temp "my text"
        
case 2temp "my text 2"

        
// and so on
    


but you can't do the following on amxx, so please, tell me whats wrong.

You should use the copy() function.
PHP Code:

copy(temp1023"my text"

Quote:

Originally Posted by 0x00 (Post 1361157)
and the last question, whats wrong with:

PHP Code:

get_randplayer()
{
    
/*
    using get_players() because i really don't
    need to do any check, like teams, etc. so get_maxplayers()
    isnt really needed.
    */

    
new players[get_players() + 1], num
    
    
for(new 1<= get_maxplayers(); x++)
        if(
cs_get_user_team(x) > 1)
            
players[num++] = x
            
    
return (num == 0) ? - players[random_num(0num 1)]


it kept saying that it must be a constant, which does not happen on sourcepawn. ty.

You can't create an array of a dynamic size like that.
The size has to be a constant number at compile time.
Therefore, use 32 because it will always be big enough for all players.

0x00 12-01-2010 19:20

Re: couple questions
 
thanks.


All times are GMT -4. The time now is 11:26.

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