1. For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
    Dismiss Notice

(Base mod) Idglibrary - a Library for Coders

Discussion in 'Works-in-Progress' started by IDGCaptainRussia, Sep 19, 2018.

  1. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    This mod, will be getting a proper github when SGAmod releases, and on that note

    I've been having quite a few people only wanting the code for their own mods.
    Please don't directly copy code from Idglib to avoid using it as a dependency
    I made this library largely from edited vanilla code, and what code I did borrow I have permission to use, if you really want to avoid using the library but use code from it please just credit me somewhere as well or write your own; this isn't asking much ;/
    If your taking like one function and leaving credit that's fine and I can understand that, but if you start taking several functions for the sole reason of the above, then we have a problem.

    Oh and, don't take the DrawSkeletronLikeArms and credit me, that code was made by @direwolf420 and you'd have to get his permission for it! I have permission to use it in IDGLib.

    If this continues I'll be forced to close-source not only this mod, but all my mods, and I DON'T want to do that!

    Thank you for understanding!

    Hello everyone, I am happy to announce I have just launched my Base Mod to the mobrowser that'll house functions for all future mods of mine. But, I have made this detailed thread so anyone can use Idglib:
    It should go without saying this is only for coders who know what they are doing. And have covered more than just the basics.
    First and for most, make sure you read Blushiemagic's tutorial on cross mod content here before we get started: blushiemagic/tModLoader
    I will be updating this as I add more functions

    First thing you need to do is add the mod as a dependancy to your build.txt file, to do this, add this line in said text file at the bottom.

    Code:
    modReferences = Idglibrary
    Now, in order to use this in your mod, you will first need to add
    Code:
    using Idglibrary;
    to every .cs file that will call functions from this.

    Now you should be ready to use these functions:

    Code:
    Idglib.Chat(string message,byte color1,byte color2,byte color3); returns nothing
    This is pretty much the same as Main.NewText, but it also accommodates for networking and broadcasts messages to clients.
    Code:
    Idglib.FindClosestTarget(int targettype,Vector2 loc,Vector2 size,bool block,bool friendlycheck); returns a int
    This allows you to find the closest object from a specified location (loc)
    Targettype is the 0 for npc, or 1 for player.
    size is a Vector2 consisting of half the width and half the height of the npc/player ideally. But it can be anything, it's used for the Centerpoint.
    Block (optional) allows you to filter out targets behind solid blocks (on by default)
    friendlycheck (optional, only works on Targettype=0) checks if the npc is friendly or not. It allows you to only target friendy NPCs if set to false (if you wanted to get the closest town NPC, for example)
    Code:
    Idglib.LookAt(Vector2 here, Vector2 there); returns a float
    This is a bit of ease-of-bytes type code, that gets the angle from here to there, the game might have one of these built in, but I never found one.
    Code:
    Idglib.Shattershots(Vector2 here,Vector2 there,Vector2 widthheight,int type,int damage,float Speed,float spread,int count,bool centershot,float globalangularoffset,bool tilecollidez,int timeleft) returns a list consisting of all the Terraria.Projectile class created
    This code creates a fan of projectiles of your choice, and returns a list of all projectiles created from it. Projectiles created with function will automatically have hostile set to true.
    centershot is whether or not a center shot is created
    globalangularoffset allows you add an angle to all projectiles, say if you want them to spin in a circle.
    spread is half the angle that projectiles will fan out.
    widthheight is again, the centerpoint like with FindClosestTarget
    Code:
    Idglib.DrawTether(string Tex,Vector2 Start,Vector2 End,int Alpha = 255); returns nothing
    Draws a tether-like sprite similar to Plantera's hooks and Wall of Flesh's Hungry. This function will only work in Draw events.
    Tex is the string of the texture you wish to use as the tether
    this function does not stretch the texture, it will repeat it and seamlessly crop it to prevent it from overextending.
    alpha is optional; it defaults to 255
    Code:
    Idglib.DrawSkeletronLikeArms(SpriteBatch spriteBatch, string texString, Vector2 selfPos, Vector2 centerPos, float selfPad = 0f, float centerPad = 0f, float direction = 0f); returns nothing
    Draws skeletron-like arms with any texture of your choice!
    selfPos is the "hand" and centerPos is the 'head"
    the rest is trial and error to see what looks best.
    This was contributed by @direwolf420 who took apart the vanilla code and made something workable with it! So major thanks to him!
    Code:
    Idglib.ColorText(Color color,string text); returns a string with a color code.
    Converts colors into a hexadecimal color code for text!
    Code:
    Idglib.RaycastDown(int x, int y)
    Casts a ray down from the location and returns where it hits, keep in mind this is in tile space, so you need to use a 1/16 of the coord value your really checking!


    ---non-general functions---

    Code:
    IdgNPC.AddBuffBypass(int npcid, int type, int time); returns nothing
    Basic code that bypasses buff immunities for NPCs; is otherwise the same as AddBuff
    Code:
    IdgNpc.FindNPCs(int npctype); returns of a list consisting of all the Terraria.NPC classes that matched the type
    Code:
    IdgNPC.FindNPCsMultitype(ushort[] npctypes); returns of a list consisting of all the Terraria.NPC classes that matched the ushort array
    this code allows you to return a list of different types. an example:
    List<NPC> myzombies = Idglib.FindNPCsMultitype(new ushort[] {(ushort)NPCID.ZombieElf,(ushort)NPCID.BaldZombie});
    Code:
    IdgNPC.AddOnHitBuff(int npcid,int buff, int time); returns nothing
    Code:
    IdgProjectile.AddOnHitBuff(int projectileid,int buff, int time); returns nothing
    allows you to add any buff with any time to an npc or projectile that inflicted on a player it hits. This function is synced online automatically.
    Code:
    IdgProjectile.Sync(int projectileid); returns nothing
    This is a client-side function that gets basic projectile data (position, velocity, damage, timeLeft) from the server's projectile and syncs it over to the projectile on the client's end. I made this after discovering New projectiles arn't synced automatically and a way to deal with randomness factors like velocity.
    Only call this on creation or in few cases as it's not very light.

    ---bonus stuff!---

    Idglib has a custom item class called ProjectileSpearBase that you can use to easily make a customized and simple spear projectile, when I get a github I can go more into detail on this.

    Idglib adds a few built in debuffs that other mods can use easily:
    Code:
    IdgPlayer.AddRadiationDebuff(Player player,int time,int level=0,bool quiet=false); returns nothing, last 2 arguments are optional
    Easy way to give a player Radiation, this debuff comes in 3 tiers (named "RadiationOne","RadiationTwo",RadiationThree" lastly) that you can pick with a level of 0-2.

    This debuff functions like its Starbound counterpart, lowering player max HP, however, the lowered hp will slowly recover over time if not radiated and persists through saving and quiting.

    --Idglib also adds a bunch of debug tools and weapons that i made to basically help me make other mods and things that other mods while testing my own mods' features didn't have for debugging purposes, they start with IDG so you can find them via cheatsheet if you want.
     
    Last edited: Jun 20, 2019
    360Chadscope likes this.
  2. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    I may need more room for text: reserved

    I would like to thank @blushiemagic for what I basically adapted into Idglib.Chat from their mod. As well as @Joost8910 for what became Shattershots. And @direwolf420 for making the skeletron arms code 'useable' from the source code and contributing it, love it!.
     
    Last edited: May 13, 2019
    360Chadscope likes this.
  3. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    9/21/18: I have added the following functions:
    NpcAddOnHitBuff
    ProjectileAddOnHitBuff
    FindNPCsMultitype

    Main topic has been updated.
     
    360Chadscope likes this.
  4. 360Chadscope

    360Chadscope Pixel Pirate

    I haven't used it yet myself, just wanted to say thank you for making modding just a little bit more convenient. I'll definitely be using this in the future :)
     
    IDGCaptainRussia likes this.
  5. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    Thanks alot mate, it means lot <3

    9/22/18
    I've restructured the way functions are called. Instead of everything being called from Idglib, things like npcs and projectile related functions are now called from IdgNpc and IdgProjectile, as they will be sharing alot of functions otherwise.

    Added:
    IdgNpc.AddBuffBypass
    IdgProjectile.Sync

    Shattershots is being reworked and moved as well, hopefully no one was using that extensively. Sorry for any inconvenience.

    Main topic has been updated.
     
  6. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    Hey, it's been awhile, I've been working on other projects but I manged to, hopefully, push a stable build of Idglib's next feature:

    9/27/18
    Added:
    Idglib.EasyShop, a basic api to add items to npc shops universally.

    This feature might still be unstable, please report what you find.
    PS: Loading older saves made in worlds before Idglib tends to cause errors and even a crash sometimes when exiting out, but after that point it may work...
    odd. Really is.

    PS#2: While it did for a time, it tended to bug out greatly after every update. So atleast for now, the ability to save easyshops has been disabled. The function now only makes temporary ones.

    PS#3: Ok, this feature, and the netcode involved with it seems to be very unstable and, rather breaking. This feature was very limited anyways, so I'm going to remove it, really sorry everyone who downloaded this during that time.
     
    Last edited: Sep 28, 2018
  7. direwolf420

    direwolf420 Terrarian

    Hi,
    do you have a github for this mod? I`m curious cause I have implemented like half of those functions for myself aswell and would like to have a comparison/reference
     
  8. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    No I don't
    I'm like the only coder who doesn't have one, I don't even know how a github works.
     
  9. DaysGone

    DaysGone Skeletron Prime

    Just checked this out.. Damn, the Terraria community has some brilliant members
     
  10. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    I wouldn't call IDGLib brilliant, it's just a short-hand API to reduce the number of lines I need to use in code.
    But I appreciate the positive reinforcement
     
    DaysGone likes this.
  11. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    It has been a "long" time since I last updated this!
    I am happy to say now that I'm back into modding, I just added some new features
    Before SGAmod comes out Idglib is going to feature some experimental features of sorts that will become part of that mod, so a heads up
     
    DaysGone likes this.
  12. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    Alright, pretty small update: added RaycastDown and fixed a non-functional method (this was awhile ago so I already forgot which one it was)
    Updated the front page to help explain "how" to use the library as a depenency better.

    Really, this library was made for myself and I choose to share it. It's a bit more, advanced use, and I wouldn't recommend using it for 1 single function (But I also wouldn't recommend *stealing* the code either to avoid using it)
    That's all for now, SGAmod is well underway so this library will be seeing a far larger use soon.
     
  13. IDGCaptainRussia

    IDGCaptainRussia Skeletron

    Updated the front page with new info, but not new functions just yet.
    Yes, I am getting pretty tired of people once again, stealing code.


    And also some other personal things like @direwolf420 just flat out ignoring ANYTHING I say to him on discord when I really thought we were buddy buddies and after he helped me here.
    Like, I seriously can't get that off my mind, I hate being betrayed by people I trusted.

    EDIT: Realized I typed personal things in an open space, oh well I guess I could have posted via status updates. I don't hate Direwolf or anything I just don't understand what I did to make him treat me this way. I'm not even being blocked or anything just straight treated like I don't exist...
     
    Last edited: Jun 16, 2019