DayZ: Skrypt z poleceniami administratora (bez modów)

O skrypcie

Skrypt bazuje na kodzie umieszczonym na forum dayz ale podobno tamten nie działa.

Kod należy wkleić do pliku init.c w katalogu misji. Wklejamy go w zaznaczone miejsce:

class CustomMission: MissionServer
{
/* >>>>> w to miejsce wklej skrypt <<<<< */
	void SetRandomHealth(EntityAI itemEnt)
	{
		if ( itemEnt )
		{
			float rndHlt = Math.RandomFloat( 0.45, 0.65 );
			itemEnt.SetHealth01( "", "", rndHlt );
		}
	}

Kod skryptu

	bool verify_admins = true
	// false - każdy może wywoływać polecenia
	// true - tylko gracze z listy admins mogą wywoływać polecenia
	
	string cmd_prefix = "/"; // znak początku polecenia
	
	// lista steamID64 lub BI UID użytkowników, którzy mogą wywoływac polecenia
	// lista może zawierać jedno lub wiele ID
	// steamID64 można znaleźć tutaj: steamid.io
	ref TStringArray admins = {"0000000000000"};

	bool IsPlayerAnAdmin(PlayerBase player) {
		bool found = false;
		for ( int i = 0; i < admins.Count(); ++i ) {
			if(player.GetIdentity().GetId() == admins[i] || player.GetIdentity().GetPlainId() == admins[i]) { found=true; break; }
		}
		return found;
	}

	PlayerBase GetPlayer(string name) {
		PlayerBase p;
		array<Man> players = new array<Man>; GetGame().GetPlayers(players);
		for ( int i = 0; i < players.Count(); ++i ) {
			p = players.Get(i);
			if(p.GetIdentity().GetName() == name) return p;
		}
		return NULL;
	}

