i have a usp gun and it has 100 ammo and when i shoot it should be reduced to 100 and it is correct, but the problem is when i put that gun down, and i pick it up again it goes back to 100 ammo, the i wish if i shot 5 bullets, it’s still 95 even though i dropped it, same as counter strike 2d.
Unfortunately you’ve made it quite difficult by using the bullet fire action to throw the uspD object. You can’t get a reference to the uspD object that’s just been fired, meaning you cannot save the ammo amount left in the uspD object.
I’d suggest that instead of firing it like a bullet, you create a new uspD object and add the ammo amount to it as an instance variable, before adding a force to it. You can keep the wait and other actions though.
Then when you pick up the uspD object, get the ammo amount from it.
Why are you using the spawn function from an extension? Just use the GDevelop create object function, Then the force will only be applied to that one object.
Also, what is Pistols? Is Pistols an object group that has uspD in it? If so, why are you deleting it when you’re dropping the weapon?
yes the pistols are group objects of usp or other pistols held by the player and i have another group made it is pistolsD that land on the ground like uspD, they are separated.
Ok, but how are you keeping this information? Using a variable, an extension, some other way?
I’m going on the assumption of the bullet extension, as you’ve used it in previous screen shots. Add the instance variable to the usp object in the scene editor:
I don’t know why it doesn’t work, did I put the variable and events upside down, or is the problem the spawn extension, but when I use create object not the expansion, it creates an object continuously and gives lag to game, btw thank you for your example to make this
In the pickup event, there’s no action to retrieve the ammo quantity from the usp and set it for the pistol.
How do you want the spawner to work? Should it create a new weapon once the currently spawned on has been collected? Because as you have it now, it looks like, over time, it it’ll spawn multiple weapons at the same spot. So when you collect one you’re actually collecting a number of them. You just can’t tell because they’re all at the same position with the same rotation
in the behavior only one spawns in the object spawner extension, that’s why I used him, not the create object which is not an extension, is that okay?