ScriptingExamples/GameCommand: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Revision as of 16:55, 3 February 2019
Description
This code adds a blue chat message to the chat box for all players, displaying the game name that the player typing the message is playing, when any player types /game
Code
Lua, Server-Side:
addCommandHandler('game', function(cmd, args, client)
message(client.player.name .. ' is playing ' .. getGameNameFromGameId(client.game), COLOUR_BLUE)
end)
function getGameNameFromGameId(gameId)
if gameId == GAME_GTA_III then return 'GTA III'
elseif gameId == GAME_GTA_VC then return 'GTA VC'
elseif gameId == GAME_GTA_SA then return 'GTA SA'
elseif gameId == GAME_GTA_UG then return 'GTA Underground'
elseif gameId == GAME_GTA_IV then return 'GTA IV'
end
return 'Unknown Game'
end
JavaScript, Server-Side:
addCommandHandler("game", function(cmd, args, client) {
message(client.player.name + " is playing " + getGameNameFromGameId(client.game), COLOUR_BLUE);
});
function getGameNameFromGameId(gameId) {
switch(gameId) {
case GAME_GTA_III:
return "GTA III";
case GAME_GTA_VC:
return "GTA Vice City";
case GAME_GTA_SA:
return "GTA San Andreas";
case GAME_GTA_UG:
return "GTA Underground";
case GAME_GTA_IV:
return "GTA IV";
}
return "Unknown Game";
}
Squirrel, Server-Side:
addCommandHandler("game", function(cmd, args, client) {
message(client.player.name + " is playing " + getGameNameFromGameId(client.game), COLOUR_BLUE);
});
function getGameNameFromGameId(gameId) {
switch(gameId) {
case GAME_GTA_III:
return "GTA III";
case GAME_GTA_VC:
return "GTA Vice City";
case GAME_GTA_SA:
return "GTA San Andreas";
case GAME_GTA_UG:
return "GTA Underground";
case GAME_GTA_IV:
return "GTA IV";
}
return "Unknown Game";
}