Author Topic: Deriboy's scripting help  (Read 530 times)

What does return; do?
Are things case sensitive?
How would I round variables? ex. 4.5 to 5
How would I 'get' if a player dies?
« Last Edit: October 22, 2009, 07:57:51 AM by Deriboy »

How would I check the amount of items in ones inventory? How would I add an item to ones inventory?

Look at existing add-ons for working examples, in this case Event_ifItemInInventory and Event_addItem, respectively.


Code: [Select]
function player::getNumItems(%player)
{
   %data = %player.getDatablock();
   %toolCount = 0;
   for(%i = 0; %i < %data.maxItems; %i++) //Loop through player's tools
   {
      if(isObject(%player.tool[%i])) //We have a tool
      {
         %toolCount++; //Add 1 to the tool count
      }
   }
   return %toolCount; //Return the final value
}

== is a boolean comparison meaning equals to. It is true the numbers on both sides of it are equal. != is the opposite. && means and. For example:
Code: [Select]
if(%X == 0 && %Y == 5)Would only be true if %x is zero and %y is five.

|| is the same thing, but it means or. For example:
Code: [Select]
if(%X == 0 || %Y != 5)Would be true if %x is zero OR %y is not five.

Thanks for all the help guys!

Look at existing add-ons for working examples, in this case Event_ifItemInInventory and Event_addItem, respectively.

How would I count the number of items in the inventory though? Not just check for a specific one.
« Last Edit: October 20, 2009, 07:43:30 AM by Deriboy »

Uhh i think if you look at add item that might help.

How would I count the number of items in the inventory though? Not just check for a specific one.
Are you joking? The code was posted only a bit above your post...

Whoops! :p

diddnt see that