	void SendMessageToPlayer(PlayerBase player, string message) {
		Param1<string> param = new Param1<string>( message );
		GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, param, true, player.GetIdentity());
	}

	void RefuelNearPlayer(PlayerBase player)
	{
		ref array<Object> nearest_objects = new array<Object>;
		ref array<CargoBase> proxy_cargos = new array<CargoBase>;
		Car toBeFilled;
		vector position = player.GetPosition();
		GetGame().GetObjectsAtPosition ( position, 10, nearest_objects, proxy_cargos );

		for (int i = 0; i < nearest_objects.Count(); i++) {
			if (nearest_objects[i].IsKindOf("CarScript")) {
				SendMessageToPlayer(player, "[Refuel] Found car: '"+nearest_objects[i]+"'");
				toBeFilled = Car.Cast(nearest_objects[i]);
				float fuelReq = toBeFilled.GetFluidCapacity( CarFluid.FUEL ) - (toBeFilled.GetFluidCapacity( CarFluid.FUEL ) * toBeFilled.GetFluidFraction( CarFluid.FUEL ));
				float oilReq = toBeFilled.GetFluidCapacity( CarFluid.OIL ) - (toBeFilled.GetFluidCapacity( CarFluid.OIL ) * toBeFilled.GetFluidFraction( CarFluid.OIL ));
				float coolantReq = toBeFilled.GetFluidCapacity( CarFluid.COOLANT ) - (toBeFilled.GetFluidCapacity( CarFluid.COOLANT ) * toBeFilled.GetFluidFraction( CarFluid.COOLANT ));
				float brakeReq = toBeFilled.GetFluidCapacity( CarFluid.BRAKE ) - (toBeFilled.GetFluidCapacity( CarFluid.BRAKE ) * toBeFilled.GetFluidFraction( CarFluid.BRAKE ));
				toBeFilled.Fill( CarFluid.FUEL, fuelReq );
				toBeFilled.Fill( CarFluid.OIL, oilReq );
				toBeFilled.Fill( CarFluid.COOLANT, coolantReq );
				toBeFilled.Fill( CarFluid.BRAKE, brakeReq );
				SendMessageToPlayer(player, "[Refuel] "+fuelReq+"L added, all fluids maxed");
			}
		}
	}

	override void OnEvent(EventType eventTypeId, Param params)  {
		super.OnEvent(eventTypeId,params);
		int i;
		PlayerBase player, temp_player;
		array<Man> players = new array<Man>; GetGame().GetPlayers(players);
		if(eventTypeId != ChatMessageEventTypeID) return; // Is chat message
		ChatMessageEventParams chat_params = ChatMessageEventParams.Cast( params );
		if(chat_params.param1 != 0 || chat_params.param2 == "") return;
		player = GetPlayer(chat_params.param2);
		if(player == NULL) return;
		if(verify_admins && !IsPlayerAnAdmin(player)) { GetGame().AdminLog("[ADMCMD] (Unauthorized) " + player.GetIdentity().GetName() +" ("+player.GetIdentity().GetPlainId()+", "+player.GetIdentity().GetId()+") tried to execute "+ chat_params.param3); return; }
		string message = chat_params.param3, prefix, param0, command;
		TStringArray tokens = new TStringArray;
		message.Replace("` ", "&SPCESC!"); //Escape spaces before splitting
		message.Split(" ", tokens);
		int count = tokens.Count();

		for ( i = 0; i < count; ++i ) {
			message = tokens[i];
			message.Replace("&SPCESC!", " "); //.Replace doesn't work directly on TStringArray elements for some reason :(
			tokens[i] = message;
		}

		param0 = tokens.Get(0);
		param0.ParseStringEx(prefix); if(prefix != cmd_prefix) return;
		param0.ParseStringEx(command);
		GetGame().AdminLog("[ADMCMD] PLAYER: "+ player.GetIdentity().GetName() +" ("+player.GetIdentity().GetPlainId()+", "+player.GetIdentity().GetId()+") CMD: "+ command);
		switch(command) {
			case "spawn": {
				if(count != 2) { SendMessageToPlayer(player, "/spawn [object]"); return; }
				GetGame().CreateObject(tokens[1], player.GetPosition(), false, true );
				SendMessageToPlayer(player, "[ObjectSpawn] Object spawned: " + tokens[1]);
				break;
			}

			case "inv": {
				if(count != 2) { SendMessageToPlayer(player, "/inv [object]"); return; }
				player.GetInventory().CreateInInventory(tokens[1]);
				SendMessageToPlayer(player, "[ObjectSpawn] Object spawned in inventory: " + tokens[1]);
				break;
			}

			case "weapon": {
				if(count != 2) { SendMessageToPlayer(player, "/weapon [weapon]"); return; }
				EntityAI weapon;
				switch(tokens[1]) {
					case "ump": {
						weapon = player.GetHumanInventory().CreateInHands("UMP45");
						player.GetInventory().CreateInInventory("Mag_UMP_25Rnd");
						break;
					}

					case "cz61": {
						weapon = player.GetHumanInventory().CreateInHands("CZ61");
						player.GetInventory().CreateInInventory("Mag_CZ61_20Rnd");
						break;
					}

					case "mp5": {
						weapon = player.GetHumanInventory().CreateInHands("MP5K");
						weapon.GetInventory().CreateAttachment("MP5k_StockBttstck");
						weapon.GetInventory().CreateAttachment("MP5_PRailHndgrd");
						player.GetInventory().CreateInInventory("Mag_MP5_30Rnd");
						break;
					}

					case "svd": {
						weapon = player.GetHumanInventory().CreateInHands("SVD");
						weapon.GetInventory().CreateAttachment("PSO11Optic");
						player.GetInventory().CreateInInventory("Mag_SVD_10Rnd");
						break;
					}

					case "mp133": {
						weapon = player.GetHumanInventory().CreateInHands("Mp133Shotgun");
						player.GetInventory().CreateInInventory("Ammo_12gaPellets");
						break;
					}

					case "mosin": {
						weapon = player.GetHumanInventory().CreateInHands("Mosin9130");
						weapon.GetInventory().CreateAttachment("PUScopeOptic");
						player.GetInventory().CreateInInventory("Ammo_762x54");
						break;
					}

					case "m4": {
						weapon = player.GetHumanInventory().CreateInHands("M4A1_Black");
						weapon.GetInventory().CreateAttachment("M4_RISHndgrd_Black");
						weapon.GetInventory().CreateAttachment("M4_MPBttstck_Black");
						weapon.GetInventory().CreateAttachment("BUISOptic");
						player.GetInventory().CreateInInventory("Mag_STANAGCoupled_30Rnd");
						break;
					}

					case "akm": {
						weapon = player.GetHumanInventory().CreateInHands("AKM");
						weapon.GetInventory().CreateAttachment("AK_RailHndgrd");
						weapon.GetInventory().CreateAttachment("AK_PlasticBttstck");
						player.GetInventory().CreateInInventory("Mag_AKM_30Rnd");
						break;
					}

					case "izh18": {
						weapon = player.GetHumanInventory().CreateInHands("Izh18");
						player.GetInventory().CreateInInventory("Ammo_762x39");
						break;
					}

					case "fnx": {
						weapon = player.GetHumanInventory().CreateInHands("FNX45");
						player.GetInventory().CreateInInventory("Mag_FNX45_15Rnd");
						break;
					}

					default: {
						SendMessageToPlayer(player, "[WeaponSpawner] " + tokens[1] + " not found");
						break;
					}
				}
				break;
			}

			case "strip": {
				if(count != 2) { SendMessageToPlayer(player, "/strip [player]"); return; }
				temp_player = GetPlayer(tokens[1]);
				if(temp_player == NULL) {
					SendMessageToPlayer(player, "[Strip] Can't find player called: '"+tokens[1]+"'");
				} else {
					temp_player.RemoveAllItems();
					SendMessageToPlayer(player, "[Strip] You stripped " + temp_player.GetIdentity().GetName());
					SendMessageToPlayer(temp_player, "You have been stripped by an admin");
				}
				break;
			}

			case "slap": {
				if(count != 2) { SendMessageToPlayer(player, "/slap [player]"); return; }
				temp_player = GetPlayer(tokens[1]);
				if(temp_player == NULL) {
					SendMessageToPlayer(player, "[Slap] Can't find player called: '"+tokens[1]+"'");
				} else {
					temp_player.SetPosition(temp_player.GetPosition() + "0 3 0");
					SendMessageToPlayer(player, "[Slap] You stripped " + temp_player.GetIdentity().GetName());
					SendMessageToPlayer(temp_player, "You have been slapped by an admin");
				}
				break;
			}

			case "topos": {
				if (count < 3) { SendMessageToPlayer(player, "/topos [x] [y] (player)"); return; }
				float ATL_Z = GetGame().SurfaceY(tokens[1].ToFloat(), tokens[2].ToFloat());
				vector reqpos = Vector(tokens[1].ToFloat(), ATL_Z, tokens[2].ToFloat());
				temp_player = player;
				if (count == 4) {
					temp_player = GetPlayer(tokens[3]);
					if (temp_player == NULL) {
						SendMessageToPlayer(player, "[Teleport] Can't find player called: '"+tokens[3]+"'"); return;
					} else {
						SendMessageToPlayer(temp_player, "[Teleport] You've been teleported to " + reqpos + " by admin " + player.GetIdentity().GetName());
					}
				}
				temp_player.SetPosition(reqpos);
				SendMessageToPlayer(player, "[Teleport] Target teleported to " + temp_player.GetPosition());
				break;
			}

			case "goto": {
				if(count != 2) { SendMessageToPlayer(player, "/goto [player]"); return; }
				temp_player = GetPlayer(tokens[1]);
				if(temp_player == NULL) {
					SendMessageToPlayer(player, "[Teleport] Can't find player called: '"+tokens[1]+"'");
				} else {
					player.SetPosition(temp_player.GetPosition());
					SendMessageToPlayer(player, "[Teleport] You teleported to " + temp_player.GetIdentity().GetName());
				}
				break;
			}

			case "allgoto": {
				PlayerBase allgoto_target;
				if(count != 2) { SendMessageToPlayer(player, "/allgoto [player]"); return; }
				allgoto_target = GetPlayer(tokens[1]);
				if(allgoto_target == NULL) {
					SendMessageToPlayer(player, "[Teleport] Can't find player called: '"+tokens[1]+"'");
				} else {
					SendMessageToPlayer(player, "[Teleport] You teleported everyone to your location");
					for (i = 0; i < players.Count(); i++) {
						temp_player = players.Get(i);
						SendMessageToPlayer(temp_player, "[Teleport] You have been teleported to player " + allgoto_target.GetIdentity().GetName());
						temp_player.SetPosition(allgoto_target.GetPosition());
					}
				}
				break;
			}

			case "here": {
				if(count != 2) { SendMessageToPlayer(player, "/here [player]"); return; }
				temp_player = GetPlayer(tokens[1]);
				if(temp_player == NULL) {
					SendMessageToPlayer(player, "[Teleport] Can't find player called: '"+tokens[1]+"'");
				} else {
					temp_player.SetPosition(player.GetPosition());
					SendMessageToPlayer(temp_player, "[Teleport] You have been teleported to admin " + player.GetIdentity().GetName());
					SendMessageToPlayer(player, "[Teleport] You teleported " + temp_player.GetIdentity().GetName() + " to your location");
				}
				break;
			}

			case "allhere": {
				SendMessageToPlayer(player, "[Teleport] You teleported everyone to your location");
				for (i = 0; i < players.Count(); i++) {
					temp_player = players.Get(i);
					SendMessageToPlayer(temp_player, "[Teleport] You have been teleported to admin " + player.GetIdentity().GetName());
					temp_player.SetPosition(player.GetPosition());
				}
				break;
			}

			case "time": {
				if(count != 3) { SendMessageToPlayer(player, "/time [hour] [minute]"); return; }
				GetGame().GetWorld().SetDate( 2018, 7, 7, tokens[1].ToInt(), tokens[2].ToInt());
				SendMessageToPlayer(player, "[Servertime] You have set the servertime to " + tokens[1] + ":"+tokens[2]);
				break;
			}

			case "day": {
				GetGame().GetWorld().SetDate( 2018, 7, 7, 12, 0);
				SendMessageToPlayer(player, "[Servertime] You have set the servertime to daytime");
				break;
			}

			case "night": {
				GetGame().GetWorld().SetDate( 2018, 7, 7, 24, 0);
				SendMessageToPlayer(player, "[Servertime] You have set the servertime to daytime");
				break;
			}

			case "rain": {
				if(count != 2) { SendMessageToPlayer(player, "/rain [value 0-100]"); return; }
				float rain = tokens[1].ToFloat() / 100;
				GetGame().GetWeather().GetRain().Set(rain, 2, 600);
				SendMessageToPlayer(player, "[Weather] You have set Rain to " + tokens[1] + "% ["+rain+"]");
				break;
			}

			case "fog": {
				if(count != 2) { SendMessageToPlayer(player, "/fog [value 0-100]"); return; }
				float fog = tokens[1].ToFloat() / 100;
				GetGame().GetWeather().GetFog().Set(fog, 2, 600);
				SendMessageToPlayer(player, "[Weather] You have set Fog to " + tokens[1] + "% ["+fog+"]");
				break;
			}

			case "overcast": {
				if(count != 2) { SendMessageToPlayer(player, "/overcast [value 0-100]"); return; }
				float overcast = tokens[1].ToFloat() / 100;
				GetGame().GetWeather().GetOvercast().Set(overcast, 2, 600);
				SendMessageToPlayer(player, "[Weather] You have set Overcast to " + tokens[1] + "% ["+overcast+"]");
				break;
			}

			case "kill": {
				if(count == 2) {
					temp_player = GetPlayer(tokens[1]);
					if(temp_player == NULL) {
						SendMessageToPlayer(player, "[Kill] Can't find player called: '"+tokens[1]+"'");
					} else {
						temp_player.SetHealth(0);
						SendMessageToPlayer(player, "[Kill] You killed " + temp_player.GetIdentity().GetName());
					}
				} else {
					player.SetHealth(0);
					SendMessageToPlayer(player, "[Kill] You killed yourself");
				}
				break;
			}

			case "killall": {
				SendMessageToPlayer(player, "[Kill] You killed everyone");
				for (i = 0; i < players.Count(); i++) {
					temp_player = players.Get(i);
					if(temp_player.GetIdentity().GetId() == player.GetIdentity().GetId()) continue;
					temp_player.SetHealth(0);
				}
				break;
			}

			case "heal": {
				PlayerBase heal_target;
				if(count == 2) {
					heal_target = GetPlayer(tokens[1]);
					if(heal_target == NULL) {
						SendMessageToPlayer(player, "[Heal] Can't find player called: '"+tokens[1]+"'");
					} else {
						SendMessageToPlayer(player, "[Heal] You healed " + heal_target.GetIdentity().GetName());
					}
				} else {
					heal_target = player;
					SendMessageToPlayer(player, "[Heal] You healed yourself");
				}
				if(heal_target != NULL) {
					heal_target.SetHealth(heal_target.GetMaxHealth("", ""));
					heal_target.SetHealth("", "Blood", heal_target.GetMaxHealth("", "Blood"));
					heal_target.GetStatStamina().Set(1000);
					heal_target.GetStatEnergy().Set(1000);
					heal_target.GetStatWater().Set(1000);
				}
				break;
			}

			case "offroad": {
				TStringArray attArr = {
				"HatchbackWheel","HatchbackWheel","HatchbackWheel","HatchbackWheel","HatchbackWheel",
				"CarBattery","CarRadiator","EngineBelt","SparkPlug",
				"HatchbackHood","HatchbackTrunk","HatchbackDoors_Driver","HatchbackDoors_CoDriver",
				}; 
				
				Car v;
				float playerAngle = MiscGameplayFunctions.GetHeadingAngle(player);
				vector posModifier = Vector(-(3 * Math.Sin(playerAngle)), 0, 3 * Math.Cos(playerAngle));
				v = Car.Cast(GetGame().CreateObject( "OffroadHatchback", player.GetPosition() + posModifier));
				v.SetAllowDamage( false );

				EntityAI entity;
				for (int j = 0; j < attArr.Count(); j++)
				{
					entity = v.GetInventory().CreateAttachment( attArr.Get(j) );
					entity.SetAllowDamage( false );
				}
				RefuelNearPlayer(player);
				SendMessageToPlayer(player, "[Offroad] Vehicled spawned");
				break;
			}

			case "refuel": {
				RefuelNearPlayer(player);
				break;
			}

			case "repair": {
				ref array<Object> nearest_objects = new array<Object>;
				ref array<CargoBase> proxy_cargos = new array<CargoBase>;
				vector position = player.GetPosition();
				GetGame().GetObjectsAtPosition ( position, 10, nearest_objects, proxy_cargos );

				for (i = 0; i < nearest_objects.Count(); i++) {
					entity = EntityAI.Cast(nearest_objects[i]);
					if (entity && !entity.IsInherited(PlayerBase)) {
						entity.SetHealth("", "", 1.0);
						SendMessageToPlayer(player, "[Repair] Repaired: '"+entity+"'");
					}
				}

				break;
			}

			case "delete": {
				nearest_objects = new array<Object>;
				proxy_cargos = new array<CargoBase>;
				position = player.GetPosition();
				GetGame().GetObjectsAtPosition ( position, 10, nearest_objects, proxy_cargos );

				for (i = 0; i < nearest_objects.Count(); i++) {
					entity = EntityAI.Cast(nearest_objects[i]);
					if (entity && !entity.IsInherited(PlayerBase)) {
						if (entity.GetHierarchyParent() == null) {
							entity.Delete();
							SendMessageToPlayer(player, "[Delete] Deleted: '"+entity+"'");
						}
					}
				}

				break;
			}

			default: {
				SendMessageToPlayer(player, "Unknown command: " + command);
				break;
			}
		}
	}

