Breakable Pawn script

Topics regarding Scripting with Reality Factory
Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Breakable Pawn script

Post by Veleran » Mon Feb 08, 2016 10:55 pm

I would like to spawn some attributes when the vase breaks.
I added in the Pawn.ini a Pawn called Breakable that has no mesh and some accessory actors to to choose from the Pawn.ini list and attach as display actors ,like vase1,vase2 and so on.

Then gets replaced with the wrecked version and reduces the bounding box height (maybe the width a little too) (the vases are smaller broken)
I have dozen vases on the works ,few are ready and thought to start with some of them and later i could add more vase types in the script.
I have a crate done but i think it could use a modified version of a generic breakables script if i have it.

The Orders for all pickups are same,changing only base vase ,attribute accessories,bounding box for starting and broken vase version bound and names.

With some basic variables added i imagine it could get much shorter and i hope simple enough.
Right now the script is kind of huge ,full of all those Orders.
I would like it to have a function to display something like "you found" and stick on it a "small bread" at the end the " from the attribute or accessory list
Also maybe have the option at start of script for a number that sets the chance for spawning at all or not, being empty or with loot,.
So far i thought to have various spawn orders and pick one of them in the level editor in any case i wanted a vase to spawn for sure.

Simple old classic stuff: ammo is projectile attributes
Food is stamina attribute increase
Drink is Health restore for red potion and mana fill for blue potion,Water and mead is stamina refill.


I do not think i finished the script anyway and i might have mixed or forgot some attribute order,so i did not bother testing,nor i have exported the accessory attribute actors yet.

About Text: I switched to low level to display a text that says what you found but i could not make it delay before disappearing -it needs fixing.
If you can,roughly align the text at above center and to the left,i use isometric view,player is almost at center and maybe text should stay clear from him.


I am not certain yet about few minor things,and i might change minor things like the distance the text appears and maybe add more pickups some day.
I mean if the text appears when the vase breaks no matter how far you are and again if you get close.

I imagine if there are dozens of vases in rows and you break them it would be a mess to say what each of them.
If a small text would be displayed above the broken vase it would not be seen in small screens,unless you press and hold at for examine in 1st person view.



Scroll down and take your time to have a look at it.I am not hurrying because i do not have the attributes actors and most vases finished and exported yet.

Orders i thought to use-just to see what i thought to do
basic orders-
Spawn (general)
SpawnOrNot
NotSpawn
VaseRandomSpawn
Vase_Ceramic_1_Spawn (can i use that _ in the orders names or not -i wonder)
Idle
Destroyed
LootOrNot
Empty
RandomLoot

--What type of attribute you found--
Ammo
Food
PotionOrDrink
Potion
Drink
Bread
Meat
Fruit

(show description text )
ThrowingDagger ...and rest attributes in list

finally--ending the script while giving the pickup upon collision
MeadFlaskWait
and so on,for the rest pickups,i did not fill it up for all attributes since the script is temporary.

Code: Select all

