forked from Mirrors/openclonk
Add cleared and respawn user callback actions to parkour goal and checkpoints
parent
e39b314239
commit
8ec12d8490
|
@ -248,11 +248,12 @@ protected func CheckForClonks()
|
|||
// If already done by player -> continue.
|
||||
if (ClearedByPlayer(plr))
|
||||
continue;
|
||||
var is_first_clear = (GetIndexOf(cleared_by_plr, true) < 0);
|
||||
// Check checkpoint status.
|
||||
if (cp_mode & PARKOUR_CP_Check)
|
||||
{
|
||||
var team_clear = !ClearedByTeam(team);
|
||||
ClearCPForPlr(plr);
|
||||
ClearCPForPlr(plr, is_first_clear);
|
||||
if (ClearedByTeam(team) && team_clear)
|
||||
cp_con->AddTeamClearedCP(team, this); // Notify parkour goal.
|
||||
}
|
||||
|
@ -264,31 +265,40 @@ protected func CheckForClonks()
|
|||
if (team)
|
||||
{
|
||||
if (ClearedByTeam(team))
|
||||
cp_con->PlayerReachedFinishCP(plr, this); // Notify parkour goal.
|
||||
cp_con->PlayerReachedFinishCP(plr, this, is_first_clear); // Notify parkour goal.
|
||||
else
|
||||
cp_con->AddPlayerClearedCP(plr, this); // Notify parkour goal.
|
||||
cp_con->AddPlayerClearedCP(plr, this, is_first_clear); // Notify parkour goal.
|
||||
}
|
||||
else
|
||||
{
|
||||
cp_con->PlayerReachedFinishCP(plr, this); // Notify parkour goal.
|
||||
cp_con->PlayerReachedFinishCP(plr, this, is_first_clear); // Notify parkour goal.
|
||||
}
|
||||
}
|
||||
// Check bonus.
|
||||
if (cp_mode & PARKOUR_CP_Bonus)
|
||||
GameCall("GivePlrBonus", plr, this);
|
||||
// User callback
|
||||
if (is_first_clear) UserAction->EvaluateAction(on_first_cleared, this, clonk, plr);
|
||||
UserAction->EvaluateAction(on_cleared, this, clonk, plr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Checkpoint callback if someone respawns here
|
||||
private func OnPlayerRespawn(object clonk, int plr)
|
||||
{
|
||||
return UserAction->EvaluateAction(on_respawn, this, clonk, plr);
|
||||
}
|
||||
|
||||
// Clear this checkpoint for the player, and possibly its team members.
|
||||
private func ClearCPForPlr(int plr)
|
||||
private func ClearCPForPlr(int plr, bool is_first_clear)
|
||||
{
|
||||
if (!(cp_mode & PARKOUR_CP_Check))
|
||||
return;
|
||||
var plrid = GetPlayerID(plr);
|
||||
cleared_by_plr[plrid] = true;
|
||||
Sound("UI::Cleared", false, 100, plr);
|
||||
cp_con->AddPlayerClearedCP(plr, this); // Notify parkour goal.
|
||||
cp_con->AddPlayerClearedCP(plr, this, is_first_clear); // Notify parkour goal.
|
||||
// Also clear for team members if the checkpoint is not PARKOUR_CP_Team.
|
||||
var team = GetPlayerTeam(plr);
|
||||
if (team && !(cp_mode & PARKOUR_CP_Team))
|
||||
|
@ -300,7 +310,7 @@ private func ClearCPForPlr(int plr)
|
|||
var test_plr_id = GetPlayerID(test_plr);
|
||||
cleared_by_plr[test_plr_id] = true;
|
||||
Sound("UI::Cleared", false, 100, test_plr);
|
||||
cp_con->AddPlayerClearedCP(test_plr, this); // Notify parkour goal.
|
||||
cp_con->AddPlayerClearedCP(test_plr, this, false, true); // Notify parkour goal.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -471,6 +481,13 @@ public func SaveScenarioObject(props)
|
|||
|
||||
/* Editor */
|
||||
|
||||
// Editor action callbacks
|
||||
local on_cleared, on_first_cleared, on_respawn;
|
||||
|
||||
public func SetOnCleared(v) { on_cleared=v; return true; }
|
||||
public func SetOnFirstCleared(v) { on_first_cleared=v; return true; }
|
||||
public func SetOnRespawn(v) { on_respawn=v; return true; }
|
||||
|
||||
// Inividual mode getting/setting functions (for editor)
|
||||
public func SetCPRespawn(bool to_val) { return SetCPMode((GetCPMode() & ~PARKOUR_CP_Respawn) | (PARKOUR_CP_Respawn * !!to_val)); }
|
||||
public func SetCPCheck(bool to_val) { return SetCPMode((GetCPMode() & ~PARKOUR_CP_Check) | (PARKOUR_CP_Check * !!to_val)); }
|
||||
|
@ -561,6 +578,9 @@ public func Definition(def)
|
|||
def.EditorProps.check = { Type="bool", Name="$Check$", EditorHelp="$CheckHelp$", AsyncGet="GetCPCheck", Set="SetCPCheck" };
|
||||
def.EditorProps.ordered = { Type="bool", Name="$Ordered$", EditorHelp="$OrderedHelp$", AsyncGet="GetCPOrdered", Set="SetCPOrdered" };
|
||||
def.EditorProps.team = { Type="bool", Name="$Team$", EditorHelp="$TeamHelp$", AsyncGet="GetCPTeam", Set="SetCPTeam" };
|
||||
def.EditorProps.on_cleared = new UserAction.Prop { Name="$OnCleared$", EditorHelp="$OnClearedHelp$", SaveAsCall="SetOnCleared" };
|
||||
def.EditorProps.on_first_cleared = new UserAction.Prop { Name="$OnFirstCleared$", EditorHelp="$OnFirstClearedHelp$", SaveAsCall="SetOnFirstCleared" };
|
||||
def.EditorProps.on_respawn = new UserAction.Prop { Name="$OnRespawn$", EditorHelp="$OnRespawnHelp$", SaveAsCall="SetOnRespawn" };
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,3 +27,9 @@ Ordered=Sortiert
|
|||
OrderedHelp=Ob dieser Checkpoint in der richtigen Reihenfolge erreicht werden muss.
|
||||
Team=Team
|
||||
TeamHelp=Ob alle Spieler eines Teams diesen Checkpoint erreichen muessen.
|
||||
OnCleared=Aktion: CP erreicht
|
||||
OnClearedHelp=Aktion, die ausgefuehrt wird, wenn ein Spieler diesen Checkpoint freischaltet.
|
||||
OnFirstCleared=Aktion: CP erstmals erreicht
|
||||
OnFirstClearedHelp=Aktion, die ausgefuehrt wird, wenn der erste Spieler diesen Checkpoint freischaltet.
|
||||
OnRespawn=Aktion: Respawn
|
||||
OnRespawnHelp=Aktion, die ausgefuehrt wird, wenn ein Spieler an diesem Checkpoint neu startet.
|
||||
|
|
|
@ -27,3 +27,9 @@ Ordered=Sorted
|
|||
OrderedHelp=Whether this checkpoint must be reached in order.
|
||||
Team=Team
|
||||
TeamHelp=Whether all players of a team need to reach this checkpoint.
|
||||
OnCleared=Action: CP reached
|
||||
OnClearedHelp=Action to be executed once for each player who clears this checkpoint.
|
||||
OnFirstCleared=Action: CP reached first
|
||||
OnFirstClearedHelp=Action to be executed when the first player clears this checkpoint.
|
||||
OnRespawn=Aktion: Respawn
|
||||
OnRespawnHelp=Action to be executed when a player respawns at this checkpoint.
|
||||
|
|
|
@ -148,7 +148,7 @@ public func TransferContentsOnRelaunch(bool on)
|
|||
/*-- Checkpoint interaction --*/
|
||||
|
||||
// Called from a finish CP to indicate that plr has reached it.
|
||||
public func PlayerReachedFinishCP(int plr, object cp)
|
||||
public func PlayerReachedFinishCP(int plr, object cp, bool is_first_clear)
|
||||
{
|
||||
if (finished)
|
||||
return;
|
||||
|
@ -162,6 +162,8 @@ public func PlayerReachedFinishCP(int plr, object cp)
|
|||
SetEvalData(plr);
|
||||
EliminatePlayers(plr);
|
||||
finished = true;
|
||||
if (is_first_clear) UserAction->EvaluateAction(on_checkpoint_first_cleared, this, cp, plr);
|
||||
UserAction->EvaluateAction(on_checkpoint_cleared, this, cp, plr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -176,13 +178,18 @@ public func SetPlayerRespawnCP(int plr, object cp)
|
|||
}
|
||||
|
||||
// Called from a check CP to indicate that plr has cleared it.
|
||||
public func AddPlayerClearedCP(int plr, object cp)
|
||||
public func AddPlayerClearedCP(int plr, object cp, bool is_first_clear, bool is_team_auto_clear)
|
||||
{
|
||||
if (finished)
|
||||
return;
|
||||
var plrid = GetPlayerID(plr);
|
||||
plr_list[plrid]++;
|
||||
UpdateScoreboard(plr);
|
||||
if (!is_team_auto_clear) // No callback if only auto-cleared for other team members after another player cleared it
|
||||
{
|
||||
if (is_first_clear) UserAction->EvaluateAction(on_checkpoint_first_cleared, this, cp, plr);
|
||||
UserAction->EvaluateAction(on_checkpoint_cleared, this, cp, plr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -414,7 +421,7 @@ protected func OnClonkDeath(object clonk, int killed_by)
|
|||
{
|
||||
var plr = clonk->GetOwner();
|
||||
// Only respawn if required and if the player still exists.
|
||||
if (no_respawn_handling || !GetPlayerName(plr))
|
||||
if (no_respawn_handling || !GetPlayerName(plr) || GetCrewCount(plr))
|
||||
return;
|
||||
var new_clonk = CreateObjectAbove(Clonk, 0, 0, plr);
|
||||
new_clonk->MakeCrewMember(plr);
|
||||
|
@ -427,6 +434,10 @@ protected func OnClonkDeath(object clonk, int killed_by)
|
|||
GameCall("OnPlayerRespawn", plr, FindRespawnCP(plr));
|
||||
// Log message.
|
||||
Log(RndRespawnMsg(), GetPlayerName(plr));
|
||||
// Respawn actions
|
||||
var cp = FindRespawnCP(plr);
|
||||
UserAction->EvaluateAction(on_respawn, this, clonk, plr);
|
||||
if (cp) cp->OnPlayerRespawn(new_clonk, plr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -692,6 +703,24 @@ private func AddEvalData(int plr)
|
|||
}
|
||||
|
||||
|
||||
/* Editor */
|
||||
|
||||
local on_checkpoint_cleared, on_checkpoint_first_cleared, on_respawn;
|
||||
|
||||
public func SetOnCheckpointCleared(v) { on_checkpoint_cleared=v; return true; }
|
||||
public func SetOnCheckpointFirstCleared(v) { on_checkpoint_first_cleared=v; return true; }
|
||||
public func SetOnRespawn(v) { on_respawn=v; return true; }
|
||||
|
||||
public func Definition(def)
|
||||
{
|
||||
_inherited(def);
|
||||
if (!def.EditorProps) def.EditorProps = {};
|
||||
def.EditorProps.on_checkpoint_cleared = new UserAction.Prop { Name="$OnCleared$", EditorHelp="$OnClearedHelp$", SaveAsCall="SetOnCheckpointCleared" };
|
||||
def.EditorProps.on_checkpoint_first_cleared = new UserAction.Prop { Name="$OnFirstCleared$", EditorHelp="$OnFirstClearedHelp$", SaveAsCall="SetOnCheckpointFirstCleared" };
|
||||
def.EditorProps.on_respawn = new UserAction.Prop { Name="$OnRespawn$", EditorHelp="$OnRespawnHelp$", SaveAsCall="SetOnRespawn" };
|
||||
}
|
||||
|
||||
|
||||
/*-- Proplist --*/
|
||||
|
||||
local Name = "$Name$";
|
||||
|
|
|
@ -29,3 +29,11 @@ MsgEvalPlrWon=%s has won the parkour in %s.
|
|||
MsgEvalTeamWon=The team %s has won the parkour in %s.
|
||||
MsgEvalPlayerX=You have cleared %d out of %d checkpoints.
|
||||
MsgEvalPlayerAll=You have cleared all checkpoints.
|
||||
|
||||
#Editor
|
||||
OnCleared=Aktion: CP erreicht
|
||||
OnClearedHelp=Aktion, die ausgefuehrt wird, wenn ein Spieler einen Checkpoint freischaltet.
|
||||
OnFirstCleared=Aktion: CP erstmals erreicht
|
||||
OnFirstClearedHelp=Aktion, die ausgefuehrt wird, wenn der erste Spieler einen Checkpoint freischaltet.
|
||||
OnRespawn=Aktion: Respawn
|
||||
OnRespawnHelp=Aktion, die ausgefuehrt wird, wenn ein Spieler an einem Checkpoint neu startet.
|
||||
|
|
|
@ -29,3 +29,11 @@ MsgEvalPlrWon=%s has won the parkour in %s.
|
|||
MsgEvalTeamWon=The team %s has won the parkour in %s.
|
||||
MsgEvalPlayerX=You have cleared %d out of %d checkpoints.
|
||||
MsgEvalPlayerAll=You have cleared all checkpoints.
|
||||
|
||||
#Editor
|
||||
OnCleared=Action: CP reached
|
||||
OnClearedHelp=Action to be executed once for each player who clears a checkpoint.
|
||||
OnFirstCleared=Action: CP reached first
|
||||
OnFirstClearedHelp=Action to be executed when the first player clears a checkpoint.
|
||||
OnRespawn=Aktion: Respawn
|
||||
OnRespawnHelp=Action to be executed when a player respawns at a checkpoint.
|
||||
|
|
Loading…
Reference in New Issue