File size: 26,653 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 |
typedef Param7<EntityAI, string, float, float, bool, string, FindInventoryLocationType> DevSpawnItemParams;//(target, item_name, health, quantity, special, presetName, locationType );
class PluginDeveloper extends PluginBase
{
protected bool m_IsWinHolding;
protected int m_FeaturesMask;
UIScriptedMenu m_ScriptConsole;
static PluginDeveloper GetInstance()
{
return PluginDeveloper.Cast( GetPlugin( PluginDeveloper ) );
}
//! Set Player position at his cursor position in the world
void TeleportAtCursor()
{
DeveloperTeleport.TeleportAtCursorEx();
}
//! Teleport player at position
void Teleport(PlayerBase player, vector position)
{
DeveloperTeleport.SetPlayerPosition(player, position);
}
//! Enable / Disable Free camera (Fly mod)
void ToggleFreeCameraBackPos()
{
DeveloperFreeCamera.FreeCameraToggle( PlayerBase.Cast( GetGame().GetPlayer() ), false );
}
//! Enable / Disable Free camera (Fly mod) - disable of camera will teleport player at current free camera position.
void ToggleFreeCamera()
{
DeveloperFreeCamera.FreeCameraToggle( PlayerBase.Cast( GetGame().GetPlayer() ), true );
}
bool IsEnabledFreeCamera()
{
return DeveloperFreeCamera.IsFreeCameraEnabled();
}
// System Public Events
void PluginDeveloper()
{
}
override void OnInit()
{
super.OnInit();
DeveloperFreeCamera.OnInit();
}
void OnRPC(PlayerBase player, int rpc_type, ParamsReadContext ctx)
{
#ifdef DIAG_DEVELOPER
switch (rpc_type)
{
case ERPCs.DEV_RPC_SPAWN_ITEM_ON_GROUND:
{
OnRPCSpawnEntityOnGround(player, ctx); break;
}
case ERPCs.DEV_RPC_SPAWN_ITEM_ON_GROUND_PATTERN_GRID:
{
OnRPCSpawnEntityOnGroundPatternGrid(player, ctx); break;
}
case ERPCs.DEV_RPC_SPAWN_ITEM_ON_CURSOR:
{
OnRPCSpawnEntityOnCursorDir(player, ctx); break;
}
case ERPCs.DEV_RPC_SPAWN_ITEM_IN_INVENTORY:
{
OnRPCSpawnEntity(player, ctx); break;
}
case ERPCs.DEV_RPC_CLEAR_INV:
{
OnRPCClearInventory(player); break;
}
case ERPCs.DEV_RPC_SEND_SERVER_LOG:
{
OnRPCServerLogRecieved( ctx ); break;
}
case ERPCs.RPC_SYNC_SCENE_OBJECT:
{
OnRPCSyncSceneObject( ctx ); break;
}
case ERPCs.DEV_RPC_PLUGIN_DZCREATURE_DEBUG:
{
OnRPCPluginDayzCreatureDebug(player, rpc_type, ctx); break;
}
case ERPCs.DEV_RPC_SPAWN_PRESET:
{
string presetName;
EntityAI target;
ctx.Read(presetName);
ctx.Read(target);
HandlePresetSpawn(player,presetName, target); break;
}
case ERPCs.DEV_RPC_SET_TIME:
{
HandleSetTime(player,ctx); break;
}
}
DeveloperTeleport.OnRPC(player, rpc_type, ctx);
#endif
}
// Public API
// Send Print to scripted console
void PrintLogClient(string msg_log)
{
if ( g_Game.GetUIManager().IsMenuOpen(MENU_SCRIPTCONSOLE) )
{
Param1<string> msg_p = new Param1<string>(msg_log);
CallMethod(CALL_ID_SCR_CNSL_ADD_PRINT, msg_p);
}
}
// Server Log Synch: Server Side
void SendServerLogToClient(string msg)
{
if ( GetGame() )
{
array<Man> players = new array<Man>;
GetGame().GetPlayers( players );
for ( int i = 0; i < players.Count(); ++i )
{
Param1<string> param = new Param1<string>( msg );
Man player = players.Get(i);
if ( player && player.HasNetworkID() )
{
player.RPCSingleParam(ERPCs.DEV_RPC_SEND_SERVER_LOG, param, true, player.GetIdentity());
}
}
}
}
void OnRPCSyncSceneObject( ParamsReadContext ctx )
{
Param3<string, EntityAI, Param> par = new Param3<string, EntityAI, Param>( "", NULL, new Param );
if ( ctx.Read( par ) )
{
PluginSceneManager module_scene_editor = PluginSceneManager.Cast( GetPlugin( PluginSceneManager ) );
SceneData scene_data = module_scene_editor.GetLoadedScene();
SceneObject scene_object = scene_data.GetSceneObjectByEntityAI( par.param2 );
GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallByName( scene_object, par.param1, par.param3 );
}
}
void OnRPCPluginDayzCreatureDebug(PlayerBase player, int rpc_type, ParamsReadContext ctx)
{
PluginDayZCreatureAIDebug pluginDZCreatureDebug = PluginDayZCreatureAIDebug.Cast( GetPlugin( PluginDayZCreatureAIDebug ) );
if (pluginDZCreatureDebug)
{
pluginDZCreatureDebug.OnRpc(player, rpc_type, ctx);
}
}
void HandleSetTime(PlayerBase player, ParamsReadContext ctx)
{
#ifdef DEVELOPER
Param5<int,int,int,int,int> p5 = new Param5<int,int,int,int,int>(0,0,0,0,0);
if ( ctx.Read( p5 ) )
{
//float time01 = p5.param4 / 100;
//int time_minutes = Math.Lerp(0, 24*60, time01 );
int year = p5.param1;
int month = p5.param2;
int day = p5.param3;
int hour = p5.param4;
int minute = p5.param5;
GetGame().GetWorld().SetDate(year,month, day, hour, minute);
/*
Debug.Log("year:" + year);
Debug.Log("month:" + month);
Debug.Log("day:" + day);
Debug.Log("hour:" + hour);
Debug.Log("minute:" + minute);
*/
}
#endif
}
void HandlePresetSpawn(PlayerBase player, string presetName, EntityAI target)
{
#ifdef DEVELOPER
PlayerBase targetPlayer = player;
if (target)
{
targetPlayer = PlayerBase.Cast(target);
}
if (!targetPlayer)
return;
targetPlayer.m_PresetSpawned = true;
string class_name = presetName + "_Preset";
typename type = class_name.ToType();
if (type)
{
PresetSpawnBase presetObj = PresetSpawnBase.Cast(type.Spawn());
if (presetObj)
{
presetObj.Init(targetPlayer);
}
}
#endif
}
// RPC Events
// Server Log Synch: Client Side
void OnRPCServerLogRecieved(ParamsReadContext ctx)
{
Param1<string> param = new Param1<string>( "" );
if ( ctx.Read(param) && param.param1 != "" )
{
Debug.ReceivedLogMessageFromServer(param.param1);
}
}
void OnRPCClearInventory(PlayerBase player)
{
ClearInventory(player);
}
// Client -> Server Spawning: Server Side
void OnRPCSpawnEntityOnCursorDir(PlayerBase player, ParamsReadContext ctx)
{
Param7<string, float, float, float, bool, string, bool> p = new Param7<string, float, float, float, bool, string, bool>("", 0, 0, 0, false, "", false);
if ( ctx.Read(p) )
{
SpawnEntityOnCursorDir(player, p.param1, p.param2, p.param3, p.param4, p.param5, p.param6, p.param7);
}
}
void OnRPCSpawnEntityOnGround(PlayerBase player, ParamsReadContext ctx)
{
Param6<string, float, float, vector, bool, bool> p = new Param6<string, float, float, vector, bool, bool>("", 0, 0, "0 0 0", false, false);
if ( ctx.Read(p) )
{
SpawnEntityOnGroundPos(player, p.param1, p.param2, p.param3, p.param4, p.param5, p.param6);
}
}
void OnRPCSpawnEntityOnGroundPatternGrid(PlayerBase player, ParamsReadContext ctx)
{
auto p = new Param10<string,int, float, float, int, int, float, float, bool, bool>("",0,0,0,0,0,0,0, false, false);
if ( ctx.Read(p) )
{
SpawnEntityOnGroundPatternGrid(player, p.param1, p.param2, p.param3, p.param4, p.param5, p.param6, p.param7, p.param8, p.param9, p.param10);
}
}
void OnRPCSpawnEntity(PlayerBase player, ParamsReadContext ctx)
{
#ifdef DEVELOPER
DevSpawnItemParams p = new DevSpawnItemParams(null,"", 0, 0, false, "", FindInventoryLocationType.ANY);
if ( ctx.Read(p) )
{
EntityAI target = EntityAI.Cast(p.param1);
PlayerBase playerTarget = PlayerBase.Cast(target);
EntityAI ent = SpawnEntityInInventory( target, p.param2, p.param3, p.param4, p.param5, "", p.param7);
if (playerTarget && p.param5)
{
if (playerTarget.m_PresetSpawned)
{
playerTarget.m_PresetSpawned = false;
playerTarget.m_PresetItems.Clear();
}
if (ent)
{
playerTarget.m_PresetItems.Insert(ent);
}
}
}
#endif
}
void OnSetFreeCameraEvent( PlayerBase player, FreeDebugCamera camera )
{
DeveloperFreeCamera.OnSetFreeCameraEvent( player, camera );
}
void OnSpawnErrorReport (string name)
{
PrintString("PluginDeveloper.SpawnEntity() Warning- Cant spawn object: " + name);
//DumpStack();
PrintString("PluginDeveloper.SpawnEntity() Warning END");
}
void SetupSpawnedEntity(PlayerBase player, EntityAI entity, float health, float quantity = -1, bool special = false, string presetName = "")
{
#ifdef DEVELOPER
if (presetName && player.m_PresetSpawned)//this is how we ascertain this is the first item being spawned from a new preset after a previous preset was already spawned in
{
player.m_PresetItems.Clear();
player.m_PresetSpawned = false;//is set to 'true' elsewhere after all the items have been spawned in
}
if ( entity.IsInherited( PlayerBase ) )
{
PlayerBase plr = PlayerBase.Cast( entity );
plr.OnSpawnedFromConsole();
}
else if ( entity.IsInherited(ItemBase) )
{
ItemBase item = ItemBase.Cast( entity );
SetupSpawnedItem(item, health, quantity);
}
else if (entity.IsInherited(House))
{
entity.PlaceOnSurface();
vector pos = entity.GetPosition();
vector ori = GetGame().GetSurfaceOrientation(pos[0], pos[2]);
entity.SetOrientation(ori);
}
if (presetName)
{
player.m_PresetItems.Insert(entity);
}
if ( special )
{
auto debugParams = DebugSpawnParams.WithPlayer(player);
entity.OnDebugSpawnEx(debugParams);
}
#endif
}
void SpawnEntityOnGroundPatternGrid( PlayerBase player, string item_name, int count, float health, float quantity, int rows, int columns, float gapRow = 1, float gapColumn = 1, bool special= false, bool withPhysics = false)
{
if (!item_name)
{
return;
}
if ( GetGame().IsServer() )
{
float rowDist = 0;
float columnDist = 0;
vector playerPos = player.GetPosition();
vector camDirForward = player.GetDirection();
vector camDirRight = camDirForward.Perpend() * -1;
int countLoop = 0;
for (int i = 0; i < rows; i++)
{
vector posRow = playerPos + camDirForward * rowDist;
vector offsetSide;
columnDist = 0;
for (int j = 0; j < columns; j++)
{
offsetSide = camDirRight * columnDist;
vector placement = posRow + offsetSide;
float hlth = health * MiscGameplayFunctions.GetTypeMaxGlobalHealth( item_name );
EntityAI ent = SpawnEntityOnGroundPos(player, item_name, hlth, quantity, placement, special );
ent.PlaceOnSurface();
InventoryItem item;
if (Class.CastTo(item, ent) && withPhysics)
item.ThrowPhysically(null, "0 0 0");
countLoop++;
if (countLoop == count)
{
return;
}
columnDist += gapColumn;
}
rowDist += gapRow;
}
}
else
{
auto params = new Param10<string, int, float, float, int, int, float, float, bool, bool>(item_name, count, health, quantity, rows, columns, gapRow, gapColumn, special, withPhysics);
player.RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_ON_GROUND_PATTERN_GRID, params, true);
}
}
void SpawnItemOnCrosshair(notnull PlayerBase player, string itemName, float health, float quantity, float maxDist = 100, bool allowFreeflight = false, bool special = false, bool withPhysics = false)
{
vector from, to;
if (allowFreeflight && FreeDebugCamera.GetInstance().IsActive())
{
from = FreeDebugCamera.GetInstance().GetPosition();
to = from + FreeDebugCamera.GetInstance().GetDirection() * maxDist;
}
else
{
from = GetGame().GetCurrentCameraPosition();
to = from + GetGame().GetCurrentCameraDirection() * maxDist;
}
float hitFraction;
vector start, end;
vector direction;
vector hitPos, hitNormal;
Object obj;
PhxInteractionLayers hitMask = PhxInteractionLayers.BUILDING | PhxInteractionLayers.DOOR | PhxInteractionLayers.VEHICLE | PhxInteractionLayers.ROADWAY | PhxInteractionLayers.TERRAIN | PhxInteractionLayers.CHARACTER | PhxInteractionLayers.AI | PhxInteractionLayers.RAGDOLL | PhxInteractionLayers.RAGDOLL_NO_CHARACTER;
DayZPhysics.RayCastBullet(from, to, hitMask, player, obj, hitPos, hitNormal, hitFraction);
// something is hit
if (hitPos != vector.Zero)
{
SpawnEntityOnGroundPos(player, itemName, health, quantity, hitPos, special, withPhysics);
}
}
/**
* @fn SpawnEntityOnGroundPos
* @brief spawns entity on exact position
* @param[in] health \p health of the item
* @param[in] quantity \p quantity to set if item.HasQuantity() (-1 == set to max)
* @param[in] pos \p position where to spawn
* @return entity if ok, null otherwise
**/
EntityAI SpawnEntityOnGroundPos( PlayerBase player, string item_name, float health, float quantity, vector pos, bool special = false, bool withPhysics = false)
{
if ( GetGame().IsServer() )
{
EntityAI entity = player.SpawnEntityOnGroundPos(item_name, pos);
if (entity)
SetupSpawnedEntity(player, entity, health, quantity, special);
else
OnSpawnErrorReport(item_name);
InventoryItem item;
if (Class.CastTo(item, entity) && withPhysics)
item.ThrowPhysically(null, "0 0 0");
return entity;
}
else
{
Param6<string, float, float, vector, bool, bool> params = new Param6<string, float, float, vector, bool, bool>(item_name, health, quantity, pos, special, withPhysics);
player.RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_ON_GROUND, params, true);
}
return NULL;
}
/**
* @fn SpawnEntityOnCursorDir
* @brief spawns entity in direction of cursor at specified distance
* @param[in] health \p health of the item
* @param[in] quantity \p quantity to set if item.HasQuantity() (-1 == set to max)
* @param[in] distance \p distance of the item from player
* @return entity if ok, null otherwise
**/
EntityAI SpawnEntityOnCursorDir( PlayerBase player, string item_name, float quantity, float distance, float health = -1, bool special = false, string presetName = "", bool withPhysics = false)
{
if ( GetGame().IsServer() )
{
// Client -> Server Spawning: Server Side
EntityAI entity = player.SpawnEntityOnGroundOnCursorDir(item_name, distance);
if ( entity )
{
if ( !entity.IsBuilding() && health < 0 && entity.GetMaxHealth() > 0)//check for default (-1)
{
health = entity.GetMaxHealth();
}
SetupSpawnedEntity( player,entity, health, quantity, special, presetName );
}
else
OnSpawnErrorReport( item_name );
InventoryItem item;
if (Class.CastTo(item, entity) && withPhysics)
item.ThrowPhysically(null, "0 0 0");
return entity;
}
else
{
// Client -> Server Spawning: Client Side
Param7<string, float, float, float, bool, string, bool> params = new Param7<string, float, float, float, bool, string, bool>(item_name, quantity, distance, health, special, presetName, withPhysics);
player.RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_ON_CURSOR, params, true);
}
return NULL;
}
/**
* @fn SpawnEntityInInventory
* @brief tries to spawn item somewhere in inventory
*
* SpawnEntityInInventory queries future parent about free inventory location of the future item
*
* @param[in] health \p health of the item
* @param[in] quantity \p quantity to set if item.HasQuantity() (-1 == set to max)
* @return entity if ok, null otherwise
**/
EntityAI SpawnEntityInInventory( notnull EntityAI target, string className, float health, float quantity, bool special = false, string presetName = "", FindInventoryLocationType locationType = FindInventoryLocationType.ANY)
{
if (target.IsPlayer())
{
return SpawnEntityInPlayerInventory(PlayerBase.Cast(target), className, health, quantity, special, presetName, locationType);
}
if ( GetGame().IsServer() )
{
InventoryLocation il = new InventoryLocation;
if (target.GetInventory() && target.GetInventory().FindFirstFreeLocationForNewEntity(className, FindInventoryLocationType.ANY, il))
{
EntityAI eai = SpawnEntity(className, il, ECE_IN_INVENTORY, RF_DEFAULT);
if ( eai && eai.IsInherited(ItemBase) )
{
if ( health < 0 )//check for default (-1)
{
health = eai.GetMaxHealth();
}
ItemBase i = ItemBase.Cast( eai );
SetupSpawnedItem(i, health, quantity);
if ( special )
{
auto debugParams = DebugSpawnParams.WithPlayer(null);
eai.OnDebugSpawnEx(debugParams);
}
}
return eai;
}
}
else
{
DevSpawnItemParams params = new DevSpawnItemParams(target, className, health, quantity, special, presetName, 0 );
GetGame().GetPlayer().RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_IN_INVENTORY, params, true, GetGame().GetPlayer().GetIdentity());
}
return null;
}
EntityAI SpawnEntityInPlayerInventory(PlayerBase player, string item_name, float health, float quantity, bool special = false, string presetName = "", FindInventoryLocationType locationType = FindInventoryLocationType.ANY)
{
if ( player )
{
if ( GetGame().IsServer() )
{
if (locationType == FindInventoryLocationType.HANDS && player.GetItemInHands())
{
if (!GetGame().IsMultiplayer())
player.DropItem(player.GetItemInHands());
else
player.ServerDropEntity(player.GetItemInHands());
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(SpawnEntityInPlayerInventory,100, false, player, item_name, health, quantity, special, presetName, locationType);
return null;
}
#ifdef DEVELOPER
if (GetGame().IsKindOf(item_name, "Transport"))
{
EntityAI car = SpawnEntityOnGroundPos(player, item_name, 1, quantity, player.GetPosition());
auto debugParams = DebugSpawnParams.WithPlayer(player);
car.OnDebugSpawnEx(debugParams);
if (GetGame().IsMultiplayer())
{
DayZPlayerSyncJunctures.SendGetInCar(player, car);
}
else
{
player.SetGetInVehicleDebug(car);
}
return car;
}
#endif
InventoryLocation il = new InventoryLocation;
if (player.GetInventory() && player.GetInventory().FindFirstFreeLocationForNewEntity(item_name, locationType, il))
{
Weapon_Base wpn = Weapon_Base.Cast(il.GetParent());
bool is_mag = il.GetSlot() == InventorySlots.MAGAZINE || il.GetSlot() == InventorySlots.MAGAZINE2 || il.GetSlot() == InventorySlots.MAGAZINE3;
if (wpn && is_mag)
{
vector pos = player.GetPosition();
EntityAI eai_gnd = SpawnEntityOnGroundPos(player, item_name, health, quantity, pos);
Magazine mag_gnd = Magazine.Cast(eai_gnd);
if (mag_gnd && player.GetWeaponManager().CanAttachMagazine(wpn, mag_gnd))
{
player.GetWeaponManager().AttachMagazine(mag_gnd);
}
return eai_gnd;
}
else
{
EntityAI eai = SpawnEntity(item_name, il, ECE_IN_INVENTORY, RF_DEFAULT);
if ( eai && eai.IsInherited(ItemBase) )
{
if ( health < 0 )//check for default (-1)
{
health = eai.GetMaxHealth();
}
ItemBase i = ItemBase.Cast( eai );
SetupSpawnedItem(i, health, quantity);
if ( special )
{
auto debugParams2 = DebugSpawnParams.WithPlayer(player);
eai.OnDebugSpawnEx(debugParams2);
}
}
return eai;
}
}
else
OnSpawnErrorReport(item_name);
return NULL;
}
else
{
// Client -> Server Spawning: Client Side
DevSpawnItemParams params = new DevSpawnItemParams(player, item_name, health, quantity, special, presetName, locationType );
player.RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_IN_INVENTORY, params, true);
}
}
return NULL;
}
/**
* @fn SpawnEntityAsAttachment
* @brief tries to spawn item as attachment
* @param[in] health \p health of the item
* @param[in] quantity \p quantity to set if item.HasQuantity() (-1 == set to max)
* @return entity if ok, null otherwise
**/
EntityAI SpawnEntityAsAttachment (PlayerBase player, EntityAI parent, string att_name, float health, float quantity)
{
if ( GetGame().IsServer() )
{
Weapon_Base wpn = Weapon_Base.Cast(parent);
if (wpn)
{
GameInventory inventory = parent.GetInventory();
return inventory.CreateInInventory(att_name);
/*
vector pos = player.GetPosition();
EntityAI eai_gnd = SpawnEntityOnGroundPos(player, att_name, health, quantity, pos);
Magazine mag_gnd = Magazine.Cast(eai_gnd);
if (mag_gnd && player.GetWeaponManager().CanAttachMagazine(wpn, mag_gnd))
{
player.GetWeaponManager().AttachMagazine(mag_gnd);
}
return eai_gnd;
*/
}
else
{
EntityAI eai = parent.GetInventory().CreateAttachment(att_name);
if (eai)
{
if ( eai.IsInherited(ItemBase) )
{
ItemBase i = ItemBase.Cast( eai );
SetupSpawnedItem(ItemBase.Cast( eai ), health, quantity);
}
return eai;
}
else
OnSpawnErrorReport(att_name);
}
return NULL;
}
else
{
// Client -> Server Spawning: Client Side
Param3<string, float, float> params = new Param3<string, float, float>(att_name, health, quantity);
player.RPCSingleParam(ERPCs.DEV_RPC_SPAWN_ITEM_AS_ATTACHMENT, params, true);
}
return NULL;
}
EntityAI SpawnFromClipboard()
{
UIScriptedMenu menu_curr = GetGame().GetUIManager().GetMenu();
if ( menu_curr == NULL )
{
PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
if ( player )
{
if ( !GetGame().GetWorld().Is3rdPersonDisabled() )
{
player.SetIsInThirdPerson(!player.IsInThirdPerson());//this counters the effect of switching camera through pressing the 'V' key
}
vector pos_player = player.GetPosition();
// Get item from clipboard
string clipboard;
GetGame().CopyFromClipboard(clipboard);
if (!clipboard.Contains(","))
{
//single item
if (DeveloperFreeCamera.IsFreeCameraEnabled())
SpawnItemOnCrosshair(player, clipboard.Trim(), -1, 1, 40, true );
else
SpawnEntityOnCursorDir(player, clipboard.Trim(), 1, 1);
}
else
{
TStringArray items = new TStringArray;
clipboard.Split( ",", items );
foreach (string item:items)
{
if (DeveloperFreeCamera.IsFreeCameraEnabled())
SpawnItemOnCrosshair(player, item.Trim(), -1, 1, 40, true );
else
SpawnEntityOnCursorDir(player, item.Trim(), 1, 1);
}
}
}
}
return NULL;
}
// Clear Entity Inventory
void ClearInventory(EntityAI entity)
{
if ( GetGame().IsServer() )
{
entity.ClearInventory();
}
else
{
Param1<int> params = new Param1<int>(0);
entity.RPCSingleParam(ERPCs.DEV_RPC_CLEAR_INV, params, true);
}
}
void ToggleHelpScreen()
{
if ( g_Game.GetUIManager().GetMenu() == NULL )
{
g_Game.GetUIManager().EnterScriptedMenu(MENU_HELP_SCREEN, NULL);
}
else if ( g_Game.GetUIManager().IsMenuOpen(MENU_HELP_SCREEN) )
{
g_Game.GetUIManager().Back();
}
}
void ToggleScriptConsole()
{
if (GetGame() != null && !g_Game.IsLoading() && GetGame().GetMission())
{
if ( g_Game.GetUIManager().GetMenu() == NULL )
{
m_ScriptConsole = g_Game.GetUIManager().EnterScriptedMenu(MENU_SCRIPTCONSOLE, NULL);
GetGame().GetMission().AddActiveInputExcludes({"menu"});
}
else if ( g_Game.GetUIManager().IsMenuOpen(MENU_SCRIPTCONSOLE) )
{
g_Game.GetUIManager().Back();
GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
}
}
}
// Mission Editor
void ToggleMissionLoader()
{
if ( g_Game.GetUIManager().IsMenuOpen(MENU_MISSION_LOADER) )
{
g_Game.GetUIManager().Back();
GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
return;
}
if ( g_Game.GetUIManager().GetMenu() )
g_Game.GetUIManager().GetMenu().Close();
g_Game.GetUIManager().EnterScriptedMenu(MENU_MISSION_LOADER, NULL);
GetGame().GetMission().AddActiveInputExcludes({"menu"});
}
// Script Editor History
private void ScriptHistoryNext()
{
// Console key press
if ( g_Game.GetUIManager().IsMenuOpen(MENU_SCRIPTCONSOLE) )
{
CallMethod(CALL_ID_SCR_CNSL_HISTORY_NEXT, NULL);
}
}
private void ScriptHistoryBack()
{
// Console key press
if ( g_Game.GetUIManager().IsMenuOpen(MENU_SCRIPTCONSOLE) )
{
CallMethod(CALL_ID_SCR_CNSL_HISTORY_BACK, NULL);
}
}
private bool IsIngame()
{
UIScriptedMenu menu_curr = GetGame().GetUIManager().GetMenu();
if ( menu_curr == NULL )
{
return true;
}
return false;
}
private bool IsInConsole()
{
UIScriptedMenu menu_curr = GetGame().GetUIManager().GetMenu();
if ( menu_curr != NULL && menu_curr.GetID() == MENU_SCRIPTCONSOLE )
{
return true;
}
return false;
}
// Tools
int QuickSortPartition( TStringArray arr, int left, int right )
{
string pivot = arr.Get( left );
int i = left;
int j = right + 1;
string temp;
while ( true )
{
while ( true )
{
i++;
if ( i > right || arr.Get(i) > pivot )
{
break;
}
}
while ( true )
{
j--;
if ( arr.Get(j) <= pivot )
{
break;
}
}
if ( i >= j )
{
break;
}
temp = arr.Get( i );
arr.Set( i, arr.Get(j) );
arr.Set( j, temp );
}
temp = arr.Get( left );
arr.Set( left, arr.Get(j) );
arr.Set( j, temp );
return j;
}
void QuickSort( TStringArray arr, int left, int right )
{
int j;
if ( left < right )
{
j = QuickSortPartition( arr, left, right );
QuickSort( arr, left, j - 1 );
QuickSort( arr, j + 1, right );
}
}
void SortStringArray( TStringArray arr )
{
QuickSort( arr, 0, arr.Count() - 1 );
}
void ResetGUI()
{
if ( GetGame() && GetGame().GetMission() )
{
GetGame().GetMission().ResetGUI();
}
}
static void SetDeveloperItemClientEx(notnull Object entity, bool getFocus = false)
{
PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
if (getFocus)
{
GetGame().GetInput().ChangeGameFocus(1);
GetGame().GetUIManager().ShowUICursor(true);
}
if (GetGame().IsMultiplayer())
{
GetGame().RPCSingleParam(GetGame().GetPlayer(), ERPCs.DEV_SET_DEV_ITEM, new Param1<Object>(entity), true, GetGame().GetPlayer().GetIdentity());
}
else
{
PluginItemDiagnostic mid2 = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic));
mid2.RegisterDebugItem(entity, player);
}
#ifdef DEVELOPER
SetDebugDeveloper_item(entity);
#endif
}
void SetDeveloperItemClient()
{
#ifdef DEVELOPER
Object entity;
PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
FreeDebugCamera debugCam = FreeDebugCamera.GetInstance();
if (debugCam && debugCam.GetCurrentCamera())
{
entity = debugCam.GetCrosshairObject();
}
else
{
if (player && player.GetActionManager())
{
ActionTarget at = player.GetActionManager().FindActionTarget();
entity = at.GetObject();
}
}
if (entity)
{
SetDeveloperItemClientEx(entity, true);
}
#endif
}
} |