Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

[REQUEST] small bird loot script

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Artifex
Fighter
Fighter
Posts: 26
Joined: Sat Oct 20, 2018 9:13 pm
Title: i kick ass and chew gum daily
Started SFD: year before old forums closed
Location: look behind you dummy
Gender:

[REQUEST] small bird loot script

Post by Artifex » 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.
0 x
Frankly my dear, I don't give a damn.

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Wed Nov 21, 2018 6:13 pm

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));
0 x

User avatar
Artifex
Fighter
Fighter
Posts: 26
Joined: Sat Oct 20, 2018 9:13 pm
Title: i kick ass and chew gum daily
Started SFD: year before old forums closed
Location: look behind you dummy
Gender:

Post by Artifex » Wed Nov 21, 2018 11:59 pm

thank you very mucho
0 x
Frankly my dear, I don't give a damn.

Post Reply