public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case DIALOG_ID_A : return RE_DIALOG_A(playerid, response, listitem, inputtext); case DIALOG_ID_B : return RE_DIALOG_B(playerid, response, listitem, inputtext); case DIALOG_ID_C : return RE_DIALOG_C(playerid, response, listitem, inputtext); case DIALOG_ID_D : return RE_DIALOG_D(playerid, response, listitem, inputtext); case DIALOG_ID_E : return RE_DIALOG_E(playerid, response, listitem, inputtext); case DIALOG_ID_F : return RE_DIALOG_F(playerid, response, listitem, inputtext); } return 1; }
This is not hooking in the normal sense and it is fact encouraged to do this because it improves readability. A single function (including callbacks) ideally consist of less than 20 lines.
|
isPlayerInVehicleA() {
if(IsPlayerInVehicle(playerid, vehicleid_A)) {
// do something...
return true;
}
return false;
}
isPlayerInVehicleB() {
if(IsPlayerInVehicle(playerid, vehicleid_B)) {
// do something...
return true;
}
return false;
}
public OnPlayerStateChange(playerid, newstate, oldstate) {
#if defined A_OnPlayerStateChange
A_OnPlayerStateChange(playerid, newstate, oldstate);
#endif
if(newstate == PLAYER_STATE_DRIVER)
isPlayerInVehicleA(playerid);
}
#if defined _ALS_OnPlayerStateChange
#undef OnPlayerStateChange
#else
#define _ALS_OnPlayerStateChange
#endif
#define OnPlayerStateChange A_OnPlayerStateChange
#if defined A_OnPlayerStateChange
forward A_OnPlayerStateChange(playerid, newstate, oldstate);
#endif
public OnPlayerStateChange(playerid, newstate, oldstate) {
#if defined B_OnPlayerStateChange
B_OnPlayerStateChange(playerid, newstate, oldstate);
#endif
if(newstate == PLAYER_STATE_DRIVER)
isPlayerInVehicleB(playerid)
}
#if defined _ALS_OnPlayerStateChange
#undef OnPlayerStateChange
#else
#define _ALS_OnPlayerStateChange
#endif
#define OnPlayerStateChange B_OnPlayerStateChange
#if defined B_OnPlayerStateChange
forward B_OnPlayerStateChange(playerid, newstate, oldstate);
#endif
public OnPlayerStateChange(playerid, newstate, oldstate) {
if(newstate == PLAYER_STATE_DRIVER)
if(isPlayerInVehicleA(playerid)) return;
if(isPlayerInVehicleB(playerid)) return;
return 1;
}