{ 
	Spawn[ ()
	{
		       Console(false);
		       Gravity(true);
               NewOrder("SpawnOrNot");
      } ] 
	
	SpawnOrNot[ () 
         {    
		// "Roll"  random chance for Spawning the breakable or not		 
     switch(random(0,2))
         {
         case 0
         {
		 NewOrder("NotSpawn");
          }
	     case 1
         {
         NewOrder("VaseRandomSpawn");
         }	 
		 case 3
         {
         NewOrder("VaseRandomSpawn");
         }
     } ] 
	 
	NotSpawn[ () 
      {        
		// nothing inside so,finish the script	  
             EndScript();
	  }	  
	} ]  
	
	VaseRandomSpawn[ () 
         {      
         switch(random(0,4))
         {
         case 0
         {
		 NewOrder("Vase_Ceramic_1_Spawn");
          }
	 case 1
         {
         NewOrder("Vase_Ceramic_2_Spawn");
         }
     case 2
         {
         NewOrder("Vase_Wooden_1_Spawn");
         }
	 case 3
         {
         SetEventState("VaseWooden1",true);
         }
     case 4
         {
         SetEventState("trigger1",true);
         }
     } ] 
	 
    Vase_Ceramic_1_Spawn[ ()
	{
		       Console(false);
		       Gravity(true);
		       BoxWidth(20);
		       BoxHeight(33);
		       AttachAccessory("Vase_Ceramic_1");
               NewOrder("Idle");
      } ] 
	  
	Idle[ () 
      {      
		    AttributeOrder("enemy_health", 1, "Destroyed");
     } ] 
	 

	Destroyed[ () 
      {            
		  BoxHeight(16);
		  DetachAccessory("Vase_Ceramic_1");
		  AttachAccessory("Vase_Ceramic_1_broken");
		  AddExplosion("Vase_Ceramic_1_Explosion", "BONE02", 0, 0, 0);
          NewOrder("LootOrNot");
	} ] 
	
	 LootOrNot[ () 
         {      
         switch(random(0,1))
          {
         case 0
          {
         NewOrder("Empty");
         }
         case 1
         {
         NewOrder("RandomLoot");
         }
	    } ] 
     }

	 Empty[ () 
     {            
             EndScript();
	  }	  
	} ] 

	 RandomLoot[ () 
      {   
         switch(random(0,3))
         {
         case 0
         {
         NewOrder("Ammo");
         }
         case 1
         {
         NewOrder("Food");
         }
         case 2
         {
         NewOrder("PotionOrDrink");
         }
     } ] 
	 
     Ammo[ ()
        {  
         switch(random(0,5))
         {
         case 0
         {
		 AttachAccessory("");		 
         NewOrder("ThrowingDagger");
         }
         case 1
         {
		 AttachAccessory("ThrowingHammer");		 	 
         NewOrder("ThrowingHammer");
         }
         case 3
         {
		 AttachAccessory("ThrowingAxe");		  
         NewOrder("ThrowingAxe");
		 case 3
         {
		 AttachAccessory("Arrow");		 
         NewOrder("Arrow");	 
		 case 4
         {
		 AttachAccessory("Bomb");		 
         NewOrder("Bomb");
         }
     } ] 
	 
	 	Food[ () 
         {      
         switch(random(0,4))
         {
         case 0
         {
         NewOrder("Bread");
         }
         case 1
         {		 	 
         NewOrder("Meat");
         }
         case 3
         {
         NewOrder("Fruit");
		 }
     } ]
	 
	 	PotionOrDrink[ () 
      {      

         switch(random(0,2))
         {
         case 0
         {
          NewOrder("Potion");
         }
         case 1
         {
          NewOrder("Drink");
          }
     } ] 
	 
     Potion[ () 
	 		// "Roll" for random Potion type
         {      
         switch(random(0,4))
         {
         case 0
         {
		 AttachAccessory("Potion_Red");	
         NewOrder("PotionOfMinorHealing");
         }
         case 1
         {
		 AttachAccessory("Potion_Red");	
         NewOrder("PotionOfHealing");
         }
		 case 2
		 }
		  AttachAccessory("Potion_Blue");	
		 NewOrder("PotionOfMinorMana");
		 {
		 case 2
		 }
		  AttachAccessory("Potion_Blue");	
		 NewOrder("PotionOfMana");
		 {
     } ] 
	 
	 	Drink[ () 
		// "Roll" for random Drink type
      {      
         switch(random(0,2))
         {
         case 0
         {
		 AttachAccessory("LeatherFlask"); 
         NewOrder("FlaskOfWater");
         }
         case 1
         {
		 AttachAccessory("LeatherFlask");  
		 NewOrder("FlaskOfMead");
          }
     } ] 
	 
     Bread[ () 
      {      
         switch(random(0,2))
      {
     case 0
      {
		  AttachAccessory("Breadsmall");
          PlayerDistOrder(64, "Breadsmall");
         }
         case 1
         {
		 AttachAccessory("BreadBig");
         PlayerDistOrder(64, "BreadBig");
         }
     } ] 
	 
	     Meat[ () 
         {      
         switch(random(0,2))
         {
        case 0
         {
		  AttachAccessory("Ham1");
          PlayerDistOrder(64, "Ham");
         }
         case 1
         {
		 AttachAccessory("HamBig");
         PlayerDistOrder(64, "HamBig");
         }
     } ] 
	 
	     Fruit[ () 
         {      
         switch(random(0,2))
         {
        case 0
         {
		  AttachAccessory("AppleRed");
          PlayerDistOrder(64, "Apple");
         }
         case 1
         {
		 AttachAccessory("AppleGreen");
         PlayerDistOrder(64, "Apple");
         }
     } ] 
	 
	 	 ThrowingDagger[ () 
      {
		// Show Decription Text of what you have found
		DrawText("Throwing Dagger", 500, 500, 255, 3, 255, 255, 255);
		RemoveText("Throwing Dagger");
		HighLevel("ThrowingDaggerWait");	 
     }
     } ]
	 
	 	 ThrowingHammer[ () 
      {
	 	 DrawText("Throwing Hammer", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Throwing Hammer");
         HighLevel("ThrowingHammerWait");	 
     }
     } ]
	 
		ThrowingAxe[ () 
      {
	 	 DrawText("Throwing Axe", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Throwing Axe");
         HighLevel("ThrowingAxeWait");	 
     }
	 } ]
	 
	 	 Arrow[ () 
      {
	 	 DrawText("Arrow", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Arrow");
         HighLevel("ArrowWait");	 
     }
     } ]
	 
	 	 Bomb[ () 
      {
	 	 DrawText("Bomb", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Bomb");
         HighLevel("BombWait");	 
     }
     } ]
	 
	 	Breadsmall[ () 
      {
	 	 DrawText("a Small Bread", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("a Small Bread");
         HighLevel("SmallBreadWait");	 
     }
     } ]
	 
		BreadBig[ () 
      {
	 	 DrawText("BreadBig", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("BreadBig");
         HighLevel("BreadBigWait");	 
     }
     } ] 
	 
	 	 Ham[ () 
         {
	 	 DrawText("Ham", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Ham");
         HighLevel("HamWait");	 
         }
     } ] 
	 
	 	 HamBig[ () 
         {
	 	 DrawText("HamBig", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("HamBig");
         HighLevel("HamBigWait");	 
         }
     } ] 
	 
	 	 AppleRed[ () 
         {
	 	 DrawText("Red Apple", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Red Apple");
         HighLevel("AppleRedWait");	 
         }
     } ] 
	 
	 	 AppleGreen[ () 
         {
	 	 DrawText("Green Apple", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Green Apple");
         HighLevel("AppleGreenWait");	 
         }
     } ] 
	 
	 	 PotionOfMinorHealing[ () 
         {
	 	 DrawText("Potion of Minor Healing", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Potion of Minor Healing");
         HighLevel("PotionOfMinorHealingWait");	 
         }
     } ] 
	 
	 	 PotionOfHealing[ () 
         {
	 	 DrawText("Potion of Healing", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Potion of Healing");
         HighLevel("PotionOfHealingWait");	 
         }
     } ] 
	 
	 	 PotionOfMinorMana[ () 
         {
	 	 DrawText("Potion of Minor Mana", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Potion of Minor Mana");
         HighLevel("PotionOfMinorManaWait");	 
         }
     } ] 
	 
	 	 PotionOfMana[ () 
         {
	 	 DrawText("Potion of Mana", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Potion of Mana");
         HighLevel("PotionOfManaWait");	 
         }
		 
     } ] 
	 
	 	 WaterFlask[ () 
         {
	 	 DrawText("Flask of Water", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Flask of Water");
         HighLevel("FlaskOfWaterWait");	 
         }
     } ] 
	 
	 	 MeadFlask[ () 
         {
	 	 DrawText("Flask of Mead", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Flask of Mead");
         HighLevel("FlaskOfMeadWait");	 
         }
     } ] 
		 
		MeadFlaskWait[ () 
		{
		// Increase Attribute -all the rest pickups above have same Order with this	
		AddCollisionOrder("FlaskOfWaterModify")
		DetachAccessory("LeatherFlask");
		ModifyAttribute("MeadFlask", 1);
		EndScript();			 
		}
     } ] 

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Wed Feb 10, 2016 12:44 pm

I did a quick scan of the code and you could probably get rid of a lot of the switch case statements by using an array of items. I would also suggest instead of using AttachAccessory() that you create a pawn and script just for moving the item's pawns to scripting points which mark the spawn location. Then assign each of the item's pawn a script that handles the breaking, triggering, state changing, and normal operation of that particular item. I could help write it but it's very hard to do if I don't have a level to test it on. Also hard when I don't have the names of the pawns and entities.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Wed Feb 10, 2016 4:25 pm

You can see some vase and attribute names in the script,you can use you own example names,try 3 random "vase" actors and 3 random spawned attributes instead all these i wrote.
If you have RF you can run it a basic empty room.

When you do not have the appropriate actors you can always use the virgil player versions and other actors for Pawns.
I will think about the scriptpoints.
If it means doubled entities for the breakables (one Pawn and one scriptpoint) i would like to avoid it,and all these szEntity names.
What i could not do was to display the text.
Maybe i will check if i can use a predefined text that attaches to the pawn entity .

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Wed Feb 10, 2016 6:53 pm

If do not make it shorter maybe i can get a check in the random spawn part,i do not know if that is the way it should be.
I may have made mistakes when i copied it from somewhere.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Wed Feb 10, 2016 9:26 pm

I took a closer look at the script you posted and it has a lot of errors, most are syntax errors that will prevent it from working. Below is a version of the script that only corrects the syntax errors not the logic. I corrected the formatting to make it easier to read. I added and removed braces where needed. I also changed the random statement numbers to match the case statements. There were also missing semicolons which I add.

Code: Select all

{
    Spawn[ ()
    {
        Console(false);
        Gravity(true);
        NewOrder("SpawnOrNot");
    } ]
   
    SpawnOrNot[ ()
    {
        // "Roll"  random chance for Spawning the breakable or not
        switch(random(0,3))
        {
            case 0
            {
                NewOrder("NotSpawn");
            }

            case 1
            {
                NewOrder("VaseRandomSpawn");
            }

            case 3
            {
                NewOrder("VaseRandomSpawn");
            }
        }
    }]
    
    NotSpawn[ ()
    {
        // nothing inside so,finish the script
        EndScript();
    }]
   
    VaseRandomSpawn[ ()
    {
        switch(random(0,4))
        {
            case 0
            {
                NewOrder("Vase_Ceramic_1_Spawn");
            }

            case 1
            {
                NewOrder("Vase_Ceramic_2_Spawn");
            }

            case 2
            {
                NewOrder("Vase_Wooden_1_Spawn");
            }

            case 3
            {
                SetEventState("VaseWooden1",true);
            }

            case 4
            {
                SetEventState("trigger1",true);
            }
        }
    }]
    
    Vase_Ceramic_1_Spawn[ ()
    {
        Console(false);
        Gravity(true);
        BoxWidth(20);
        BoxHeight(33);
        AttachAccessory("Vase_Ceramic_1");
        NewOrder("Idle");
    } ]
     
    Idle[ ()
    {
        AttributeOrder("enemy_health", 1, "Destroyed");
    }]
    
    Destroyed[ ()
    {
        BoxHeight(16);
        DetachAccessory("Vase_Ceramic_1");
        AttachAccessory("Vase_Ceramic_1_broken");
        AddExplosion("Vase_Ceramic_1_Explosion", "BONE02", 0, 0, 0);
        NewOrder("LootOrNot");
    }]
   
    LootOrNot[ () 
    {
        switch(random(0,1))
        {
            case 0
            {
                NewOrder("Empty");
            }

            case 1
            {
                NewOrder("RandomLoot");
            }
        }
    }]

    Empty[ () 
    {            
         EndScript();
    }]

    RandomLoot[ () 
    {
        switch(random(0,2))
        {
            case 0
            {
                NewOrder("Ammo");
            }

            case 1
            {
                NewOrder("Food");
            }

            case 2
            {
                NewOrder("PotionOrDrink");
            }
        }
    }]
    
    Ammo[ ()
    {
        switch(random(0,5))
        {
            case 0
            {
                AttachAccessory("ThrowingDagger");
                NewOrder("ThrowingDagger");
            }

            case 1
            {
                AttachAccessory("ThrowingHammer");
                NewOrder("ThrowingHammer");
            }

            case 3
            {
                AttachAccessory("ThrowingAxe");
                NewOrder("ThrowingAxe");
            }

            case 4
            {
                AttachAccessory("Arrow");
                NewOrder("Arrow");
            }

            case 5
            {
                AttachAccessory("Bomb");
                NewOrder("Bomb");
            }
        }
    }]
    
    Food[ ()
    {
        switch(random(0,3))
        {
            case 0
            {
                NewOrder("Bread");
            }

            case 1
            {
                NewOrder("Meat");
            }

            case 3
            {
                NewOrder("Fruit");
            }
        }
    }]
    
    PotionOrDrink[ ()
    {
        switch(random(0,1))
        {
            case 0
            {
                NewOrder("Potion");
            }

            case 1
            {
                NewOrder("Drink");
            }
        }
    }]

    // "Roll" for random Potion type
    Potion[ ()
    {
        switch(random(0,3))
        {
            case 0
            {
                AttachAccessory("Potion_Red");
                NewOrder("PotionOfMinorHealing");
            }

            case 1
            {
                AttachAccessory("Potion_Red");
                NewOrder("PotionOfHealing");
            }

            case 2
            {
                AttachAccessory("Potion_Blue");
                NewOrder("PotionOfMinorMana");
            }

            case 3
            {
                AttachAccessory("Potion_Blue");
                NewOrder("PotionOfMana");
            }
        }
     }]


    // "Roll" for random Drink type
    Drink[ ()
    {
        switch(random(0,1))
        {
            case 0
            {
                AttachAccessory("LeatherFlask");
                NewOrder("FlaskOfWater");
            }

            case 1
            {
                AttachAccessory("LeatherFlask");
                NewOrder("FlaskOfMead");
            }
        }
    }]
    
    Bread[ ()
    {
        switch(random(0,1))
        {
            case 0
            {
                AttachAccessory("Breadsmall");
                PlayerDistOrder(64, "Breadsmall");
            }

            case 1
            {
                AttachAccessory("BreadBig");
                PlayerDistOrder(64, "BreadBig");
            }
        }
    }]
    
    Meat[ ()
    {
        switch(random(0,1))
        {
            case 0
            {
                AttachAccessory("Ham1");
                PlayerDistOrder(64, "Ham");
            }

            case 1
            {
                AttachAccessory("HamBig");
                PlayerDistOrder(64, "HamBig");
            }
        }
    }]
    
    Fruit[ ()
    {
        switch(random(0,1))
        {
            case 0
            {
                AttachAccessory("AppleRed");
                PlayerDistOrder(64, "Apple");
            }

            case 1
            {
                AttachAccessory("AppleGreen");
                PlayerDistOrder(64, "Apple");
            }
        }
    }]
    
    ThrowingDagger[ ()
    {
        // Show Decription Text of what you have found
        DrawText("Throwing Dagger", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Throwing Dagger");
        HighLevel("ThrowingDaggerWait");
    }]
    
    ThrowingHammer[ ()
    {
        DrawText("Throwing Hammer", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Throwing Hammer");
        HighLevel("ThrowingHammerWait");
    }]
    
    ThrowingAxe[ ()
    {
        DrawText("Throwing Axe", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Throwing Axe");
        HighLevel("ThrowingAxeWait");
    }]
    
    Arrow[ ()
    {
        DrawText("Arrow", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Arrow");
        HighLevel("ArrowWait");
    }]
    
    Bomb[ ()
    {
        DrawText("Bomb", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Bomb");
        HighLevel("BombWait");
    }]
    
    Breadsmall[ ()
    {
        DrawText("a Small Bread", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("a Small Bread");
        HighLevel("SmallBreadWait");
    }]
    
    BreadBig[ ()
    {
        DrawText("BreadBig", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("BreadBig");
        HighLevel("BreadBigWait");
    }]
    
    Ham[ ()
    {
        DrawText("Ham", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Ham");
        HighLevel("HamWait");
    }]
    
    HamBig[ ()
    {
        DrawText("HamBig", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("HamBig");
        HighLevel("HamBigWait");
    }]
    
    AppleRed[ ()
    {
        DrawText("Red Apple", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Red Apple");
        HighLevel("AppleRedWait");
    }]
    
    AppleGreen[ ()
    {
        DrawText("Green Apple", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Green Apple");
        HighLevel("AppleGreenWait");
    }]
    
    PotionOfMinorHealing[ () 
    {
         DrawText("Potion of Minor Healing", 500, 500, 255, 3, 255, 255, 255);
         RemoveText("Potion of Minor Healing");
         HighLevel("PotionOfMinorHealingWait");    
      
    }] 
    
    PotionOfHealing[ () 
    {
        DrawText("Potion of Healing", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Potion of Healing");
        HighLevel("PotionOfHealingWait");    
     
    }] 
    
    PotionOfMinorMana[ () 
    {
        DrawText("Potion of Minor Mana", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Potion of Minor Mana");
        HighLevel("PotionOfMinorManaWait");    
    
    }] 
    
    PotionOfMana[() 
    {
        DrawText("Potion of Mana", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Potion of Mana");
        HighLevel("PotionOfManaWait");    
    }] 
    
    WaterFlask[ () 
    {
        DrawText("Flask of Water", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Flask of Water");
        HighLevel("FlaskOfWaterWait");    
    }] 
   
    MeadFlask[ () 
    {
        DrawText("Flask of Mead", 500, 500, 255, 3, 255, 255, 255);
        RemoveText("Flask of Mead");
        HighLevel("FlaskOfMeadWait");    
    }] 
       
    MeadFlaskWait[ () 
    {
        // Increase Attribute -all the rest pickups above have same Order with this   
        AddCollisionOrder("FlaskOfWaterModify");
        DetachAccessory("LeatherFlask");
        ModifyAttribute("MeadFlask", 1);
        EndScript();          
    }] 

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Wed Feb 10, 2016 11:31 pm

What do the SetEventState() functions do in the VaseRandomSpawn order?

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Thu Feb 11, 2016 9:10 am

Thank you for correcting it.I was modelling the actors as i copied the lines (the sample i used had seteventstate on it) and got tired and forgot to double check it because i was nit going to run test the script.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Fri Feb 12, 2016 10:10 pm

How do you want the loot to be picked up? Some examples would be to have the player automatically pick up loot if they are a certain distance from the loot or have the player press a key when they are facing the loot and a certain distance away.

Do you want the loot to go in the inventory or work right away? If the player picks up a potion does he drink it when it's picked up or does it go in the inventory? If the player picks up a weapon does it become the weapon he is holding or does it go in the inventory?

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Sat Feb 13, 2016 7:44 pm

For now i would like to try the pick the attribute which goes in the inventory at a certain distance without pressing a key.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Sun Feb 14, 2016 10:25 am

Here is my updated version of the script:

Code: Select all

{
    Items
    {
        [Nothing]
        [Vase_Ceramic_1]
        [Vase_Ceramic_2]
        [Vase_Wooden_1]
        [Vase_Wooden_2]
    }

    Loots
    { 
        {
            Name    [Nothing]
        }
 
        {    
            Name    [ThrowingDagger]
            Text    [Throwing Dagger]
            Amount  [1]
        }

        {
            Name    [ThrowingHammer]
            Text    [Throwing Hammer]
            Amount  [1]
        }

        {
            Name    [ThrowingStars]
            Text    [5 Throwing Stars]
            Amount  [5]
        }

        {
            Name    [ThrowingStars]
            Text    [10 Throwing Stars]
            Amount  [10]
        }

        {    
            Name    [Arrows]
            Text    [10 Arrows]
            Amount  [10]
        }

        {
            Name    [BreadSmall]
            Text    [Small Bread]
            Amount  [1]
        }

        {    
            Name    [Potion_Red]
            Text    [Small Potion of Healing]
            Amount  [1]
        }

        {
            Name    [Green_Potion]
            Text    [Large Potion of Healing]
            Amount  [1]
        }
    }
             
    FONT          [Tahoma]
    
    // Don't change these
    TextDisplayed [false] 
    Item  [Nothing]   
    Loot  [Nothing]    


    Spawn[ ()
    {   
        Console(true);

        // Get random Item 
        Item = toString(Items[random(0,Items.numChildren-1)]);
        
        // if Item is not nothing display Item
        // and wait for it to be destroyed
        if (Item != "Nothing")
        {
            Gravity(true);
            BoxWidth(20);
            BoxHeight(33);
            AttachAccessory(Item);
            SetCollision ();
            AttributeOrder("enemy_health", 1, "Destroyed");
            return;    
        }
        EndScript();
    }]
         

    Destroyed[ ()
    {
        // Destroy Item and display explosion and broken Item
        BoxWidth(20);
        BoxHeight(16);
        DetachAccessory(Item);
        AttachAccessory(Item # "_Broken");
        AddExplosion(Item # "_Explosion", "BONE02", 0, 0, 0);
        NewOrder("LootOrNot");
    }]


    LootOrNot[()
    {
        // Get random loot
        Loot = Loots[random(0,Loots.numChildren-1)];
        
        // If loot is not Nothing then display the loot
        // and go to ControlLoot
        if (Loot.Name != "Nothing")
        {
            AttachAccessory(Loot.Name);    
            LowLevel("ControlLoot");
        }  
    }]


    ControlLoot[()
    {
        // Show text and wait for Loot to be picked up

        Distance = DistanceBetweenEntities("Player",self.EntityName,true);
        
        if (Distance < 300.0)
        {
            if (TextDisplayed = false)
            {    
                ShowText(0,self.EntityName,"",Loot.Text,FONT,"",0,0,"center",255.0);
                TextDisplayed = true;
            }
                                 
        }
        else
        {
            if (TextDisplayed = true)
            {
                 RemoveText(0);
                 TextDisplayed = false;
            }
        }

        if (Distance < 100)
        {   
            HighLimit = Player.GetAttributeHighLimit(Loot.Name);
            Amount = Player.GetAttribute(Loot.Name) + toInt(Loot.Amount);

            if (HighLimit >= Amount)
            {
                if (TextDisplayed = true)
                {
                    RemoveText(0);
                }
                HighLevel("TakeLoot");
            }
        }
    }]


    TakeLoot[()
    {    
         // Remove Loot from pawn and give it to player
         DetachAccessory(Loot.Name);
         Player.ModifyAttribute(Loot.Name,toInt(Loot.Amount));
    }]
 
} 
I used a lot of generic orders so you wouldn't have to create a new order for every item. You just need to modify the Items and Loots variable located at the top of the script. It's pretty self explanatory just add the breakable items to the Items list and the loot items to the Loots list.

All items and loot items must be defined in the pawns.ini file with type = accessory, this includes all the weapons. The breakable items will have two definitions in the Pawns.ini file, one for the unbroken item and one for the broken item. The name of the broken object needs to have the same name as the unbroken item with _Broken appended to the end. For example Vase_Ceramic_1 and Vase_Ceramic_1_Broken. The explosion must be the same as the unbroken item with _Explosion added to the end. I could make the broken item and explosion different variables so you can use the same broken item and explosion for different items.

You will need to tweak the variables to get the items and loot to line up properly on the screen but it shouldn't be hard. I was testing using the barrel0, barrel1, jacket, and helmet actors and they were close but not exact.

The way I set this up was to create an accessory named Spawn_Item in Pawn.ini. It was just a copy of the camera pawn with rotation set to 0 0 0. Then in the editor I created a pawn and added Spawn_Item as PawnType, ScriptName is the name of the above script's file, and ScriptOrder is Spawn.

You can look at the HealthPack definitions in all the INI files to see how to get the loot added to the inventory.

If you have problems or changes just post here and I will try to help.
Last edited by Allanon on Sun Feb 14, 2016 9:58 pm, edited 1 time in total.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Sun Feb 14, 2016 2:21 pm

I will try it later when i finish modeling of the vases because it takes some time to modify the base actors to crack and then separate each piece as explosion actor.
Thanks in advance.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Fri Aug 12, 2016 10:25 am

The vases accessories randomness look good but after that the player can not get the pickups attributes.

Something else-does anyone know if the healthPack is hardcoded?
Do you have to name your custom health potion as healthpack so it will work through the inventory?
I do not know of any settings for the healthpack besides how many you can carry.

I would like to be able do a similar refill also with the stamina and mana (basic stat attributes) again through the inventory.


i can also spread around in the level the common attribute entity,but i am not sure yet if the player should have to go from one end of the level back to the other edge to pick some attribute he left earlier.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Fri Aug 26, 2016 1:24 pm

Besides the player can not get his attribute modified by the vase,he falls down through the floor when ever he steps on the place a vase has randomly chose not to spawn.It is like you have placed an empty or hint brush there.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Breakable Pawn script

Post by Allanon » Fri Aug 26, 2016 8:16 pm

Veleran wrote:Besides the player can not get his attribute modified by the vase,he falls down through the floor when ever he steps on the place a vase has randomly chose not to spawn.It is like you have placed an empty or hint brush there.
It's hard to debug these problems without the actual working level. In my test level everything worked so without the actual level, actors, and scripts I really can't tell what's going wrong.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Breakable Pawn script

Post by Veleran » Sat Aug 27, 2016 12:37 am

I thought i checked the settings related to the script,but i guess i must have missed something.
I plan to simplify it and reduce each player attribute pick ups (lie having each player using one throwing weapon only) but i do not have time now and until then i leave it as is ,with all vase attributes to be picked.
I also get an error in the skeleton scripts about incorrect parameters in method BlendToAnimation of IdlePain order.

The level shuts down when you go near the north corridor end trap and the fireball flies.
It crashes even if i remove the explosion from the projectile in weapon ini.
If you want check also the traphead.s and change the projectile to dart if it bugs you.

The corridors are tiny (to fit most i can on screen) and i plan to make other wider dungeons later.
I have not balanced and bug tested all yet.And among other,i need more actor stuff to cover the walls.
I hope you not mind i did not remove the default rf actors and content,i leave it there just in case.
The file will be stored there for 21 days
http://www.megafileupload.com/7xfl/Real ... _Crypt.rar


Weapon controls are 1 for sword 2 for throwing.
Last edited by Veleran on Thu Sep 15, 2016 12:47 pm, edited 1 time in total.

Post Reply