View Single Post
  #37  
Old 06-26-2013, 04:46 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Here's a little tip for understanding the options part of move(), showstats(), enablefeatures() etc and how it works:

If these functions are known to you, you might have noticed the build up of the options going like this

1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 ETC ETC

Basically you can create any numbers using the numbers given above

31 = 1 + 2 + 4 + 8 + 16
30 = 2 + 4 + 8 + 16
29 = 1 + 4 + 8 + 16

Following? Now, why are those functions using numbers like that? Why not use normal numbers from 1 to 10 for example? To answer that, let me set an example up:

PHP Code:
/*
  createNPC(x, y, type, options)
  options:
    1 = randomized look?
    2 = roam around
    3 = hunt and hurt players
*/
function onCreated() {
  
createNPC(xy"baddy"2); // randomized look + roam around

  
createNPC(xy"baddy"3); // function as enemy to the player, hunt & kill
}

function 
createNPC(npcxnpcynpctypeoptions) {
  
// how to tell the difference between 1+2 (randomized look + roam around)
  // and 3 (hunt players and hurt them
  
  
temp.npc putnpc2(npcxnpcy"");
  if (
options == 1+2) {
    
// just give up here and start over., ok?
    //the script can't tell the difference between 1+2 and 3


Now, how can it be done instead? Well, yeah, you use the numbers given further up this post and do like this:

PHP Code:
/*
  createNPC(x, y, type, options)
  options:
    1 = randomized look?
    2 = roam around
    4 =  function as enemy to the player
*/
function onCreated() {
  
createNPC(xy"baddy"2); // randomized look + roam around

  
createNPC(xy"baddy"4); // function as enemy to the player, hunt & kill
}

function 
createNPC(npcxnpcynpctypeoptions) {
  
temp.npc putnpc2(npcxnpcy"");
  
temp.npc.join("npc_"npctype); // would join npc_baddy
  
temp.npc.type npctype;

  if (
options&1temp.npc.join("npc_module_randomizedlook");
  if (
options&2temp.npc.join("npc_module_roam");
  if (
options&4temp.npc.join("npc_module_enemyai");

By using the & operator you can simply check if a bit value exists within the specified bit value given.

so instead of doing something like createNPC(x, y, type, true, true, false);, or set up predefined options, use this method instead!
__________________

Last edited by Chompy; 06-26-2013 at 06:05 PM..
Reply With Quote