23.11.2012, 19:52
yes, there is a way.
when creating pickups, lets say 100 of them, then each single created pickup will return a value, the pickupID. you can use that id as pointer to a cell in the PickupType array:
lets pretend you create 3 pickups, which return the ids 41,42 and 43: (if 40 pickups were created before)
this is very important not to mess up:
PickupType[pickup[0]] upto PickupType[pickup[2]] contains the id 41,42 and 43 now, so when you pickup one of those, the onplayerpickuppickup callback will use f.ex 41 as pickupid - use THAT pickupid to access the previously mentioned array:
look how beautiful that looks! the pickups were created by using an array, a pointer, and the content, but the line above works just fine - pickupid==41, PickupType[pickupid]==PICKUP_ACTION_MONEY - and thats 1.
uising a little more memory will give you a superior performance increase - regardless of the amount of pickups, it will always run in the same time: 1 cycle only. no loops, no if-else spaghetti codes - just:
did i miss something? wrote that in a hurry, excuse any mistake. the concept should be clear, nevertheless...
>>>important<<<<
make SURE that the PickupType[] array is equal or bigger in size than your maximum pickups amount. an array [4000] cells wont eat your ram, but a [99] with 100 pickups created, WILL crash your server as soon the array index is out of bounds! (i had that with 4001 deers hopping around lol)
added explanation:
here, only the last pickupid gets stored in pickupone, its being overwritten each time, the previous pickupid gets lost. there is no guarantee that pickupids are being created sequentially btw.
hint: instead of "Pickup", try "DynamicPickup", using the Streamer Plugin
when creating pickups, lets say 100 of them, then each single created pickup will return a value, the pickupID. you can use that id as pointer to a cell in the PickupType array:
Код:
//ok, here some definitions as action type to perform - i added Money just for explaining purposes #define PICKUP_ACTION_MONEY 1 #define PICKUP_ACTION_WEAPONS 2 new PickupType[100];
Код:
pickup[0]=CreatePickup(blabla);//#41 PickupType[pickup[0]]=PICKUP_ACTION_MONEY; pickup[1]=CreatePickup(blabla);//#42 PickupType[pickup[1]]=PICKUP_ACTION_MONEY; pickup[2]=CreatePickup(blabla);//#43 PickupType[pickup[2]]=PICKUP_ACTION_MONEY;
PickupType[pickup[0]] upto PickupType[pickup[2]] contains the id 41,42 and 43 now, so when you pickup one of those, the onplayerpickuppickup callback will use f.ex 41 as pickupid - use THAT pickupid to access the previously mentioned array:
Код:
new PerformAction=PickupType[pickupid];
uising a little more memory will give you a superior performance increase - regardless of the amount of pickups, it will always run in the same time: 1 cycle only. no loops, no if-else spaghetti codes - just:
Код:
switch(PerformAction) { case PICKUP_ACTION_MONEY: { GivePlayerMoney(blabla); } case PICKUP_ACTION_WEAPONS: { GivePlayerWeapon(blabla); } }
>>>important<<<<
make SURE that the PickupType[] array is equal or bigger in size than your maximum pickups amount. an array [4000] cells wont eat your ram, but a [99] with 100 pickups created, WILL crash your server as soon the array index is out of bounds! (i had that with 4001 deers hopping around lol)
added explanation:
Код:
pickupone = CreatePickup(); pickupone = CreatePickup(); pickupone = CreatePickup();
hint: instead of "Pickup", try "DynamicPickup", using the Streamer Plugin