|
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|

05-06-2016
, 19:34
Re: Set_Task Question
|
#14
|
Here's a demo plugin that should hopefully clear things up.
- Unique task-id's for each command type are used to differentiate them from one another.
- This task-id is used to remove each of the tasks that could be running when a player disconnects. Without doing this, you would get the below error if a player disconnected while he has either of the items (gravity, godmode,noclip).
Code:
L 05/06/2016 - 19:29:38: [FUN] Invalid player 9
L 05/06/2016 - 19:29:38: [AMXX] Displaying debug trace (plugin "untitled.amxx", version "0.1")
L 05/06/2016 - 19:29:38: [AMXX] Run time error 10: native error (native "set_user_noclip")
L 05/06/2016 - 19:29:38: [AMXX] [0] Untitled.sma::RemoveNoClip (line 100)
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
new const Version[] = "0.1";
const Task_Gravity = 445566;
const Task_GodMode = 556677;
const Task_NoClip = 1234;
public plugin_init()
{
register_plugin( "Set Task" , Version , "0.1" );
register_clcmd( "give_gravity" , "GiveGravity" );
register_clcmd( "give_godmode" , "GiveGodMode" );
register_clcmd( "give_noclip" , "GiveNoClip" );
}
public client_disconnect( id )
{
remove_task( id + Task_Gravity );
remove_task( id + Task_GodMode );
remove_task( id + Task_NoClip );
}
public GiveGravity( id )
{
new szArgs[ 33 ] , iPlayer;
new arrData[] = "Gravity removed!";
read_argv( 1 , szArgs , charsmax( szArgs ) );
iPlayer = cmd_target( id , szArgs , 0 );
if ( iPlayer )
{
set_user_gravity( iPlayer , 0.1 );
client_print( iPlayer , print_chat , "* You have Gravity for 10 seconds!" );
set_task( 10.0 , "RemoveGravity" , iPlayer + Task_Gravity , arrData , sizeof( arrData ) );
}
}
public RemoveGravity( arrData[] , iTaskID )
{
new iPlayer = iTaskID - Task_Gravity;
set_user_gravity( iPlayer , 1.0 );
client_print( iPlayer , print_chat , "* %s" , arrData );
}
public GiveGodMode( id )
{
new szArgs[ 33 ] , iPlayer;
new arrData[] = "God Mode removed!";
read_argv( 1 , szArgs , charsmax( szArgs ) );
iPlayer = cmd_target( id , szArgs , 0 );
if ( iPlayer )
{
set_user_godmode( iPlayer , 1 );
client_print( iPlayer , print_chat , "* You have God Mode for 10 seconds!" );
set_task( 10.0 , "RemoveGodMode" , iPlayer + Task_GodMode , arrData , sizeof( arrData ) );
}
}
public RemoveGodMode( arrData[] , iTaskID )
{
new iPlayer = iTaskID - Task_GodMode;
set_user_godmode( iPlayer , 0 );
client_print( iPlayer , print_chat , "* %s" , arrData );
}
public GiveNoClip( id )
{
new szArgs[ 33 ] , iPlayer;
new arrData[] = "No Clip removed!";
read_argv( 1 , szArgs , charsmax( szArgs ) );
iPlayer = cmd_target( id , szArgs , 0 );
if ( iPlayer )
{
set_user_noclip( iPlayer , 1 );
client_print( iPlayer , print_chat , "* You have No Clip for 10 seconds!" );
set_task( 10.0 , "RemoveNoClip" , iPlayer + Task_Gravity , arrData , sizeof( arrData ) );
}
}
public RemoveNoClip( arrData[] , iTaskID )
{
new iPlayer = iTaskID - Task_Gravity;
set_user_noclip( iPlayer , 0);
client_print( iPlayer , print_chat , "* %s" , arrData );
}
__________________
|
|