Posted: Thu Dec 04, 2008 3:31 am Post subject: Script Problem
Ok, when I attempted this I pretty much assumed it was beyond my current abilites but I had a go anyway.
Here's the script in its two parts
Part 1: The east part that works fine enough
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: yes
Commands:
if %actor.is_pc%
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% &&
!%actor.varexists(orkplayer)%
say You can play as the Imperial Guard, Chaos, Tau or the Orks. Just say which team you want and I'll hook you up.
else
say You're already in the game dude! You need to say play if you want to go in.
end
end
And part 2, the problomatic bit!
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: Tau, Imperial Guard, Orks, Chaos, Play
Commands:
if %speech% == Tau
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
set tauplayer
remote tauplayer %actor.id%
end
elseif %speech% == Imperial Guard
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
set imperialguardplayer
remote imperialguardplayer %actor.id%
end
elseif %speech% == Orks
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
set orkplayer
remote orkplayer %actor.id%
end
elseif %speech% == Chaos
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
set chaosplayer
remote chaosplayer %actor.id%
end
elseif %speech% == play
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
say You need to join a team to be able to play.
else
say Alright, have fun!
teleport %actor% 5344
end
end
So the two things in testing this script that didn't seem to work are A) if %speech% == Tau line and B) the teleport %actor% 5344 line. Everything else works peachy.
And to briefy explain what its supposed to do, a PC is present with 4 choices (teams) that they can join and participate in a "Virtual Reality" game I made in an arcade. The PC chooses whichever option and provided they haven't already selected a team, the variable for that team will be assigned to them. Once they have a team, another can't be chosen or can they be removed from "their duties to the team"
And the function the variables serve themselves besides determining whether or not a player is on a team, the NPC's in this "VR game" check the PC's and other NPC's for the variable for their own team and if the intended target doesn't have it, the NPC will attack. Also team specific is present that checks this variable so a player from one team can't wear another teams gear and so forth.
Joined: Jun 18, 2006 Posts: 1685 Location: Halesowen, England
Posted: Thu Dec 04, 2008 6:08 am Post subject:
There are a few improvements that can be made to your second script. Firstly, you are repeating a long 'if' line:
Code:
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
but this could just be checked just once by checking this first.
Also, an 'if' should be
Code:
if
elseif
elseif
else
end
But, you are putting
Code:
if
end
elseif
end
elseif
end
Each if should have one end, with as many elses inbetween as necessary.
When comparing strings, it's often better to use /= instead of ==, which checks to see if the string on the right is in the string on the left.
So, abcdefghijklmnopqrstuvwxyz /= defg would return TRUE. This is useful for speech trigs, where a player may type "say I'd like to play Orks, please", then %speech /= Orks would still work.
Finally, I'm assuming it should teleport the actor if they choose a valid option, but your script has this in an 'else', so it will only teleport if the player says something that the script doesn't recognise. To cure this, if the player says something not recognised, the script stops running. If the script keeps running, then it will teleport the player.
Here is a re-written script which is easier to read. I can't promise it's correct, because I haven't tested it, but it is more likely to work.
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: Tau, Imperial Guard, Orks, Chaos, Play
Commands:
if !%actor.varexists(imperialguardplayer)% && !%actor.varexists(tauplayer)% && !%actor.varexists(chaosplayer)% && !%actor.varexists(orkplayer)%
if %speech% /= Tau
set tauplayer
remote tauplayer %actor.id%
elseif %speech% /= Imperial Guard
set imperialguardplayer
remote imperialguardplayer %actor.id%
elseif %speech% /= Orks
set orkplayer
remote orkplayer %actor.id%
elseif %speech% /= Chaos
set chaosplayer
remote chaosplayer %actor.id%
elseif %speech% /= play
say You need to join a team to be able to play.
return 0
halt
else
say Sorry, that's meaningless to me. Just say which team you wish to join.
return 0
halt
end
say Alright, have fun!
teleport %actor% 5344
else
say You have already chosen, it's too late to change your mind now.
end
else
say You have already chosen, it's too late to change your mind now.
end
Heroes is occupying my attention for the next 49 minutes so I'll have a more proper look at it when the programs over in anycase I still learned something which is alway good, so thanks Jamdog.
Joined: Jun 18, 2006 Posts: 1685 Location: Halesowen, England
Posted: Thu Dec 04, 2008 9:58 am Post subject:
That bit is hit if the player has already chosen (they already have one of the variables attached). If you stat <player>, you should see the attached variables listed at the bottom.
You can use the vdelete command to remove these variables from the player, then try the script again. _________________
Forgot to post after I'd tested it earlier. Tried all four and only Imperial Guard got a reaction as desired. The teleport line doesn't work either, I'm guessing I might have to change it to mteleport instead. Not sure how much difference it makes, but I probaly should of mentioned that the codebase is CWG Rasputin 3.51 off the top of my head.
My brain has zombified from days of no sleep so I won't attempt a rewrite that I'd promised myself. Uber tiredness + scripting = bad.
PS. Is it possible to have it check for the variable instead of not having it? It seems more logical to do it that way if it were possible.
Joined: Nov 26, 2005 Posts: 1390 Location: Shelby Township, Michigan
Posted: Thu Dec 04, 2008 11:13 am Post subject:
Dean wrote:
Forgot to post after I'd tested it earlier. Tried all four and only Imperial Guard got a reaction as desired. The teleport line doesn't work either, I'm guessing I might have to change it to mteleport instead. Not sure how much difference it makes, but I probaly should of mentioned that the codebase is CWG Rasputin 3.51 off the top of my head.
My brain has zombified from days of no sleep so I won't attempt a rewrite that I'd promised myself. Uber tiredness + scripting = bad.
PS. Is it possible to have it check for the variable instead of not having it? It seems more logical to do it that way if it were possible.
The teleport should be %teleport%, as for the rest of the script gimme 5 minutes and I'll rewrite it. _________________ DG Script Reference Forum 4 Dimensions
Joined: Nov 26, 2005 Posts: 1390 Location: Shelby Township, Michigan
Posted: Thu Dec 04, 2008 11:16 am Post subject:
First let's change the first script to this:
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: yes
Commands:
if %actor.is_pc%
if !%actor.varexists(PartInPlay)%
say You can play as the Imperial Guard, Chaos, Tau or the Orks. Just say which team you want and I'll hook you up.
else
say You're already in the game dude! You need to say play if you want to go in.
end
end
Forgot to post after I'd tested it earlier. Tried all four and only Imperial Guard got a reaction as desired. The teleport line doesn't work either, I'm guessing I might have to change it to mteleport instead. Not sure how much difference it makes, but I probaly should of mentioned that the codebase is CWG Rasputin 3.51 off the top of my head.
My brain has zombified from days of no sleep so I won't attempt a rewrite that I'd promised myself. Uber tiredness + scripting = bad.
PS. Is it possible to have it check for the variable instead of not having it? It seems more logical to do it that way if it were possible.
The teleport should be %teleport%, as for the rest of the script gimme 5 minutes and I'll rewrite it.
I should have taken off the tin foil hat and gotten a coffee earlier. The amount of times I've used that in recent times, I should have remembered.
Joined: Nov 26, 2005 Posts: 1390 Location: Shelby Township, Michigan
Posted: Thu Dec 04, 2008 11:28 am Post subject:
Voila!
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: Tau Imperial Guard Orks Chaos Play
Commands:
if %speech% /= play
if %actor.varexists(PartInPlay)%
say Alright, have fun!
%teleport% %actor% 5344
else
say You need to join a team to be able to play.
end
else
if !%actor.varexists(PartInPlay)%
if %speech% /= Tau || %speech% /= Imperial Guard || %speech% /= Orks || %speech% /= chaos
if %speech% /= Tau
set PartInPlay Tau
elseif %speech% /= Imperial Guard
set PartInPlay Imperial Guard
elseif %speech% /= Orks
set PartInPlay Orks
elseif %speech% /= Chaos
set PartInPlay Chaos
end
remote PartInPlay %actor.id%
else
say Sorry, that's meaningless to me. Just say which team you wish to join.
end
else
say You have already chosen, it's too late to change your mind now.
end
end
WARNING: This is about as well tested as the theory that all babies are actually born as elephants and later stay elephants or become human, which surprisingly has no evidence to support it and was just made up from the drunken mind of Fizban.
EDIT: By the way, I failed, that is the same # of lines as Jamdog's, I wasn't able to shorten it. It also took me 25 minutes, not 5. _________________ DG Script Reference Forum 4 Dimensions
*edit: I think the lesson among others for me is to simplify the whole process. I, at least in my eyes went about trying to make it more 'complicated' than it needed to be.
Ok, so I went about updating the other triggers that search for the team variables (eg: NPCs that attack NPCs and PCs of other teams) I went ahead and used as partinplay tau and didn't work, should it be partinplay: tau instead, or something else?
Joined: Nov 26, 2005 Posts: 1390 Location: Shelby Township, Michigan
Posted: Thu Dec 04, 2008 11:18 pm Post subject:
Dean wrote:
Ok, so I went about updating the other triggers that search for the team variables (eg: NPCs that attack NPCs and PCs of other teams) I went ahead and used as partinplay tau and didn't work, should it be partinplay: tau instead, or something else?
Thanks again, I've learnt more than one thing today though, thats bad luck? My only question now is; is that like a variable array of sorts or is called something else?
Joined: Nov 26, 2005 Posts: 1390 Location: Shelby Township, Michigan
Posted: Fri Dec 05, 2008 1:37 am Post subject:
Nope, no special term, just checking the value of one variable instead of checking for the existence of several.
Also it dawned on me that it may not have been clear.
In any script checking PartInPlay always check for:
if %actor.varexists(PartInPlay)%
before checking for its value with something like
if %actor.PartInPlay% == Tau
otherwise you run the risk of it sending an error message when it reaches the line where it checks the value of the variable if the variable doesn't exist. _________________ DG Script Reference Forum 4 Dimensions
Joined: Mar 31, 2004 Posts: 316 Location: New Zealand
Posted: Sun Dec 21, 2008 11:42 pm Post subject:
Just for fun I will do the script too.
Keep my hand in.
(Based off Fizzy's cleaned up version)
Code:
Trigger Intended Assignment: Mobiles
Trigger Type: Speech , Numeric Arg: 100, Arg list: Tau Imperial Guard Orks Chaos Play
Commands:
set keywords "Imperial Guard" "Tau" "Orks" "Chaos"
set teams Imperial Guard, Tau, Orks, Chaos
if %speech% /= play
if %actor.varexists(PartInPlay)%
say Alright, have fun in the %actor.PartInPlay% team!
%teleport% %actor% 5344
else
say You need to join a team to be able to play.
end
else
if !%actor.varexists(PartInPlay)%
if %keywords.contains("%speech%")%
set PartInPlay %speech%
remote PartInPlay %actor.id%
say Welcome to the %actor.PartInPlay% team, say Play to start.
else
say Sorry, that's meaningless to me. Just say which team you wish to join.
say You can choose: %teams%
end
else
say You have already chosen, it's too late to change your mind now.
end
end
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum