GTA Vice-City: Cheats.

vitogta

  • Jr. Member
  • Posts: 55
GTA Vice-City: Cheats.
«  »Last edited
https://forum.vc-mp.org/?topic=6039.0
http://forum.vc-mp.org/?topic=3883.0

My version of this feature. Of course it would be much better to code it at clientside but since we started it as serverside:

Code: [Select]
cheats <- {
"keys" : "abcdefghijklmnopqrstuvwxyz",
"key_binds" : {},
"cheats" : {},
"key_stack" : {},
"init" : function(){
for(local i = 1; i < 27; i++){
this.key_binds.rawset(::BindKey(true, i+64, 0, 0), keys.slice(i-1, i));
}
for(local i = 0; i < 100; i++){
this.key_stack.rawset(i, {});
}
},
"set" : function(text, cheat){
this.cheats.rawset(text.tolower(), cheat);
for(local i = 0; i < 100; i++){
this.key_stack[i].rawset(text.tolower(), "");
}
},
"del" : function(text){
this.cheats.rawdelete(text.tolower());
for(local i = 0; i < 100; i++){
this.key_stack[i].rawdelete(text.tolower());
}
},
"key_down" : function(player, key){
if(this.key_binds.rawin(key)){
local i = player.ID;
local key = this.key_binds.rawget(key);
foreach(k, v in this.cheats){
local l = this.key_stack[i][k].len();
if((l < k.len()) && (key == k.slice(l, l+1))){
this.key_stack[i][k] += key;
} else {
local l2 = this.key_stack[i][k].len();
local key2 = this.key_stack[i][k].slice(l2 - 1, l2);
this.key_stack[i][k] = "";
if(key == k.slice(0, 1)){
this.key_stack[i][k] += key;
} else if(key2 == k.slice(0, 1)){
this.key_stack[i][k] += key2;
local l = this.key_stack[i][k].len();
if((l < k.len()) && (key == k.slice(l, l+1))){
this.key_stack[i][k] += key;
} else {
this.key_stack[i][k] = "";
}
} else {
this.key_stack[i][k] = "";
}
}
if(k == this.key_stack[i][k]){
this.key_stack[i][k] = "";
this.cheats[k].pcall(::getroottable(), player);
}
}
}
}
}

::cheats.init();

::cheats.set("ASPIRINE", function(player){
player.Health = 100;
player.Vehicle && player.Vehicle.Fix();
::Announce("Cheat activated", player, 0);
});

::cheats.set("BIGBANG", function(player){
for(local i = 0 ; i < 1000; i++){
local v = ::FindVehicle(i);
v && (v.Pos.Distance(player.Pos) < 300) && v.Kill();
}
::Announce("Cheat activated", player, 0);
});

function onKeyDown(player, key){
    ::cheats.key_down(player, key);
}
VCMP-139 As a scripter, I want to create client-side map markers, spheres, checkpoints, etc.
VCMP-29 Add per-world settings for weather, gravity, and other settings
VCMP-51 As a scripter, I want to be able to access datetime, sound, and timer functions on the client side

MEGAMIND

  • Sr. Member
  • Developer of "Web-Net" search engine
  • Posts: 457