Pickups problem -
Amine_Mejrhirrou - 23.11.2012
Hello all.
i have a problem with pickups
i would like to creat a multiple pickups that can do the same thing !
i have tried this
Код:
new pickupone;
//at OnGameModeInit
pickupone = CreatePickup(2000, 2, 2184.93, 944.26, -23.20, -1);//this pickup exist in game dont respond
pickupone = CreatePickup(2000, 2, 184.93, 35.26, -50.20, -1);//pickup exist But dont respond
pickupone = CreatePickup(2000, 2, 1000.93, 1255.26, -46.20, -1);//this pickup exist in game BUT this is the only one who respond to OnPlayerPickUpPickup !
what i'm looking for is a way to do something that will make the function respond to all the pickups !
Re: Pickups problem -
NewerthRoleplay - 23.11.2012
Well they all have the same pickupid...
Re : Pickups problem -
Amine_Mejrhirrou - 23.11.2012
that's why o thought that it should work ! but it's not
there is one alternative is to creat diferent ids for eache one but i would like to know if there is a different method like adding pickupone[100] or something
Re: Pickups problem -
NewerthRoleplay - 23.11.2012
If you are making it an array then you have to assign a value to a part of the array not the whole array.
Re: Pickups problem -
Babul - 23.11.2012
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:
Код:
//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];
lets pretend you create 3 pickups, which return the ids 41,42 and 43: (if 40 pickups were created before)
Код:
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;
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:
Код:
new PerformAction=PickupType[pickupid];
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:
Код:
switch(PerformAction)
{
case PICKUP_ACTION_MONEY:
{
GivePlayerMoney(blabla);
}
case PICKUP_ACTION_WEAPONS:
{
GivePlayerWeapon(blabla);
}
}
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:
Код:
pickupone = CreatePickup();
pickupone = CreatePickup();
pickupone = CreatePickup();
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
Re : Pickups problem -
Amine_Mejrhirrou - 23.11.2012
+REP, that's very well explained ! thnks