Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-20-2003, 02:40 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
% and timevar

Ok, I usually pick up on things really easily, but I just can't pick up on this subject.

First, explain to me how exactly timevar is usefull. How it works and it's purposes.

Second, how can the modulus (%) sign get the time? I have seen many scripts do this but I don't understand how it works.
__________________
new account: Trevor
Reply With Quote
  #2  
Old 02-20-2003, 03:35 AM
RTelvecho RTelvecho is offline
Banned
RTelvecho's Avatar
Join Date: Oct 2002
Location: Toronto, Ontario, Canada
Posts: 807
RTelvecho is on a distinguished road
Send a message via AIM to RTelvecho
timevar uses the server time or something, its more ifficient than adding manually i guess...

% is not for getting time, its like until

this.var=(this.var+1)%5;
Means
Add 1 to this.var until its value is 4 then go back to 0 and start again.
Reply With Quote
  #3  
Old 02-20-2003, 04:27 AM
HoudiniMan HoudiniMan is offline
Playerworld Administrator
HoudiniMan's Avatar
Join Date: Dec 2001
Location: Calfiornia - USA
Posts: 3,512
HoudiniMan is on a distinguished road
since i've never really understood this either tell me if this is right...

say you had a fishing npc and you got 1 gralat for each 7 pounds of fish... could you use something like this where client.fish is how many pounds they've caught...?
NPC Code:

