AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with passing an array by set_task (https://forums.alliedmods.net/showthread.php?t=113335)

[PUPPETS] Scooter 12-25-2009 14:52

Problem with passing an array by set_task
 
Hello,
I've got a problem with passing a Steam-ID from one function to another one by set_task. Here's my code:

Code:

public check_manual(id, level, cid)
{
 ...
 new header_connect[4]
 
 header_connect[0] = id
 format(header_connect[1], 31 ,"%s", player_steam)
 // Point1
 console_print(id, header_connect[1])
 header_connect[2] = player_exists
 header_connect[3] = player_id
 
 set_task(1.0, "connect_web", id, header_connect, 4)
 ...
}
 
public connect_web(arg[])
{
...
 //Point2
 console_print(id,arg[1])
...
}

At Point1 I get (as it should be):
STEAM_0:0:1234

But in connect_web at Point2, it's reduced to:
S_M

If I replace 4 in set_task by 80, I get:
S_MAM_0:0:1234

Why do I get S_MAM.. instead of STEAM and why do I have to increase array size in set_task?

Thanks for your help,
Scooter

ehha 12-25-2009 18:23

Re: Problem with passing an array by set_task
 
http://forums.alliedmods.net/showpos...5&postcount=11
Yeah, increase it so it can contain all your data in a long string.
Does player_id contain the full steamid?

[PUPPETS] Scooter 12-26-2009 07:44

Re: Problem with passing an array by set_task
 
Thank you for the link. After putting everything in one array, it works fine.

That's my new code:
Code:

new header_connect[80]
 header_connect[0] = id //id of admin
 header_connect[1] = player_exists //victim on server?
 header_connect[10] = player_id //id of victim
 format(header_connect[20], 31 ,"%s", player_steam) //victim's steam-id

id and player_id are integers, player_exists is bool and player_steam contains one steam-id.

Bugsy 12-26-2009 08:33

Re: Problem with passing an array by set_task
 
Quote:

Originally Posted by [PUPPETS] Scooter (Post 1031705)
Thank you for the link. After putting everything in one array, it works fine.

That's my new code:
Code:

new header_connect[80]
 header_connect[0] = id //id of admin
 header_connect[1] = player_exists //victim on server?
 header_connect[10] = player_id //id of victim
 format(header_connect[20], 31 ,"%s", player_steam) //victim's steam-id

id and player_id are integers, player_exists is bool and player_steam contains one steam-id.

Here's a more organized\readable way to do this:
PHP Code:

enum _:ConnectHeader
{
    
iPlayerID,
    
bool:bPlayerExists,
    
iVictimID
    
szSteamID35 ]
}

public 
client_putinserverid )
{
    new 
chDataConnectHeader ];

    
chDataiPlayerID ] = id;
    
chDatabPlayerExists ] = true;
    
chDataiVictimID ] = -1;
    
get_user_authidid chDataszSteamID ] , 34 );

    
set_task7.0 "ShowData" id chData sizeofchData ) );
}

public 
ShowDatachData[] , id )
{
    
client_printid print_chat "iPlayerID=%d bPlayerExists=%d iVictimID=%d szSteamID=%s" chDataiPlayerID ] , chDatabPlayerExists ] , chDataiVictimID ] , chDataszSteamID ] );



[PUPPETS] Scooter 01-06-2010 10:21

Re: Problem with passing an array by set_task
 
I finally had time to test your version, it also works great and is easier to handle. Thanks.

ÜnLoCo 06-01-2010 23:34

Re: Problem with passing an array by set_task
 
this is useful thank you guys !!!!
:twisted: i had to say it !


All times are GMT -4. The time now is 04:17.

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