Simple Script Help

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
The Jackal
Sergeant Major
Posts: 101
Joined: Wed May 07, 2003 10:09 am
Contact:

Simple Script Help

Post by The Jackal »

I am new to this whole biz of scripting. I think it's sexy though. All I got in my head is some qBasic I learnt a couple a years ago on my DOS PC.
I am working on a script to perform a simple print command.

I would like the correct syntax and argument to display a looped message on screen if a condition is met.

For example.
The script with check to see if FF is on. And if Yes, it would display "TEXT". If NO, it would display "TEXT2"

And loop in at intervals (60secs)

I once saw an example on a message board that contained something like this:

local.ff = 0
get_cvar "g_teamdamage"

if (local.FF==1)
wait 5
iprintInbold "FF is ON"

else
wait 5
iprintInbold "FF is OFF"

Somewhere in it had the [/i][/b]While statement, I guess to perform the loop function.

Please help me. Once I get this I am on my way to more complex ones. [/i][/b]
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Code: Select all

check_ff:
   while ( true )
   {
      wait 60
      if (local.FF==1)
      {
         iprintInbold "FF is ON"
      }
      else
      {
         iprintInbold "FF is OFF" 
      }
   }
end
... for this to work, you must set the local.FF variable to the value of FF... or replace local.FF with a reference to the variable that controls FF ( I dont know what it is called... maby game.teamdamage or something ).
Admin .MAP Forums
Image
Head above heels.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Well I'd make a couple of changes:

Code: Select all

check_ff:
   while (1)
   {
      local.FF = getcvar "g_teamdamage"
      if (local.FF==1)
      {
         iprintlnbold "FF is ON"
      }
      else
      {
         iprintlnbold "FF is OFF"
      }
      wait 5 // just for testing :)
   }
end
Although I'm not sure I don't think while (true) works. Also the command is iprintlnbold (with a 'l'), not iprintInbold (with a capital 'i'). These are just minor things though.
Image
User avatar
The Jackal
Sergeant Major
Posts: 101
Joined: Wed May 07, 2003 10:09 am
Contact:

Thanks for the syntax, but I am still stuck

Post by The Jackal »

I used that syntax and argument. It displays the message onscreen, like it should.

However, the problem is that it does not recognize the state of the cvar "teamdamage"

I turned FF on and restarted, but the script continued to print the text for "FF is OFF".

This is exactly as I have it in mp_malta_dm.scr

check_ff:
while (1)
{
local.FF = getcvar "g_teamdamage"
if (local.FF==1)
{
wait 15
iprintlnbold "Friendly Fire is ON"
}
else
{
wait 15
iprintlnbold "Friendly Fire is OFF"
}
wait 30
}
end

I think the problem lies in line 4. Please see how I can be helped.

Thanks. :roll: [/b]
User avatar
The Jackal
Sergeant Major
Posts: 101
Joined: Wed May 07, 2003 10:09 am
Contact:

Just another quick question.....

Post by The Jackal »

What are the differences between:

While (1) and While (true)?

Doesn't (1) the works the same as (true)?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

if (local.FF==1)

should be

if (local.FF=="1")

:oops:
Image
nihilo
Sergeant Major
Posts: 107
Joined: Thu Mar 13, 2003 6:07 am

Post by nihilo »

thats odd, maybe you could explain this one to me jv

When it looks at local.FF it finds the char 1 (string 1, cause there's no char type) instead of the int value 1? In other words local.FF is equal the symbol "1" or "0" instead of the value 1 or 0?!? Seems bizarre.. do they do this for other things too?
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

guess

Post by tltrude »

This is just a guess, but maybe "1" and "0" mean "on" and "off". Where as 1 and 0 would mean "true" and "false".

Why does it need to continually check if FF is on or off. Shouldn't it just check one time at the start of the round and then print the results in the timed loop?
Last edited by tltrude on Wed May 07, 2003 7:09 pm, edited 1 time in total.
Tom Trude,

Image
nihilo
Sergeant Major
Posts: 107
Joined: Thu Mar 13, 2003 6:07 am

Post by nihilo »

I would think it would be easier to say on and off is the same as true and false. So light == on is the same as light == true. No need to have two different values, right? I don't really know, my experience with MoHAA scripting doesn't come close to many others here.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Would be nice

Post by tltrude »

It would be nice to know it FF is on or off while the map is loading--on the loading screen.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Well you can't use the script to modify the loading screen, since the script is server side whereas the loading screen is client side.

getcvar returns a string, that's why you have to use if(local.ff=="1").
You can also use:

Code: Select all

local.ff = int(getcvar "g_teamdamage")
if(local.ff == 1)
This just casts the getcvar output to a regular integer (which you could use in calculations).
Image
User avatar
The Jackal
Sergeant Major
Posts: 101
Joined: Wed May 07, 2003 10:09 am
Contact:

It Works

Post by The Jackal »

Thanks guys, it works like a charm.

The reason I want it to check and then loop thought-out round is because we do not play Time Limit Rounds. We are a bunch of snipers that hide all night. So if we called the cvar was changed in between rounds, the message can display our rules with cvar status. I am our clan's best scripter and I don't know crap like you guys - GOD HELP US.

Take a look at this script I made. A simple one. It is supposed to print a set of messages when a client logs on, only on that client's screen. I only tested it on my game and not on a full server. Do you think it will do just what I want?

wait 5
$player[0] iprint "Welcome To <[OneX]> Snipers Only!"
if($player[1])
$player[1] iprint "Welcome To <[OneX]> Snipers Only!"
if($player[2])
$player[2] iprint "Welcome To <[OneX]> Snipers Only!"
if($player[3])
$player[3] iprint "Welcome To <[OneX]> Snipers Only!"
.....and so on, and so on.

Will it? Please tell me Yes. It it in the map script file.
nihilo
Sergeant Major
Posts: 107
Joined: Thu Mar 13, 2003 6:07 am

Post by nihilo »

ahh.. ok. I can see that. thx.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

iprint

Post by tltrude »

I think "iprint" will crash it. Try, "iprintln" (thats an L not an I). It stands for iprint line.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

No, iprint is a valid command for the Player class.

The $player array starts indexing at 1 though, so $player[0] is NIL.

Jackal, I suppose you're looping that code or something?
Image
Post Reply