17.02.2019, 14:02
Hello. I wanted to make system about shooting license. Basically it all works, except the part when I want to detect when player shoots on my object. Do you have any ideas?
Here is the code:
"Creating the targets"
"Detecting when player shots"
"Checking when player fails"
If you are interested in more of the code, just feel free to ask me.
Here is the code:
"Creating the targets"
Код:
forward CreateWeaponTargets(); public CreateWeaponTargets() { ammid[0] = CreateObject(2051, 289.64972, -130.96371, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[1] = CreateObject(2051, 287.28040, -137.44701, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[2] = CreateObject(2051, 290.74988, -135.88361, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[3] = CreateObject(2051, 279.16095, -134.54240, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[4] = CreateObject(2051, 284.53262, -131.68022, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[5] = CreateObject(2051, 291.70749, -140.59309, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[6] = CreateObject(2051, 293.50726, -138.64970, 1005.72467, 0.00000, 0.00000, 90.00000); ammid[7] = CreateObject(2051, 283.27692, -140.78691, 1005.72467, 0.00000, 0.00000, 90.00000); }
Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) { if(polazeweap[playerid]==true && weaponid == 24 && hittype == BULLET_HIT_TYPE_OBJECT) { if(hitid == ammid[0]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[0]); } else if(hitid == ammid[1]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[1]); } else if(hitid == ammid[2]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[2]); } else if(hitid == ammid[3]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[3]); } else if(hitid == ammid[4]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[4]); } else if(hitid == ammid[5]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[5]); } else if(hitid == ammid[6]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[6]); } else if(hitid == ammid[7]) { if(unistenid[playerid]>7) { SCM(playerid, COLOR_LIME, "[POLAGANJE]: Cestitamo! Dobili ste dozvolu za oruћje!"); weaponl[playerid]=true; polazeweap[playerid]=false; SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); unistenid[playerid]=0; CreateWeaponTargets(); } PlayerPlaySound(playerid,3211056,0.0,0.0,0.0); unistenid[playerid]++; DestroyObject(ammid[7]); } } return 1; }
Код:
Under OnPlayerUpdate: if(polazeweap[playerid]==true && GetPlayerInterior(playerid)==7)//variable polazeweap is just to check if player is at the shooting range { SetPlayerArmedWeapon(playerid,24); if(GetPlayerWeapon(playerid) == 0) { polazeweap[playerid]=false; SCM(playerid, COLOR_RED, "[POLAGANJE]: Naћalost nisi poloћio ispit!"); SetPlayerPos(playerid, 245.8972, 67.1190, 1004.9882); SetPlayerInterior(playerid, 6); SetPlayerVirtualWorld(playerid, 0); SetPlayerAmmo(playerid, 24, 0); CreateWeaponTargets(); } }