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

BarrelScript Fallout: New Vegas

(Difference between revisions)
Return to current revision
  1.  
    This script uses a timer to check for the player being near a special spot. If the player is near that spot and has a certain Z-angle, he will find a broken 9mm pistol.[image]barrel.jpg|thumb|right|BarrelScript in-game[/image]
    [h="2"] Code [/h]
    [highlight=cpp]
    #include "vaultscript.h"
    #include <cstdio>

    using namespace std;
    using namespace vaultmp;

    Base _9mm = (Base) 0x000E3778;
    Value spot[] = {-102.76, -398.82, 3458.55};
    Value angle[] = {93.0, 134.0};
    IDSet player_barrel;

    Result VAULTSCRIPT BarrelSpot()
    {
    IDVector players = GetList(Type::ID_PLAYER);

    for (const ID& id : players)
    {
    if (!player_barrel.count(id) && IsNearPoint(id, spot[0], spot[1], spot[2], 30.0))
    {
    Value X, Y, Z;
    GetAngle(id, X, Y, Z);

    if (Z > angle[0] && Z < angle[1])
    {
    UIMessage(id, "You found a broken 9mm pistol at the bottom of the barrel!");
    AddItem(id, _9mm, 1, 0.0, False);
    player_barrel.insert(id);
    }
    }
    }

    return (Result) 0;
    }

    Void VAULTSCRIPT exec()
    {
    if (GetGameCode() != Index::NEWVEGAS)
    {
    printf("BarrelScript is for Fallout: New Vegas only!\n");
    terminate();
    }

    CreateTimer(&BarrelSpot, (Interval) 500);

    printf("BarrelScript for Fallout: New Vegas loaded\n");
    }

    Void VAULTSCRIPT OnPlayerDisconnect(ID player, Reason reason)
    {
    player_barrel.erase(player);
    }

    Void VAULTSCRIPT OnSpawn(ID object)
    {
    player_barrel.erase(object);
    }
    [/highlight]
    [highlight=c]
    #include <vaultmp>

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

    new _9mm = 0x000E3778,
    Float:spot[] = [-102.76,-398.82,3458.55],
    Float:angle[] = [93.0,134.0],
    bool:event[MAX_PLAYERS] = [false,...];

    main()
    {
    if(GetMaximumPlayers() > MAX_PLAYERS) printf("Error, your MAX_PLAYERS is too low! Required: %d",GetMaximumPlayers());
    switch(GetGameCode())
    {
    case NEWVEGAS:
    {
    printf("BarrelScript for Fallout: New Vegas loaded\n");
    CreateTimer("BarrelSpot",1000);
    }
    default: printf("BarrelScript is for Fallout: New Vegas only!\n");
    }
    }

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

    public OnPlayerRequestGame(ID)
    {
    new conID = GetConnection(ID);
    PlayerID[conID] = ID;
    new base = 0x00000000;
    switch (GetGameCode())
    {
    case FALLOUT3: base = 0x00030D82; // Carter
    case NEWVEGAS: base = 0x0010C0BE; // Jessup
    }
    return base;
  3.  
    }

    forward BarrelSpot();
    public BarrelSpot()
    {
    for (new i; i<MAX_PLAYERS; i++)
    {
    new ID = PlayerID[i];
    if(ID == 0 || event[i]) continue;
    if(!IsNearPoint(ID,spot[0],spot[1],spot[2],30.0)) continue;
    new Float:x,Float:y,Float:z;
    GetAngle(ID,x,y,z);
    if(z > angle[0] && z < angle[1])
    {
    UIMessage(ID,"You found a broken 9mm pistol at the bottom of the barrel!");
    AddItem(ID,_9mm,1,0.0,Bool:false);
    event[i] = true;
    }
    }
    return 1;
    }
    [/highlight]
    [category]Script examples[/category]