Page 1 of 1

Law System Fail

Posted: April 30th, 2012, 9:07 pm
by donnelly517
I'm making a law system for my rpg. There are men and woman who wander the streets of cities and towns, and killing one causes a variable to be set to 2. If this variable is at 2 then the guards will attack you on sight, and upon your death the variable is set back to 0, so guards will act normally. It seems that the script for people is working, but the guards will not attack you even after killing many people.

Code: Select all

include scripts/1

]
r_script_signal hit [
    r_action_clear self
    r_action_attack self actor
    r_sound "iolar/slice"
  ]
]

]
r_script_signal spawn [
  r_action_wander self 0 256 0
  r_additem self 8 1
  r_equip self 8 0
  ]
]

]
r_script_signal attacksound [
	r_sound "iolar/attack" self
]

]
r_script_signal death [
    r_sound "iolar/citizendie"
]
Men and women's script.

Code: Select all

include scripts/1

r_script_signal talk [
  if (!= (r_get_faction self) (r_get_faction actor)) [
    r_action_clear self
    r_action_attack self actor
  if (= (r_get_faction self) (r_get_faction actor)) [
      r_sound "Iolar/greet" self
  ]
]

r_script_signal hit [
    r_action_clear self
    r_action_attack self actor
    r_sound "Iolar/slice" self
  ]
]

r_script_signal update [
  if (r_cansee self player) [
      (case r_global_get $highfrostcriminal)
           if r_global $highfrostcriminal = 2
               r_action_clear self
               r_action_attack self player 1
  ]
]

r_script_signal collide [
  if (!= (r_get_faction self) (r_get_faction actor)) [
    r_action_clear self
    r_action_attack self actor
  ]
]
r_script_signal spawn [
  r_additem self 2 1
  r_equip self 2 0
  ]

Guard's script.
I've tried changing a lot of things but nothing seems to help. Anybody know what's wrong. I also want to figure out more about variables so it's easier to make quests.

Re: Law System Fail

Posted: April 30th, 2012, 9:46 pm
by Sircameron
The if statement is wrong in for the check to see if they're a criminal or not it needs to be

Code: Select all

if ((r_global_get $highfrostcriminal) 2)
Thats the only mistake i see

Re: Law System Fail

Posted: April 30th, 2012, 10:02 pm
by Hirato
by the looks of it, you're not setting any variables.


Also, I'm noticing a lot of errors in your scripts too...
You appear to be trying to set the hit signal inside the talk signal's block. (both of them)

and then there's the update signal for the guards....
Oh boy... just where do I start... (quickly annotated version below)

Code: Select all

r_script_signal update [
  if (r_cansee self player) [ //good up till this point
      (case r_global_get $highfrostcriminal) //useless statement; doesn't do anything EVER
           if r_global $highfrostcriminal = 2 // effectively if [r_global] [$highfrostcriminal] [=]; completely wrong and useless; the tutorial did go over querying and setting global variables around part 6
               r_action_clear self //these are always executed
               r_action_attack self player 1
  ] // "cansee player" block closes
]
Below is a version that's a bit more correct and does what I think you wanted to do...

Code: Select all

r_script_signal "update" [
    if (&& (r_cansee self player) [= (r_global_get $highfrostcriminal) 2]) [
        r_action_clear self
        r_action_attack self player 1
    ]
]
Anyways, to do it properly, you should really be changing the faction relationships with the player faction and the town's faction.
Basically make them less friendly every time he hurts or kills someone to the point where they attack him on sight.

EDIT: since you're using the SVN, I did set up some basics inside base/scripts/1.cfg to allow the NPCs to respond to the various things they can see around them, friendlies and hostiles included,

Re: Law System Fail

Posted: May 1st, 2012, 7:32 pm
by donnelly517
These script mistakes and probably the reason my games won't move to SVN. Starting fresh isn't always a bad thing though, and I can salvage a lot of things I'd like to keep.

Re: Law System Fail

Posted: May 1st, 2012, 11:09 pm
by Hirato
The changes you'll need to make to convert things from a 2.7.1 compatible form to a 2.8.0/SVN compatible form are relatively minimal. From what I remember they basically stem to how you treat items in scripts.
For the most part, it'll boil down to this...

Code: Select all

//old - now broken
r_script_signal spawn [
    r_additem self 5 1
    r_equip self 5 0
]

//new
r_script_signal spawn [
    r_additem self 5 1 [ r_equip actor self 0 ]
]

Meanwhile, the errors in your scripts will need to be remedied regardless of whether or not you decide to stick with 2.7.1 or decide to help test the next version. As it is incorrect and broken for both cases.

Re: Law System Fail

Posted: May 6th, 2012, 6:09 pm
by donnelly517
How can I get the realtionship between the player and guards to change in SVN?