Page 1 of 1
[REQUEST] small bird loot script
Posted: Thu Oct 25, 2018 2:27 am
by Artifex
Can anybody make a script where upon killing a bird, loot is dropped?
by this i mean the birds drop health or a slo-mo or hammer or something "light". I don't want them dropping bazookas.
Actually, make that an option if its possible(to drop heavy weapons like guns, launchers etc.) which i can set to true or false.
Re: [REQUEST] small bird loot script
Posted: Wed Nov 21, 2018 6:13 pm
by JakSparro98
Artifex wrote: ↑Thu Oct 25, 2018 2:27 am
Can anybody make a script where upon killing a bird, loot is dropped?
by this i mean the birds drop health or a slo-mo or hammer or something "light". I don't want them dropping bazookas.
Actually, make that an option if its possible(to drop heavy weapons like guns, launchers etc.) which i can set to true or false.
Sorry for the late, here is your request:
Code: Select all
public void RegisterLootTable()
{
//RIFLES
LootTable.Add(new LootItem("WpnPumpShotgun",0));
LootTable.Add(new LootItem("wpnM60",0));
LootTable.Add(new LootItem("WpnSniperRifle",0));
LootTable.Add(new LootItem("WpnSawedOff",0));
LootTable.Add(new LootItem("WpnBazooka",0));
LootTable.Add(new LootItem("WpnAssaultRifle",0));
LootTable.Add(new LootItem("WpnCarbine",0));
LootTable.Add(new LootItem("WpnFlamethrower",0));
LootTable.Add(new LootItem("WpnGrenadeLauncher",0));
LootTable.Add(new LootItem("WpnSMG",0));
LootTable.Add(new LootItem("WpnTommygun",0));
LootTable.Add(new LootItem("WpnDarkShotgun",0));
LootTable.Add(new LootItem("WpnMP50",0));
//HANDGUNS
LootTable.Add(new LootItem("WpnFlareGun",0));
LootTable.Add(new LootItem("wpnUzi",0));
LootTable.Add(new LootItem("WpnSilencedUzi",0));
LootTable.Add(new LootItem("WpnPistol",0));
LootTable.Add(new LootItem("WpnSilencedPistol",0));
LootTable.Add(new LootItem("WpnMagnum",0));
LootTable.Add(new LootItem("WpnRevolver",0));
LootTable.Add(new LootItem("WpnMachinePistol",0));
//MELEE
LootTable.Add(new LootItem("WpnPipeWrench",0));
LootTable.Add(new LootItem("wpnChain",0));
LootTable.Add(new LootItem("WpnHammer",0));
LootTable.Add(new LootItem("WpnKatana",0));
LootTable.Add(new LootItem("WpnMachete",0));
LootTable.Add(new LootItem("WpnChainsaw",0));
LootTable.Add(new LootItem("WpnKnife",0));
LootTable.Add(new LootItem("WpnBat",0));
LootTable.Add(new LootItem("WpnBaton",0));
LootTable.Add(new LootItem("WpnShockBaton",0));
LootTable.Add(new LootItem("WpnLeadPipe",0));
LootTable.Add(new LootItem("WpnAxe",0));
//THROWNABLES
LootTable.Add(new LootItem("WpnGrenades",0));
LootTable.Add(new LootItem("wpnMolotovs",0));
LootTable.Add(new LootItem("WpnC4",0));
LootTable.Add(new LootItem("WpnMines",0));
//PICKUPS
LootTable.Add(new LootItem("ItemPills",0));
LootTable.Add(new LootItem("ItemMedkit",0));
LootTable.Add(new LootItem("ItemSlomo5",0));
LootTable.Add(new LootItem("ItemSlomo10",0));
}
class LootItem
{
static int Offset=1;
static int MaxRandomRange=-1;
String TileName;
int SpanwChance;
int MinRange;
int MaxRange;
public LootItem(String tilename,int spawnchance)
{
TileName=tilename;
SpanwChance=spawnchance;
CalculateSpawnChance();
}
void CalculateSpawnChance()
{
MinRange=Offset;
MaxRange=SpanwChance+Offset-1;
Offset=MaxRange+1;
}
public bool TrySpawn(int RandomNumber)
{
if(RandomNumber >= MinRange && RandomNumber <= MaxRange)
return true;
return false;
}
public static int GetMaxRandomRange(){return MaxRandomRange;}
public static void SetMaxRandomRange(int range){MaxRandomRange=range;}
public int GetSpawnChance(){return SpanwChance;}
public String GetTileName(){return TileName;}
}
class Entity
{
IObject Obj;
Vector2 LastPosition;
public Entity(IObject obj)
{
Obj=obj;
}
public void UpdatePosition()
{
LastPosition=Obj.GetWorldPosition();
}
public IObject GetEntity(){return Obj;}
public Vector2 GetLastPosition(){return LastPosition;}
}
List<LootItem>LootTable=new List<LootItem>();
List<Entity>EntityPool=new List<Entity>();
Events.UpdateCallback m_updateEvent = null;
float m_totalElapsed = 0f;
public void OnStartup() {
RegisterLootTable();
m_updateEvent = Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float elapsed) {
foreach(IObject obj in Game.GetObjectsByName("Dove00"))
RegisterEntity(obj);
for(int i=0;i<EntityPool.Count();i++)
if(EntityPool[i].GetEntity().IsRemoved)
{
CreateLoot(EntityPool[i].GetLastPosition());
EntityPool.RemoveAt(i);
i--;
}
else
EntityPool[i].UpdatePosition();
}
public void CreateLoot(Vector2 position)
{
if(LootItem.GetMaxRandomRange()==-1)
{
int count=0;
foreach(LootItem item in LootTable)
count+=item.GetSpawnChance();
LootItem.SetMaxRandomRange(count);
}
Random RNG=new Random();
int RandomNumber=RNG.Next(1,LootItem.GetMaxRandomRange()+1);
foreach(LootItem item in LootTable)
if(item.TrySpawn(RandomNumber))
Game.CreateObject(item.GetTileName(),position);
}
public void RegisterEntity(IObject entity)
{
if(!ContainsID(entity.UniqueID))
EntityPool.Add(new Entity(entity));
}
public bool ContainsID(int ID)
{
foreach(Entity item in EntityPool)
if(item.GetEntity().UniqueID==ID)
return true;
return false;
}
You can modify the item spawn chance by changing the second parameter of a LootItem object with any positive number (0 is to disable the item),e.g:
LootTable.Add(new LootItem("WpnSMG",15));
Re: [REQUEST] small bird loot script
Posted: Wed Nov 21, 2018 11:59 pm
by Artifex
thank you very mucho