A question...
#1

How to make it check if the player is on the right co-ordinates for a specific command? I mean, I know like for /enter command, how to check and all, but if there is 200 houses on the server, would I have to do 200 lines that check if the player is at the right entrance or a loop? Is there any other way to do it. Also, if I wanted to show a player a message when he steps infront of someone's door, would I have to do a loop and check it every time in OnPlayerUpdate (sounds a bit laggy to me). How to check a players position for a large number of positions, when he updates, but in an efficient way?
Reply
#2

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:
Код:
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
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:
Код:
		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])
that array, created in 1 line, looks like
Код:
new PickupType[]={10311,10312,20311,20312,20581,20852};
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:
Код:
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);
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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)