NewbProgrammer
Unregistered
Код:
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;
}
Posts: 579
Threads: 5
Joined: Oct 2015
use data variable as an array to pass multiple values.
NewbProgrammer
Unregistered
29.06.2016, 13:07
(
Последний раз редактировалось NewbProgrammer; 29.06.2016 в 13:44.
)
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;
}