Hey dataviruset,
I finished the basic race game and incorporated it into your Last Request portion of Hosties.
The trigger_* entities I wanted to use were all brush entities and so I couldn't use these so instead there's just a timer that checks how close each player is to the end point.
Also, some things I hadn't coded yet: a count-down to when race will begin (similar to the no-scope only players would be frozen during this time), stripping knives from race contestants, and adding translation support to the race PrintToChatAll statements.
PHP Code:
// Global vars
new Float:gV_StartRaceLocation[3];
new Float:gV_EndRaceLocation[3];
PHP Code:
// ConVar-stuff
new Handle:sm_hosties_lr_race_enable = INVALID_HANDLE;
OnPluginStart()
PHP Code:
sm_hosties_lr_race_enable = CreateConVar("sm_hosties_lr_race_enable", "1", "Enable or disable race option in last request");
OnConfigsExecuted()
PHP Code:
if (GetConVarInt(sm_hosties_lr_race_enable) == 1)
PushArrayCell(LRsenabled, 10);
Command_LastRequest
PHP Code:
if (GetConVarInt(sm_hosties_lr_race_enable) == 1)
{
decl String:lr_race[32];
Format(lr_race, sizeof(lr_race), "%T", "Race", client);
AddMenuItem(menu, "race", lr_race);
}
Inside MainHandler, added (param2 == 10) to the larger IF statement
and this inside that:
PHP Code:
else if (param2 == 10)
{
// create menu for T to choose start point
new Handle:racemenu1 = CreateMenu(RaceStartPointHandler);
SetMenuTitle(racemenu1, "Find a Starting Location");
AddMenuItem(racemenu1, "startloc", "Use current position");
SetMenuExitButton(racemenu1, true);
DisplayMenu(racemenu1, param1, MENU_TIME_FOREVER);
}
MainPlayerHandler
PHP Code:
case 10:
{
Format(lrname, sizeof(lrname), "%T", "Race", LRplayers[param2]);
}
Inside LaunchLR()
PHP Code:
case 10: // race option
{
// teleport both players to the start of the race
TeleportEntity(LRprogressplayer1, gV_StartRaceLocation, NULL_VECTOR, NULL_VECTOR);
TeleportEntity(LRprogressplayer2, gV_StartRaceLocation, NULL_VECTOR, NULL_VECTOR);
PrintToChatAll("\x03[V] \x01Race begins NOW!");
// make timer to check the race winner
CreateTimer(0.1, Timer_Race, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
PHP Code:
public RaceEndPointHandler(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
if (!LRblock)
{
if (!LRinprogress)
{
if (IsPlayerAlive(param1) && (GetClientTeam(param1) == CS_TEAM_T))
{
// use this location
GetClientAbsOrigin(param1, gV_EndRaceLocation);
gV_EndRaceLocation[2] += 10;
TE_SetupBeamRingPoint(gV_EndRaceLocation, 100.0, 130.0, BeamSprite, HaloSprite, 0, 15, 30.0, 7.0, 0.0, redColor, 1, 0);
TE_SendToAll();
// allow them to choose a player finally
CreateMainPlayerHandler(param1);
}
else
PrintToChat(param1, MESS, "Not Alive Or In Wrong Team");
}
else
PrintToChat(param1, MESS, "Too Slow Another LR In Progress");
}
else
PrintToChat(param1, MESS, "LR Not Available");
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
public RaceStartPointHandler(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
if (!LRblock)
{
if (!LRinprogress)
{
if (IsPlayerAlive(param1) && (GetClientTeam(param1) == CS_TEAM_T))
{
// use this location
GetClientAbsOrigin(param1, gV_StartRaceLocation);
gV_StartRaceLocation[2] += 10;
TE_SetupBeamRingPoint(gV_StartRaceLocation, 100.0, 130.0, BeamSprite, HaloSprite, 0, 15, 30.0, 7.0, 0.0, greyColor, 1, 0);
TE_SendToAll();
CreateRaceEndPointMenu(param1);
}
else
PrintToChat(param1, MESS, "Not Alive Or In Wrong Team");
}
else
PrintToChat(param1, MESS, "Too Slow Another LR In Progress");
}
else
PrintToChat(param1, MESS, "LR Not Available");
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
CreateRaceEndPointMenu(client)
{
new Handle:EndPointMenu = CreateMenu(RaceEndPointHandler);
SetMenuTitle(EndPointMenu, "Choose an End Point");
AddMenuItem(EndPointMenu, "endpoint", "Use Current Position");
SetMenuExitButton(EndPointMenu, true);
DisplayMenu(EndPointMenu, client, MENU_TIME_FOREVER);
}
public Action:Timer_Race(Handle:timer)
{
if ( (!IsClientInGame(LRprogressplayer1)) || (!IsPlayerAlive(LRprogressplayer1))
|| (!IsClientInGame(LRprogressplayer2)) || (!IsPlayerAlive(LRprogressplayer2)) )
{
return Plugin_Stop;
}
new Float:LRPlayer1Position[3];
new Float:LRPlayer2Position[3];
GetClientAbsOrigin(LRprogressplayer1, LRPlayer1Position);
GetClientAbsOrigin(LRprogressplayer2, LRPlayer2Position);
// check if how close they are to the end point
decl Float:distancePlayer1;
decl Float:distancePlayer2;
distancePlayer1 = GetVectorDistance(LRPlayer1Position, gV_EndRaceLocation, false);
distancePlayer2 = GetVectorDistance(LRPlayer2Position, gV_EndRaceLocation, false);
// the order dictates we give ties to the terrorist
// add a photo-finish random call later if they're both within the amount
if (distancePlayer1 < Float:130.0)
{
ForcePlayerSuicide(LRprogressplayer2);
PrintToChatAll("\x03[V] \x01%N has won the race!", LRprogressplayer1);
return Plugin_Stop;
}
else if (distancePlayer2 < Float:130.0)
{
ForcePlayerSuicide(LRprogressplayer1);
PrintToChatAll("\x03[V] \x01%N has won the race!", LRprogressplayer2);
return Plugin_Stop;
}
return Plugin_Continue;
}