Author Topic: onMount function not working  (Read 2426 times)

I can't see whats wrong with the code in the onMount function.
It's supposed to unmount itself if the wrong person attempts to equipt the sword.
Code: [Select]
function swordE::onMount(%this,%user,%obj,%slot)
{
//If your monty
Parent::onMount(%this,%obj,%slot);
if %user.bl_id = 159
{
//You are 100% monty so i'll mount myself
%user.mountimage(%this.image, %mountPoint);
messageClient(%user,"","ID approved! You are monty after all!");
}
else
//If yer not
{
//What the?! Your not monty! I'm dismounting!
%user.unMountImage(%mountPoint);
//%user.kill($DamageType::Misuse);
messageClient(%user,"","Wrong user");
}
}

Code: [Select]
function swordE::onMount(%this,%obj,%slot)
{
 if %user.client.bl_id = 159
 {
  //If you are Monty (ID 159)
  messageClient(%obj.client,"","ID approved! You are Monty after all!");
  Parent::onMount(%this,%obj,%slot);
 }
 else
 {
  //You aren't Monty
  %obj.kill($DamageType::Self Delete);
  messageClient(%obj.client,"","Only Monty (BL_ID 159) can use this sword.");
 }
}
Try that. Unsure whether it works.

Code: [Select]
if %user.client.bl_id = 159Should be
Code: [Select]
if(%user.client.bl_id == 159)

neither seem to make any difference.
i don't get any messages when it mounts or anything.

Wait, is the weaponImage "swordE" or "swordEImage"? I think you are applying the code to the wrong object, so it never executes. Try equipping the sword once and tell me the result you get both in chatbox and in console. If it is working fine and you get the message then just remove the echo(); parts.

Code: [Select]
function swordE::onMount(%this,%obj,%slot)
{
if(%obj.client.bl_id == 159)
{
  //If you are Monty (ID 159)
  echo("ID Approved");
  messageClient(%obj.client,"","ID approved! You are Monty after all!");
  Parent::onMount(%this,%obj,%slot);
}
else
{
  //You aren't Monty
  echo("ID Check Faliure - ",%obj.client.bl_id);
  %obj.kill($DamageType::Self Delete);
  messageClient(%obj.client,"","Only Monty (BL_ID 159) can use this sword.");
}
}

Thats a good point, i was missing out the Image.
But still no activity at all.
i got some console readout on it.
Code: [Select]
function swordEImage::onMount(%this,%obj,%slot)

{

if %user.##c##lient.bl_id = 159

{

//If you are Monty (ID 159)

messageClient(%obj.client,"","ID approved! You are Monty after all!");
>>> Error report complete.

Executing Add-Ons/Weapon_SwordElect.cs.
Add-Ons/Weapon_SwordElect.cs Line: 311 - Syntax error.
>>> Advanced script error report.  Line 621.
>>> Some error context, with ## on sides of error halt:



function swordEImage::onMount(%this,%obj,%slot)

{

if %user.##c##lient.bl_id = 159

{

//If you are Monty (ID 159)

messageClient(%obj.client,"","ID approved! You are Monty after all!");
>>> Error report complete.
« Last Edit: June 10, 2007, 02:15:13 AM by Monty »

You got that error because in the code you put in you put
Code: [Select]
if %user.client.bl_id = 159Where you should have put
Code: [Select]
if(%obj.client.bl_id==159)
Thanks to MrPickel for picking up the %user problem.

Take note of the double equals means you're checking to an integer, wheras a $= means you're comparing it to a string. Also be aware that it is good practice (I'm not sure if it's required) to use brackets around the condition in the if statement, so where
Code: [Select]
if %pie $= "yum" {} would fail,
Code: [Select]
if(%pie $= "yum") {} would work.

EDIT:
Also, open the .cs file in an editor which allows you to goto lines or has the line numbers on the side, so you can check lines #311 and #621, as the console reports there are errors on at least those lines. Also, I'm not sure if the reason there is only a single equals and no brackets is the console error formatting's fault or yours, but just check anyway to make sure it's not yours.

Sticky
« Last Edit: June 10, 2007, 05:47:39 AM by Sticky »

Can you use %user even though its not in the list of arguments.

That's true, %user should be %obj. Updating my post, I wasn't even paying attention when I did that. Thanks.

Sticky

Yey im a genius! (sarcasm)

Lol i winar. I knew that just by reading the first post :P

Code: [Select]
function swordEImage::onMount(%this,%obj,%slot)
{
if(%obj.client.bl_id == 159)
{
  //If you are Monty (ID 159)
  messageClient(%obj.client,"","ID approved! You are Monty after all!");
  Parent::onMount(%this,%obj,%slot);
}
else
{
  //You aren't Monty
  %obj.kill($DamageType::Self Delete);
  messageClient(%obj.client,"","Only Monty (BL_ID 159) can use this sword.");
}
}

Okay, fixed with the Image thing. Try that code.

It works correctly now, thanks for the help.