if (playerchats&&strequals(#c,sell fish)) { //or some such...
fishleft=strtofloat(client.fish)%7; //finds if there are fish left over
fishsold=strtofloat(client.fish)-#v(fishleft); //removes left over fish
playerrupees+=(fishsold/7)*1; //total divided by how many bunches you had, times price (1 is optional in this case)
client.fish=fishleft; //restores left over fish as total
}



it would find the remainder and store it as "fish left"
then take it away from the main number of fish and sell the bulk off...
then replace the bulk with what was left over originally...

so if you had 30 fish it would have remainder 2, take two away, sell the 28 for 4g, then replace your ammount with just 2 pounds theoretically...
something i just kinda thought up from reading your guys' posts
__________________
-HoudiniMan (Chief Playerworld Administrator)
Compulsive Support Center Checker - 5 Years and Change
Graal Support Center

Reply With Quote
  #4  
Old 02-20-2003, 04:42 AM
HoudiniMan HoudiniMan is offline
Playerworld Administrator
HoudiniMan's Avatar
Join Date: Dec 2001
Location: Calfiornia - USA
Posts: 3,512
HoudiniMan is on a distinguished road
doesn't int() round to the nearest integer?
or does it always round down, just stripping off the decimels?
cause it you had 13 fish i wouldn't want it to round 1.8 up to 2 and give you any free fish
__________________
-HoudiniMan (Chief Playerworld Administrator)
Compulsive Support Center Checker - 5 Years and Change
Graal Support Center

Reply With Quote
  #5  
Old 02-20-2003, 05:16 PM
Falados Falados is offline
Cucumber NPC
Falados's Avatar
Join Date: Jan 2003
Posts: 141
Falados is on a distinguished road
Send a message via ICQ to Falados Send a message via AIM to Falados
Quote:
Originally posted by HoudiniMan
doesn't int() round to the nearest integer?
or does it always round down, just stripping off the decimels?
cause it you had 13 fish i wouldn't want it to round 1.8 up to 2 and give you any free fish
int() is a conversion statement that converts floating points to integers, It just truncates the floating points disregaurding whether or not its >=.5 or not. If you want to round you could do something like...

var=int(var+0.5);
__________________

subliminal message: 1+1=3
Reply With Quote
  #6  
Old 02-20-2003, 11:55 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by Kaimetsu

And far more accurate/reliable. Timevar represents a precise global time measurement since the start of the server. It increments once every five seconds.
according to stefan timevar is the time since pay to play has come out, but the start time doesn't really matter since all you really need to know is that it increases once every 5 seconds so what you said is accurate enough
Reply With Quote
  #7  
Old 02-21-2003, 02:19 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
What is timevar2 then?

and

What would this return?
NPC Code:
test = (mytimevar%(30*24))*2;

__________________
new account: Trevor
Reply With Quote
  #8  
Old 02-21-2003, 02:34 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
Quote:
Originally posted by Kaimetsu


It would return the remainder of mytimevar divided by 720, multiplied by two.
I meant, What kind of time would it return? What time would you get that with.
__________________
new account: Trevor
Reply With Quote
  #9  
Old 02-21-2003, 04:16 AM
PrinceDark PrinceDark is offline
Criminal X
PrinceDark's Avatar
Join Date: Feb 2003
Location: Miami, Florida
Posts: 662
PrinceDark will become famous soon enough
%
A simple example
NPC Code:

dir=(dir+2)%4;



So let's say you have a npc that has onwall checks and you want it to turn in the other direction when it is at a certain distance from the wall. The above code will make it turn in the opposite direction.

if dir==1. So if the npc has onwall detection while heading left, and it gets near the wall and performs this command it will change the direction to 3.

So to break it down.
dir=(dir+2)%4;
=(1+2)%4
=3 - int(3 / 4) * 4
=3 - int(.75) * 4
=3 - 0*4
=3 - 0

So in the end it will be dir=3

There's another way to rotate the player or npc's. I think it's dir=(dir+1)%4; and it rotates clockwise or counterclockwise. Something like that.

--
For timevar I have no clue. I never used it before and I'll be learning it now when people explain it in this thread I suppose.
__________________
- Criminal X: certified nut case
Reply With Quote
  #10  
Old 02-21-2003, 04:21 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
Quote:
Originally posted by PrinceDark
%
dir=(dir+2)%4;
=(1+2)%4
=3 - int(3 / 4) * 4
=3 - int(.75) * 4
=3 - 0*4
=3 - 0
I understand that. Thank you very much.
__________________
new account: Trevor
Reply With Quote
  #11  
Old 02-21-2003, 04:56 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
Quote:
Originally posted by Kaimetsu
I wish people would stop spreading these stupid modulus rotation methods. They're extremely inefficient - they only look good because they're so short.
How would you rotate an npc to the opisite direction?
__________________
new account: Trevor
Reply With Quote
  #12  
Old 02-23-2003, 09:50 PM
Com013 Com013 is offline
Registered User
Join Date: Aug 2002
Location: GMT+1
Posts: 381
Com013 is on a distinguished road
Quote:
Originally posted by Kaimetsu
dir+=2;
if(dir>3) dir-=4;
But aren't the npc attributes limited to a certain range? Then the dir wouldn't be able to get above 3. (I know, that would be no problem, you'd just use another variable).

And in some cases I'd use while(ndir > 3) instead of if(ndir > 3), just in case it is too big (Which is impossible at the given example).

But why is % slower? I think I've heard that modulo is quite a complex floating point operation, but we normaly have FPUs integrated in the CPUs and the FPU operation would still be faster than interpreting 3 additional Graal Script Commands, wouldn't it?
__________________
Com013
Former Admin of the LAT on Graal The Adventure

e-mail: [email protected]
Reply With Quote
  #13  
Old 02-23-2003, 10:04 PM
Falados Falados is offline
Cucumber NPC
Falados's Avatar
Join Date: Jan 2003
Posts: 141
Falados is on a distinguished road
Send a message via ICQ to Falados Send a message via AIM to Falados
The point is, WHY would you create a floating point if your answer will never need it. Integer mathmatics takes less processor time that floating point.

I mean all the computer has to do is see if an integer is greater then a certain number and then if it is, set it to zero. but the MOD has to do

a-int(a/b)*b to do the same operation. Shorter in the code, but more complex than it needs to be.
__________________

subliminal message: 1+1=3
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.