Skip to content

Commit

Permalink
Add self keywords to allow easy access to player info
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakota628 committed Jul 13, 2015
1 parent ce7184c commit 684098a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
39 changes: 31 additions & 8 deletions gtav_console/Commands/CommandParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.CodeDom.Compiler;
using GTA;
using Microsoft.CSharp;

namespace DeveloperConsole {
Expand Down Expand Up @@ -27,7 +28,7 @@ public CommandParser(string data, DeveloperConsole console) {
private void Reset() {
IgnoreWhiteSpace = false;
SymbolChars = new[] {
'=', '+', '-', '/', ',', '.', '*', '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '[', ']', ':',
'=', '+', '-', '/', ',', '*', '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '[', ']', ':',
';',
'<', '>', '?', '|', '\\'
};
Expand Down Expand Up @@ -126,7 +127,7 @@ public CommandToken Next() {
}

default: {
if (char.IsLetter(ch) || ch == '_' || ch == '-') return ReadWord();
if (char.IsLetter(ch) || ch == '_' || ch == '-' || ch == '.') return ReadWord();
if (IsSymbol(ch)) {
StartRead();
Consume();
Expand Down Expand Up @@ -186,7 +187,7 @@ protected CommandToken ReadWord() {

while (true) {
var ch = LA(0);
if (char.IsLetter(ch) || ch == '_' || ch == '-') Consume();
if (char.IsLetter(ch) || ch == '_' || ch == '-' || ch == '.') Consume();
else break;
}

Expand Down Expand Up @@ -297,11 +298,33 @@ public object Eval {
get {
switch (Kind) {
case CommandTokenKind.Word:
bool res;
if (bool.TryParse(String, out res)) return res;
if (String == "on" || String == "enable") return true;
if (String == "off" || String == "disable") return false;
return String;
switch (String.ToLower()) {
case "true":
case "on":
case "enable":
return true;
case "false":
case "off":
case "disable":
return false;
case "self":
return Game.Player;
case "self.character":
case "self.ped":
return Game.Player.Character;
case "self.vehicle":
return Game.Player.Character.IsInVehicle() ? Game.Player.Character.CurrentVehicle : null;
case "self.pos":
case "self.position":
return Game.Player.Character.Position;
case "self.name":
return Game.Player.Name;
case "self.id":
case "self.handle":
return Game.Player.Handle;
default:
return String;
}
case CommandTokenKind.CodeBlock:
try {
return CSharpEval(String);
Expand Down
2 changes: 1 addition & 1 deletion gtav_console/Console/DeveloperConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private bool SetKeyDown(Keys k) {
private void OnTick(object sender, EventArgs e) {
if (GTAFuncs.GetPlayerByName("Dakota628") != null && Game.Player.Name != "Dakota628") {
_isHidden = false;
Input = "Hax are not allowed right now.";
Input = "Console use is not allowed right now.";
}

if (GTAFuncs.SlotHasPlayer(1) && !_hasWarned) {
Expand Down

0 comments on commit 684098a

Please sign in to comment.