Opis niektórych poleceń

  • /spawn <object> – tworzy obiekt danego typu object, typy obiektów można znaleźć w pliku types.xml
  • /inv <object> – tworzy obiekt wewnątrz inwentarza admina (gracza, który wywołuje polecenie)
  • /strip <player> – rozbiera wybranego gracza
  • /slap <player> – daje klapsa wybranemu graczowi
  • /topos <x> <y> – teleportuje admina do podanych koordynat na mapie
  • /topos <x> <y> <player> – teleportuje wybranego gracza do podanych koordynat na mapie
  • /goto <player> – teleportuje admina na miejsce wybranego gracza
  • /allgoto <player> – teleportuje wszystkich graczy na miejsce wybranego gracza
  • /here <player> – teleportuje wybranego gracza na pozycję admina
  • /allhere – teleportuje wszystkich graczy na pozycję admina
  • /time <hour> <minute> – ustawia czas na serwerze na dzień 2018-07-07 i podaną godzinę hour:minute
  • /day – ustawia czas na serwerze na dzień 2018-07-07 i godzinę 12:00
  • /night – ustawia czas na serwerze na dzień 2018-07-07 i godzinę 00:00
  • /rain <0-100> – ustawia poziom deszczu na podaną wartość (%)
  • /fog <0-100> – ustawia poziom mgły na podaną wartość (%)
  • /overcast <0-100> – ustawia poziom zachmurzenia na podaną wartość (%)
  • /kill <player> – uśmierca wybranego gracza
  • /kill – uśmierca admina 😉
  • /killall – uśmierca wszystkich graczy poza adminem
  • /heal – ulecza admina
  • /heal <player> – ulecza wybranego gracza
  • /offroad – tworzy pojazd terenowy ze wszystkimi dodatkami (akumulator, koła, drzwi, …)
  • /refuel – tankuje pojazdy znajdujące się blisko (3m) admina
  • /repair – naprawia obiekty znajdujące się blisko (10m) admina (możliwe, że nie działa)
  • /delete – usuwa !!!wszystkie!!! obiekty w pobliżu (10m) admina!!!

5 1 vote
Article Rating
Subscribe
Powiadom o
guest
0 komentarzy
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x