Welcome to CWG Project Home
Search
Home · Topics · Downloads · Your Account · Forums · Top 10
 
 


 
 
Who is Online

There are currently, 163 guest(s) and 38 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
 
 

 
 
Modules

· Home
· Content
· Downloads
· FAQ
· Feedback
· Forums
· Journal
· Members List
· Private Messages
· Recommend Us
· Reviews
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Web Links
· Your Account
 
 

 
 
Search



 
 

 
  cwg.lazuras.org :: View topic - Script Problem
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script Problem

 
Post new topic   Reply to topic    cwg.lazuras.org Forum Index -> Builder Lounge
View previous topic :: View next topic  
Author Message
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 3:31 am    Post subject: Script Problem Reply with quote

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.

Thanks in advance,
Dean
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Jamdog
CWG - Honored Elder


Joined: Jun 18, 2006
Posts: 1685
Location: Halesowen, England

PostPosted: Thu Dec 04, 2008 6:08 am    Post subject: Reply with quote

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

_________________

Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 7:34 am    Post subject: Reply with quote

Doesn't appear to work except for this part.
Code:
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. Cool
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Jamdog
CWG - Honored Elder


Joined: Jun 18, 2006
Posts: 1685
Location: Halesowen, England

PostPosted: Thu Dec 04, 2008 9:58 am    Post subject: Reply with quote

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.
_________________

Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 10:15 am    Post subject: Reply with quote

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. Laughing

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.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Fizban
CWG - Honored Elder


Joined: Nov 26, 2005
Posts: 1390
Location: Shelby Township, Michigan

PostPosted: Thu Dec 04, 2008 11:13 am    Post subject: Reply with quote

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. Laughing

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Fizban
CWG - Honored Elder


Joined: Nov 26, 2005
Posts: 1390
Location: Shelby Township, Michigan

PostPosted: Thu Dec 04, 2008 11:16 am    Post subject: Reply with quote

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

_________________

DG Script Reference Forum
4 Dimensions
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 11:25 am    Post subject: Reply with quote

Fizban wrote:
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. Laughing

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.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Fizban
CWG - Honored Elder


Joined: Nov 26, 2005
Posts: 1390
Location: Shelby Township, Michigan

PostPosted: Thu Dec 04, 2008 11:28 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 10:53 pm    Post subject: Reply with quote

Thanks guys, works a treat.

*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. Laughing
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Thu Dec 04, 2008 11:03 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Fizban
CWG - Honored Elder


Joined: Nov 26, 2005
Posts: 1390
Location: Shelby Township, Michigan

PostPosted: Thu Dec 04, 2008 11:18 pm    Post subject: Reply with quote

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?


if %actor.PartInPlay% != Tau

if %actor.PartInPlay% == Tau
_________________

DG Script Reference Forum
4 Dimensions
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dean
CWG - Member


Joined: Dec 12, 2006
Posts: 74

PostPosted: Fri Dec 05, 2008 1:33 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Fizban
CWG - Honored Elder


Joined: Nov 26, 2005
Posts: 1390
Location: Shelby Township, Michigan

PostPosted: Fri Dec 05, 2008 1:37 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mordecai
CWG - Honored Elder


Joined: Mar 31, 2004
Posts: 316
Location: New Zealand

PostPosted: Sun Dec 21, 2008 11:42 pm    Post subject: Reply with quote

Just for fun I will do the script too. Smile
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

_________________

Mordecai from http://4dimensions.org
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    cwg.lazuras.org Forum Index -> Builder Lounge All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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

Powered by phpBB © 2001, 2005 phpBB Group
 
 


 
 


All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest ? 2002 by me
You can syndicate our news using the file backend.php or ultramode.txt
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.28 Seconds