03.07.2011, 09:01
if your script is not recieving any "get-player-coordinates" action, like picking up a pickup, or entering a checkpiont, then you are right: you will need to script a loop through the entire array of your coordinates, calculating each distance aswell. thats indeed a waste of time. a server holding 50 players and 200 houses, would need to run through 10000 lines checking coordinate arrays (assuming each player wants to go inside somewhere)...
to avoid this, theres a simple trick. look at these lines:
the Pickup[0] doesnt hold just the pickup for showing ingame, or only points to the created object maybe for later deletion, it also contains the (returned) ID of the CreateDynamicPickup(), which can be used as a pointer in the array PickupType[] (with the size as your pickups maximum indeed). thats called a hash-table.
heres an example how i use that method for determining how each pickupid points to a unique interior id:
that array, created in 1 line, looks like
if you enter one of your checkpoints/pickups, make a SendClientMessage line, showing you the (looped and checked) ID, and let it print you the real pickupid. ah, dont forget the [pointed] UniqueID:
enjoy swapping pointers with arrays all time. it could drive you nuts... however, i hope that helps a bit ^^
edit: set the maximum for pickups to 100. then you can seek the chat for the "Match" line heheh (or try with 1000000 pickups and watch the chatlog)
to avoid this, theres a simple trick. look at these lines:
Код:
new UniqueID=10311;//we use this number as any index. an interior maybe? Pickup[0]=CreateDynamicPickup(blablabla);//looks common... PickupType[0]=UniqueID;//some number you need like an interior id? lets point it at the 10311
heres an example how i use that method for determining how each pickupid points to a unique interior id:
Код:
pickupid UniqueID UniqueID (pointed at by using PickupType[pickupid] in OPPUDP) PickupType[ 0 ]= 10311 format(,,"%d",PickupType[pickupid]) PickupType[ 1 ]= 10312 format(,,"%d",PickupType[pickupid]) PickupType[ 2 ]= 20311 format(,,"%d",PickupType[pickupid]) PickupType[ 3 ]= 20312 format(,,"%d",PickupType[pickupid]) PickupType[ 4 ]= 20581 format(,,"%d",PickupType[pickupid]) PickupType[ 5 ]= 20582 format(,,"%d",PickupType[pickupid])
Код:
new PickupType[]={10311,10312,20311,20312,20581,20852};
Код:
public OnPlayerPickUpDynamicPickup(playerid,pickupid){ new string[128]; //loop version for(new id=0;id<200;id++) { format(string,sizeof(string),"id:%d",id); SendClientMessageToPlayer(0xcccc33ff,string); if(pickupid==PickupType[id]) { format(string,sizeof(string),"Match found: PickupType[id]:%d",PickupType[id]); SendClientMessageToPlayer(0x33cc33ff,string); } } //hash table version SendClientMessageToPlayer(0xcc33ccff,"and now a bit faster..."); format(string,sizeof(string),"pickupid:%d PickupType:%d",pickupid,PickupType[pickupid]); SendClientMessageToPlayer(0xccccccff,string);
edit: set the maximum for pickups to 100. then you can seek the chat for the "Match" line heheh (or try with 1000000 pickups and watch the chatlog)