lever triggered ONLY by allies and once

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Dani
Sergeant Major
Posts: 113
Joined: Mon Mar 08, 2004 6:45 pm
Contact:

lever triggered ONLY by allies and once

Post by Dani »

Wat scripting do i need to do, so that a lever with a trigger_use can ONLY be triggered once and ONLE by allies??? Thanks for your help (probs obvious)
Angex
Major
Posts: 293
Joined: Mon Dec 30, 2002 1:23 pm
Contact:

Post by Angex »

How about this to get you started, but keep in mind there is more than one way of doing it:

Code: Select all


thread alliesLever:

// Controls the checking loop.
local.triggered = 0

// While the trigger hasn't been used by allies, keep checking.

while (!local.triggered) {
    // Wait till it's used.
    $trigger waittill trigger

    // Find out who used it.
    local.player = param.other

    // Check what team they're on.
    if (local.player.dmteam == "allies") {
        // Allied player used the trigger, end the check loop.
        local.triggered = 1

        // Make the lever do something.
    }
}

end

Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

thread alliesLever:

$trigger waittill trigger

// Find out who used it.
local.player = parm.other

// Check what team they're on.
if (local.player.dmteam == "allies")
{
do whatever
// Make the lever do something.
}
else
{
goto thread alliesLever
}
end


I wouldnt bother with global variables in this case, if an axis triggers it, nothing happens and it resets, if an ally triggers it, the thread is done. Either would work tho.
When I am king, you will be first against the wall~
Image
Angex
Major
Posts: 293
Joined: Mon Dec 30, 2002 1:23 pm
Contact:

Post by Angex »

Splaetos wrote:I wouldnt bother with global variables in this case
Good job I made them local :)

It all depends on whether you like using goto, personally I always try to avoid it. Although for MoH scrippting it's not too bad since there are certain limitations to using it.
Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

eh? so I cant read ~

anyway, id prefer not using any variables~~~ Cause moh scripting is stupid --

but either way works

I dont particularly favor while loops either, in any language. (not that i dont use them, ive just had more bugs from them then anything else)
When I am king, you will be first against the wall~
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I don't see anything wrong with variables :? or while loops :roll:

goto is evil though :evil: :wink:
Image
Dani
Sergeant Major
Posts: 113
Joined: Mon Mar 08, 2004 6:45 pm
Contact:

Post by Dani »

So if i do the one Splaetos says then i will have a trigger that only works once and can only be triggered by allies? I have chosen this one for 2 resons, 1 cos it has less script, 2 cos i know a bit bout programing and this looks better.
Thanks
Angex
Major
Posts: 293
Joined: Mon Dec 30, 2002 1:23 pm
Contact:

Post by Angex »

Yes Splaetos' script will do what you want.

I guess that means you're in the goto camp :D
Splaetos
Major General
Posts: 730
Joined: Tue Jan 20, 2004 2:55 pm
Contact:

Post by Splaetos »

If i had been awake and seen that they were local variables I probably wouldnt have bothered to post an alternative =) I dont hate while loops that much. I do think they are a common culprit or inneffieceny and occasionaly problems, but that doesnt really matter in this context(and in this game much at all - who cares if a loop doesnt terminate, no one is going ot notice a few computations while playing moh). I do use alot of while loops with checks inside them, but I try and stay away from some of the other neverending while loops(although sometimes it proves impossible)

I dont see any problem with goto tho =p In this case it does the same thing as the while loop, and ive never seen problems with threads when you run them over and over, thats the point of them, the while loop saves effort if there is alot to repeat outside the loop... but not much else.
When I am king, you will be first against the wall~
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

shorter

Post by tltrude »

I bet I can make it even shorter.

Give the trigger a setthread for "allied_lever"--using that, you don't need waittill.

allied_lever:
local.player = parm.other
if (local.player.dmteam != "allies")
end
$trigger remove
//do whatever
end


Ha ha!
Tom Trude,

Image
Dani
Sergeant Major
Posts: 113
Joined: Mon Mar 08, 2004 6:45 pm
Contact:

Post by Dani »

so do i just do this?:

allied_lever:
local.player = parm.other
if (local.player.dmteam != "allies")
end
$trigger remove
//The bit were the sound comes in, and the gate moves ect
end
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

jv_map wrote:goto is evil though :evil: :wink:
Word!

You should have proof that you have a very high education and lots of years of programming/scripting practice before you are allowed to use goto.

I see one use for it: Getting out of very deeply nested for statements when break would be unpractical...

goto = :evil:

:)
Admin .MAP Forums
Image
Head above heels.
User avatar
HDL_CinC_Dragon
Brigadier General
Posts: 574
Joined: Mon Dec 22, 2003 8:32 pm

Post by HDL_CinC_Dragon »

lol, a competition over goto's and loops and shorter scripts lol.
Image
Post Reply