Page 1 of 1

Restriction in magic.inc!

PostPosted: Wed Sep 03, 2003 10:51 pm
by Arcane
How can I put in my magic.inc 1 restriction.
If a player move 15 titles he lost his concetration and miss the spell.

My wrong code:

var X, Y;
var number;
number := 15;
x := caster.x;
y := caster.y;
if( GetEquipmentByLayer( caster, 25 ))
if( !x > number or !y > number)
return 0;
else
endif
else
endif

PostPosted: Wed Nov 12, 2003 6:42 am
by Kardall
At the very very beginning of the magic.inc, put something like:

Code: Select all
var oldx := caster.x;
var oldy := caster.y;


then where you do the skill check to see if they cast it... do something like:

Code: Select all
if( coordDist( caster.x, caster.y, oldx, oldy ) >= 15 )
  // Put Fail Stuff here cause they went too far.
else
   // skillcheck code
   if( checkSkill(who......
...
endif


I hope you have the coordDist() function. It basically checks distance between a set of x/y points... it doesn't check Z so... if you want to do that, do an: || CheckZ(caster.z, oldz)

type of thing and write a Z checking function like that.

PostPosted: Fri Dec 26, 2003 1:33 pm
by Arcane
thanxs
it´s works...
Now this restriction it´s not working:

var prevtime := ReadGameClock() + 5;
if(ReadGameClock() > prevtime)
SendSysMessage(caster, "Voce demorou demais e perdeu o focus.",3,70);
return 0;
endif


what´s wrong? =(

PostPosted: Mon Dec 29, 2003 4:11 pm
by Fistandantilus
Your code is ok, it should compile. But you are not performing anything between prevtime and next line (readgameclock) so that enough time can pass. As it is, restriction will never take place.

Just to check it is ok, change code to this:

Code: Select all
var prevtime := ReadGameClock();
sleep 1;
if(ReadGameClock() > prevtime)
SendSysMessage(caster, "Voce demorou demais e perdeu o focus.",3,70);
return 0;
endif


This should always print the message.

PostPosted: Mon Dec 29, 2003 10:20 pm
by Drocket
That really wouldn't help either, since it would simply always print the message, making the checks rather pointless. The big thing that you need to do is...

var prevtime := ReadGameClock() + 5;

--> Do something here <--

if(ReadGameClock() > prevtime)
SendSysMessage(caster, "Voce demorou demais e perdeu o focus.",3,70);
return 0;
endif

It looks like you want a 5 second time limit for the player to do something, but you never give them a chance to do anything. You save the time, then immediately check the time with no opportunity for the player to do anything.

PostPosted: Tue Dec 30, 2003 8:03 am
by Fistandantilus
Drocket, the code i posted was supposed to do so.. it was just to show Arcane that it worked ;)