SA-MP Forums Archive
Little help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Little help (/showthread.php?tid=606008)



[Solved]Little help - SaiyanZ - 28.04.2016

Hello,
I was trying to make something like attaching object to only one weapon, Heres the code it attaches the object but it dosn't Destroy it if i switch weapon, Please see if anything is wrong:

PHP код:
public OnPlayerUpdate(playerid)
{
    if(
GetPlayerWeapon(playerid)== 24)
    {
    
SetPlayerAttachedObject(playerid03399);
    }
    else
    {
    
DestroyObject(playerid0);
    }
    return 
1;




Re: Little help - Sew_Sumi - 28.04.2016

You don't want to hook it into OnPlayerUpdate.

You should look at a timer, and check whether the object is needed before you keep processing the code.

Where you check for the deagle, should also check if the object is already spawned on the player. Via another variable, being ObjectSpawned[MAX_PLAYERS], and setting it when the object is spawned, and setting to 0 when the object is deleted.


Re: Little help - SaiyanZ - 28.04.2016

Can you give one example pls?


Re: Little help - Bigwebicek - 28.04.2016

You are entering wrong slot, you need to enter slot number 1 - 10, so for example:

SetPlayerAttachedObject(playerid, 5, 339, 9);

where 5 is the slot.

Then, replace DestroyObject(playerid, 0); with RemovePlayerAttachedObject(playerid, slot);, where slot is your entered number at SetPlayerAttachedObject.


Re: Little help - SaiyanZ - 28.04.2016

Quote:
Originally Posted by Bigwebicek
Посмотреть сообщение
You are entering wrong slot, you need to enter slot number 1 - 10, so for example:

SetPlayerAttachedObject(playerid, 5, 339, 9);

where 5 is the slot.

Then, replace DestroyObject(playerid, 0); with RemovePlayerAttachedObject(playerid, slot);, where slot is your entered number at SetPlayerAttachedObject.
Oh Man Thank you, It worked, Forgot the slots again ;c
I <3 you