sampgdk || SetTimerEx/SetTimer + params
#1

Hello all. Sorry for my bad english. But i'll try to speak it

Need the timer to send the playerid.
Function SetTimerEx does not exist. What function to use? Or how to send playerid via SetTimer?

Thx
Reply
#2

Код:
SetTimer(1000, false, YourTimerName, (void *) playerid);

// Somewhere else.
void SAMPGDK_CALL YourTimerName(int timerid, void *data) {
	int playerid = (int) data;

	// Do something with playerid.
}
How I used it:
Код:
void SAMPGDK_CALL SkipClassSelection(int timer_id, void *data) {
	int player_id = (int) data;

	TogglePlayerSpectating(player_id, false);
	SpawnPlayer(player_id);

	SetPlayerVirtualWorld(player_id, 0);
	SetPlayerInterior(player_id, 0);
	SetPlayerPos(player_id, 1957.7498f, 1343.0189f, 15.3746f);
	SetPlayerFacingAngle(player_id, 270.7008f);
	SetCameraBehindPlayer(player_id);
	return;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int player_id, int class_id) {
	TogglePlayerSpectating(player_id, true); // Do not show the player class selection controls.
	
	SetTimer(500, false, SkipClassSelection, (void *) player_id);
	return true;
}
Reply
#3

Quote:
Originally Posted by NewbProgrammer
Посмотреть сообщение
Код:
SetTimer(1000, false, YourTimerName, (void *) playerid);

// Somewhere else.
void SAMPGDK_CALL YourTimerName(int timerid, void *data) {
	int playerid = (int) data;

	// Do something with playerid.
}
How I used it:
Код:
void SAMPGDK_CALL SkipClassSelection(int timer_id, void *data) {
	int player_id = (int) data;

	TogglePlayerSpectating(player_id, false);
	SpawnPlayer(player_id);

	SetPlayerVirtualWorld(player_id, 0);
	SetPlayerInterior(player_id, 0);
	SetPlayerPos(player_id, 1957.7498f, 1343.0189f, 15.3746f);
	SetPlayerFacingAngle(player_id, 270.7008f);
	SetCameraBehindPlayer(player_id);
	return;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int player_id, int class_id) {
	TogglePlayerSpectating(player_id, true); // Do not show the player class selection controls.
	
	SetTimer(500, false, SkipClassSelection, (void *) player_id);
	return true;
}
Oh, Thank you!
And if want to pass multiple values?
Reply
#4

use data variable as an array to pass multiple values.
Reply
#5

Quote:
Originally Posted by VaReNiX
Посмотреть сообщение
Oh, Thank you!
And if want to pass multiple values?
This is where it gets a little complex.
You can pass a struct. (similar but not quite like a PAWN enum)
Код:
struct SCS_Data {
	int id;
	float spawn_x;
	float spawn_y;
	float spawn_z;
};

void SAMPGDK_CALL SkipClassSelection(int timer_id, void *data) {
	SCS_Data player = (SCS_Data) data;

	TogglePlayerSpectating(player.id, false);
	SpawnPlayer(player.id);

	SetPlayerVirtualWorld(player.id, 0);
	SetPlayerInterior(player.id, 0);
	SetPlayerPos(player.id, player.spawn_x, player.spawn_y, player.spawn_z);
	SetPlayerFacingAngle(player.id, 270.7008f);
	SetCameraBehindPlayer(player.id);
	return;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int player_id, int class_id) {
	SCS_Data data;
	
	data.id = player_id;
	data.spawn_x = 1957.7498f;
	data.spawn_y = 1343.0189f;
	data.spawn_z = 15.3746f;

	TogglePlayerSpectating(player_id, true); // Do not show the player class selection controls.
	
	SetTimer(500, false, SkipClassSelection, (void *) data);
	return true;
}
Reply
#6

Thanks for the help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)