new var = MyFunc(...)?
#1

Hi, i want to know how to make a function with a variable. Like
pawn Код:
new var = SetTimer(blah);
KillTimer(var);
works.

Because i want to do something like this:
pawn Код:
new zone1 = CreateZone(some floats);
IsPlayerInZone(playerid, zone1) ;
DestroyZone(zone1);
How do i do this?
Reply
#2

You just have to return the value in the function:

Exemple
pawn Код:
new zoneid = -1;

CreateZone()
{
  return zoneid++;
}

new zone1 = CreateZone(); //zone1 is zone id 0
new zone2 = Createzone(); //zone2 is zone id 1
Reply
#3

Oke, but when i want to use this function, after i created a zone: (new zone1 = CreateZone(1342.4352, 321.5788, 1345.3564, 341.9043);
pawn Код:
if(IsPlayerInZone(playerid, zone1))
{
  if(zoneid == zone1)
  {
    printf("How do i show the floats out of CreateZone here?");
  }
}
Reply
#4

Use arrays.
Reply
#5

..Example? I'm not a scripting god you know, i don't have anything at a post like yours. Sorry
Reply
#6

"scripting god" lmao, ok dude I'm in a good mood so I'll give you an example:

pawn Код:
// used to track the amount of zones created and to pass the current ID back out of the custom function
new iZoneCount = -1;

// used to store the coordinates of your created zones, the slot of the array is it's ID (the first dimension)
new Float:fGangZonesCoords[ >>AMOUNT_HERE<< ][ 4 ];


//in your custom create zone function CreateZone( Float:min_x, Float:max_x, ...................

  iZoneCount ++; // increment by one (move to the next zonescoords array slot)
  fGangZonesCoords[ iZoneCount ][ 0 ] = min_x; // pass the values to the array
  //do this for all four
  return iZoneCount; //return the current slot being used, the zones id (the slot in the array)
Reply
#7

why you do this ?
pawn Код:
new Zone1;
new Zone2;
Zone1 = CreateZone...
Zone2 = CreateZone...
why not
pawn Код:
new Zone[15]; // You can change "15" by the maximux zones
Zone[0] = CreateZone...
Zone[1] = CreateZone...
and to destroy all the zones in the same time you can use
pawn Код:
for(new z = 0; z < 15; z ++)
{
DestroyZone(Zone[z]);
}
or this
pawn Код:
if(IsPlayerInZone(playerid, zone1))
{
  if(zoneid == zone[0])
  {
    printf("How do i show the floats out of CreateZone here?");
  }
}
...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)