Author Topic: Item Pickup  (Read 1732 times)

I need an item to not pick up until a variable equals one.
Then it checks to see if another variable equals greater then some number.
Then it needs to check for a free slot.
Then it needs to put the item in that slot if theres an open one.
If not it should say no room or something.
If the variable isnt greater than the number it should say to low or something.
If the first variable doesn't equal one it should say not one or something.

I also need to know how to read a text file (Not every line) and store the first line into a variable.

Code: [Select]
if(!%client.firstvariable = 1 && !%client.secondvariable > 10){
   messageclient(%client,"",'Not one or 10');
}

Something like that. Ill explain to you about and not + or.

&& (and) checks for multiple stuff eg. if(%client.wee && %client.poo){}
|| (or) checks for one eg if(%client.wee || %client.poo){}
! (not) checks for stuff thats not true. eg if(!%client.wee){}

File Reading:
As an example, here's a script to read a specific line number in a file.

Code: [Select]
function readFileLine(%filepath,%line)
{
%file=new FileObject();
%file.openForRead(%filepath);

// the file path is opened for read, now let's loop through each line
   while( %file.isEOF() != True)   // same as: while( !%file.isEOF() )
   {
   %text = %file.readLine();
   %i++;
      if(%line == %i)
      {
      return %text;
      }
   }
}
So to make a variable equal the first line of a file you would do:
Code: [Select]
%variable = readFileLine("./file.txt", 0);

what does $= mean like in !$= ,and $=?

I need all the ifs so that i can respond to each. Each if checks something different if i use or i cant specify why they couldn't pick it up.
« Last Edit: June 15, 2007, 07:44:57 PM by Flea »

what does $= mean like in !$= ,and $=?

I need all the ifs so that i can respond to each. Each if checks something different if i use or i cant specify why they couldn't pick it up.

$= is for comparing strings i.e
Code: [Select]
%lol = "hi";
%lol2 = "hi";
if(%lol $= %lol2) { return true; }
Would return true. You can't use == for strings because you just don't.

!$= is for comparing if a string is not equal to another one
Code: [Select]
%lol = "hi";
%lol2 = "hi";
if(%lol !$= %lol2) { return true; }
else { return false; }
That would return false.

Code: [Select]
function Item::onPickup(%this,%item,%obj,%amount)
{
 if(%obj.variable != 1){commandtoclient(%obj.client,'centerPrint',"\c5Variable not equal to 1.",2);return;}
 if(!(%obj.variable2 > 10)){commandtoclient(%obj.client,'centerPrint',"\c5Variable2 not greater than 10.",2);return;}
 Parent::onPickup(%this,%item,%obj,%amount);
}

You can either add that code as is, changing variable and variable2 for things you set, or replace "Item" with your weapon/tool's "GunItem", "RocketLauncherItem", etc name.

Yey mine was rightish.