This site has been archived and made available for preservation purposes. No edits can be made.

NukaScript Fallout 3

(Difference between revisions)
Return to current revision
  1.  
    This script uses a timer to check for the player being in a special area. If the player is in that area and is sneaking, he will find a hidden nuka cola.[image]NukaScript.jpg|thumb|right|NukaScript in-game[/image]
    [h="2"] Code [/h]
    [highlight=cpp]
  2. -
    #include "../vaultscript.h"
    #include <map>
  3. +
    #include "vaultscript.h"
  4.  
    #include <cstdio>

    using namespace std;
    using namespace vaultmp;

    Base nuka = (Base) 0x0001519E;
    Value area[] = {-12630.32, -15715.93, -12728.72, -15834.46};
  5. -
    map<ID, State> player_nuka;
  6. +
    IDSet player_nuka;
  7.  

  8. -
    Result VAULTSCRIPT NukaArea()
  9. +
    Result VAULTSCRIPT NukaArea() noexcept
  10.  
    {
  11. -
    for (pair<const ID, State>& player : player_nuka)
  12. +
    IDVector players = GetList(Type::ID_PLAYER);

    for (const ID& id : players)
  13.  
    {
  14. -
    if (!player.second && GetActorSneaking(player.first))
  15. +
    if (!player_nuka.count(id) && GetActorSneaking(id))
  16.  
    {
    Value X, Y, Z;
  17. -
    GetPos(player.first, X, Y, Z);
  18. +
    GetPos(id, X, Y, Z);
  19.  

    if (X < area[0] && X > area[2] && Y < area[1] && Y > area[3])
    {
  20. -
    UIMessage(player.first, "You found a hidden nuka cola!");
    AddItem(player.first, nuka, 1, 100.0, False);
    player.second = True;
  21. +
    UIMessage(id, "You found a hidden nuka cola!");
    AddItem(id, nuka, 1, 100.0, False);
    player_nuka.insert(id);
  22.  
    }
    }
    }
  23. -

  24. +

  25.  
    return (Result) 0;
    }

  26. -
    Void VAULTSCRIPT exec()
  27. +
    Void VAULTSCRIPT exec() noexcept
  28.  
    {
    if (GetGameCode() != Index::FALLOUT3)
    {
    printf("NukaScript is for Fallout 3 only!\n");
    terminate();
    }

    CreateTimer(&NukaArea, (Interval) 500);

    printf("NukaScript for Fallout 3 loaded\n");
    }

  29. -
    Void VAULTSCRIPT OnPlayerDisconnect(ID player, Reason reason)
  30. +
    Void VAULTSCRIPT OnPlayerDisconnect(ID player, Reason reason) noexcept
  31.  
    {
    player_nuka.erase(player);
    }

  32. -
    Void VAULTSCRIPT OnSpawn(ID object)
  33. +
    Void VAULTSCRIPT OnSpawn(ID object) noexcept
  34.  
    {
  35. -
    if (IsPlayer(object))
  36. +
    player_nuka.erase(object);
    }
    [/highlight]
    [category]Script examples[/category]
    [highlight=c]
    #include <vaultmp>

    #define MAX_PLAYERS (4)
    new PlayerID[MAX_PLAYERS] = [0,...];

    new nuka = 0x0001519E,
    Float:area[] = [-12630.32,-15715.93,-12728.72,-15834.46],
    bool:event[MAX_PLAYERS] = [false,...];

    main()
    {
    if(GetMaximumPlayers() > MAX_PLAYERS) printf("Error, your MAX_PLAYERS is too low! Required: %d",GetMaximumPlayers());
    switch(GetGameCode())
  37.  
    {
  38. -
    player_nuka.erase(object);
    player_nuka.insert(pair<ID, State>(object, False));
  39. +
    case FALLOUT3:
    {
    printf("NukaScript for Fallout 3loaded\n");
    CreateTimer("NukaSpot",1000);
    }
    default: printf("NukaScript is for Fallout 3 only!\n");
    }
    }

    public OnPlayerDisconnect(ID, reason)
    {
    new conID = GetConnection(ID);
    event[conID] = false;
    PlayerID[conID] = 0;
    }

    forward NukaSpot();
    public NukaSpot()
    {
    for (new i; i<MAX_PLAYERS; i++)
    {
    new ID = PlayerID[i];
    if(ID == 0 || event[i] || !GetActorSneaking(ID)) continue;
    new Float:x,Float:y,Float:z;
    GetPos(ID,x,y,z);
    if (x < area[0] && x > area[2] && y < area[1] && y > area[3])
    {
    UIMessage(ID,"You found a hidden nuka cola!");
    AddItem(ID,nuka,1,100.0,Bool:false);
    event[i] = true;
    }
  40.  
    }
  41. +
    return 1;
  42.  
    }
  43. -
    [/highlight]
    [h="2"] Explanation [/h]
    [category]Script examples[/category]
  44. +
    [/highlight]