Author Topic: My script isn't doing what i want it too  (Read 1968 times)

I'm very new to scripting, I've been wanting to do it for years, but have only been giving it a proper go recently.
I've gone through the syntax guide on garagegames, looked at youtube videos, and i am able to do the very basic stuff. Now i want to make a script that would make things happen in game. This script is useless, its just meant as scripting practice.

Code: [Select]
function servercmdresetgun(%client)
{    
  if(gunimage.projectile == gunimage.projectile = gunprojectile)
  {
    %client.chatmessage("\c6Gun has already \c3reset\c6.");
  }
  else
  {
    gunimage.projectile = gunprojectile;
    %client.chatmessage("\c6Gun \c3reset\c6.");
  }
}

function servercmdrocketgun(%client)
{
  if(gunimage.projectile == gunimage.projectile = rocketlauncherprojectile)
  {
    %client.chatmessage("\c6Rocket projectiles are alredy \c3activated\c6.");
  }
  else
  {
    gunimage.projectile = rocketlauncherprojectile;
    %client.chatmessage("\c6Rocket projectiles \c3ACTIVATED\c6!");
  }
}

The script is meant to change the projectiles of the default weapon "Gun", which i can already do. But to take it up a step, I want it so that if i type /resetgun in game, while already on the default gun settings, it will give me a message in game "Gun has already reset." Same for when i type /rocketgun while already on the slightly modded version of the gun, it will give the message Rocket projectiles are already activated."

I know that what im doing wrong is in the
Code: [Select]
if(gunimage.projectile == gunimage.projectile = gunprojectile)and i know that my approach to that control statement is completely wrong... so if someone could correct that line I'd be very grateful ^^

Thanks in advance.

Code: [Select]
if(GunImage.projectile == GunProjectile)

Code: [Select]
if(GunImage.projectile == GunProjectile)

I made the changes, but it still wont work, as if the control statement is always false

I made the changes, but it still wont work, as if the control statement is always false
What exactly is going wrong?

Syntax error?

Or possibly naming the DataBlock wrong for the rocket??

theres no syntax errors, i can change the projectiles perfectly fine.
Whats not happening, is there is no message saying "gun has already reset" when i type /resetgun while the gun is using gun projectiles
and there is no message saying "rocket projectiles are already activated" when i type /rocketgun while the gun is using rocket projectiles.

did you change the if() statements like Pacnet told you to?

It should look like this;

function servercmdresetgun(%client)
{   
  if(gunimage.projectile == gunprojectile)
  {
    %client.chatmessage("\c6Gun has already \c3reset\c6.");
  }
  else
  {
    gunimage.projectile = gunprojectile;
    %client.chatmessage("\c6Gun \c3reset\c6.");
  }
}

function servercmdrocketgun(%client)
{
  if(gunimage.projectile == rocketlauncherprojectile)
  {
    %client.chatmessage("\c6Rocket projectiles are alredy \c3activated\c6.");
  }
  else
  {
    gunimage.projectile = rocketlauncherprojectile;
    %client.chatmessage("\c6Rocket projectiles \c3ACTIVATED\c6!");
  }
}
« Last Edit: August 15, 2012, 09:28:19 AM by nerraD »

Code: [Select]
if(GunImage.Projectile == RocketLauncherProjectile)

did you change the if() statements like Pacnet told you to?

It should look like this;

function servercmdresetgun(%client)
{   
  if(gunimage.projectile == gunprojectile)
  {
    %client.chatmessage("\c6Gun has already \c3reset\c6.");
  }
  else
  {
    gunimage.projectile = gunprojectile;
    %client.chatmessage("\c6Gun \c3reset\c6.");
  }
}

function servercmdrocketgun(%client)
{
  if(gunimage.projectile == rocketlauncherprojectile)
  {
    %client.chatmessage("\c6Rocket projectiles are alredy \c3activated\c6.");
  }
  else
  {
    gunimage.projectile = rocketlauncherprojectile;
    %client.chatmessage("\c6Rocket projectiles \c3ACTIVATED\c6!");
  }
}

yup thats just how mine looks, i even copy/pasted it in to clarify, but now when i say /resetgun it will always say "gun has already reset", and when  i type /rocketgun it always says "rocket projectiles are already activated, without actually changing to rocket projectiles

try if(gunimage.projectile $= "gunprojectile")

if i was at home i'd quickly fix this

try if(gunimage.projectile $= "gunprojectile")

if i was at home i'd quickly fix this
haha, well i appreaciate your help.
my script now looks like this:
function servercmdresetgun(%client)
{   
  if(GunImage.projectile $= "GunProjectile")
  {
    %client.chatmessage("\c6Gun has already \c3reset\c6.");
  }
  else
  {
    gunimage.projectile = gunprojectile;
    %client.chatmessage("\c6Gun \c3reset\c6.");
  }
}

function servercmdrocketgun(%client)
{
  if(gunimage.projectile $= "rocketlauncherprojectile")
  {
    %client.chatmessage("\c6Rocket projectiles are alredy \c3activated\c6.");
  }
  else
  {
    gunimage.projectile = rocketlauncherprojectile;
    %client.chatmessage("\c6Rocket projectiles \c3ACTIVATED\c6!");
  }
}
and its still doign the same thing :/

Well since I do not know what is happening, try doing something like this

$RocketGun = 0;

function servercmdresetgun(%client)
{   
  if(!$RocketGun)
  {
    %client.chatmessage("\c6Gun has already \c3reset\c6.");
  }
  else
  {
    $RocketGun = 0;
    gunimage.projectile = gunprojectile;
    %client.chatmessage("\c6Gun \c3reset\c6.");
  }
}

function servercmdrocketgun(%client)
{
  if($RocketGun)
  {
    %client.chatmessage("\c6Rocket projectiles are alredy \c3activated\c6.");
  }
  else
  {
    $RocketGun = 1;
    gunimage.projectile = rocketlauncherprojectile;
    %client.chatmessage("\c6Rocket projectiles \c3ACTIVATED\c6!");
  }
}

i tried playing with that idea before i posted the topic, but i never used the "!", can you explain what it is?
and nope its still not working :/ the gun projectiles wont change (right now they're set as gunprojectile)
when i type /resetgun it always says "Gun has already reset"
When i type /rocketgun it always says "Rocket projectiles are already activated"

the ! is the opposite

the ! is the opposite

opposite meaning if the statement was true, it would go to the false logic?