Admob ads are not showing in Unity, C# - c#

My Admob ads are not showing in my app on Android, I tried everything, different versions of unity, types of ads, re-installation of admob plugin, different combinations of player settings for android compilation.
Log on Unity (I tested it on Android) is:
Dummy IsLoaded
Dummy ShowIntertitial
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using GoogleMobileAds.Api;
public class ControllerMain : MonoBehaviour
{
public Button LV1, LV2, LV3, LV4, LV5, LV6, LV7, LV8, LV9, LV10;
public int ReturnedVal;
private string MyIdA = "ca-app-pub-3940256099942544/1033173318";
//private InterstitialAd fullscreenad;
//private string FullScreenID = "ca-app-pub-3940256099942544/1033173651";
//private BannerView bannerView;
private InterstitialAd InterFULLSC;
void LOV1() {
SceneManager.LoadScene(1);
}
void LOV2()
{
SceneManager.LoadScene(2);
}
void LOV3()
{
SceneManager.LoadScene(3);
}
void LOV4()
{
SceneManager.LoadScene(4);
}
void LOV5()
{
SceneManager.LoadScene(5);
}
void LOV6()
{
SceneManager.LoadScene(6);
}
void LOV7()
{
SceneManager.LoadScene(7);
}
void LOV8()
{
SceneManager.LoadScene(8);
}
void LOV9()
{
SceneManager.LoadScene(9);
}
void LOV10()
{
SceneManager.LoadScene(10);
}
// Start is called before the first frame update
void Start()
{
MobileAds.Initialize(initStatus => { });
this.InterFULLSC = new InterstitialAd(MyIdA);
//LV1.GetComponent<Image>().color = Color.black;
ReturnedVal = GameMonitor.IsPassed;
if (ReturnedVal > 0)
{
AdRequest requ = new AdRequest.Builder().Build();
this.InterFULLSC.LoadAd(requ);
if (this.InterFULLSC.IsLoaded()) {
this.InterFULLSC.Show();
}
//MobileAds.Initialize(appID);
//go
//bannerView = new BannerView("ca-app-pub-3940256099942544/6300978111", AdSize.Banner, AdPosition.Bottom);
//AdRequest requ = new AdRequest.Builder().Build();
//bannerView.LoadAd(requ);
//bannerView.Show();
//end
//fullscreenad = new InterstitialAd(FullScreenID);
//AdRequest request = new AdRequest.Builder().Build();
//fullscreenad.LoadAd(request);
//if (fullscreenad.IsLoaded())
//{
// fullscreenad.Show();
//}
//else { Debug.Log("Didn't load"); }
}
Debug.Log(ReturnedVal);
LV1.GetComponent<Image>().color = Color.green;
LV2.GetComponent<Image>().color = Color.black;
LV3.GetComponent<Image>().color = Color.black;
LV4.GetComponent<Image>().color = Color.black;
LV5.GetComponent<Image>().color = Color.black;
LV6.GetComponent<Image>().color = Color.black;
LV7.GetComponent<Image>().color = Color.black;
LV8.GetComponent<Image>().color = Color.black;
LV9.GetComponent<Image>().color = Color.black;
LV10.GetComponent<Image>().color = Color.black;
LV2.interactable = false;
LV3.interactable = false;
LV4.interactable = false;
LV5.interactable = false;
LV6.interactable = false;
LV7.interactable = false;
LV8.interactable = false;
LV9.interactable = false;
LV10.interactable = false;
LV1.interactable = true;
LV1.onClick.AddListener(LOV1);
if (ReturnedVal == 2 || ReturnedVal>2) {
LV2.interactable = true;
LV2.GetComponent<Image>().color = Color.green;
LV2.onClick.AddListener(LOV2);
}
if (ReturnedVal == 3 || ReturnedVal > 3)
{
LV3.interactable = true;
LV3.GetComponent<Image>().color = Color.green;
LV3.onClick.AddListener(LOV3);
}
if (ReturnedVal == 4 || ReturnedVal > 4)
{
LV4.interactable = true;
LV4.GetComponent<Image>().color = Color.green;
LV4.onClick.AddListener(LOV4);
}
if (ReturnedVal == 5 || ReturnedVal > 5)
{
LV5.interactable = true;
LV5.GetComponent<Image>().color = Color.green;
LV5.onClick.AddListener(LOV5);
}
if (ReturnedVal == 6 || ReturnedVal > 6)
{
LV6.interactable = true;
LV6.GetComponent<Image>().color = Color.green;
LV6.onClick.AddListener(LOV6);
}
if (ReturnedVal == 7 || ReturnedVal > 7)
{
LV7.interactable = true;
LV7.GetComponent<Image>().color = Color.green;
LV7.onClick.AddListener(LOV7);
}
if (ReturnedVal == 8 || ReturnedVal > 8)
{
LV8.interactable = true;
LV8.GetComponent<Image>().color = Color.green;
LV8.onClick.AddListener(LOV8);
}
if (ReturnedVal == 9 || ReturnedVal > 9)
{
LV9.interactable = true;
LV9.GetComponent<Image>().color = Color.green;
LV9.onClick.AddListener(LOV9);
}
if (ReturnedVal == 10)
{
LV10.interactable = true;
LV10.GetComponent<Image>().color = Color.green;
LV10.onClick.AddListener(LOV10);
}
}
// Update is called once per frame
void Update()
{
}
}

Initialize the ads using the following format:
MobileAds.Initialize(appID);
Also you are trying to load and show the ad together in start function which might be one of the reason for the issue you are facing.
Load the ad in start function but show the ad on any button click by calling the below function
void ShowAd(){
if (this.InterFULLSC.IsLoaded()) {
this.InterFULLSC.Show();
}
}

Related

'Image' does not contain a definition for 'HitTest' and no accessible extension method 'HitTest'

Hello and Good Night.
I already looked for all the solutions on Google, including putting "using UnityEngine.UI;", I tried to leave only "Image" and "Texture" instead of "GUITexture or UI.Image" and this causes even more errors, I don't know what else to do. I would be grateful for the help. Thank you very much.
code:
using UnityEngine.UI;
using UnityEngine;
using System.Collections;
public class GUIItemButton : GUIItem
{
public Sprite _texNormalState;
public Sprite _texSelectedState;
public Sprite _texHoverState;
public Sprite _texDisabledState;
public bool _HighLiteOnHover = false;
bool mbButtonHover = false;
bool mbMouseClicked = false;
bool mbDisabled = false;
bool mbRespondsToInput = true;
public delegate void clickCallBack();
public clickCallBack _CallBack = null;
Vector3 mViewRectPosOffset = new Vector3(0,0,0);
Camera mCamera = null;
// Use this for initialization
void Start ()
{
//Debug.Log("Button start");
meGUIItemType = eGUI_ITEM_TYPE.Button;
if(mCamera == null)
{
mCamera = Camera.main;
mViewRectPosOffset = new Vector3(mCamera.rect.x*Screen.width,mCamera.rect.y*Screen.height,0);
}
}
public void setCamera(Camera pCam)
{
mCamera = pCam;
mViewRectPosOffset = new Vector3(mCamera.rect.x*Screen.width,mCamera.rect.y*Screen.height,0);
//Debug.Log(mViewRectPosOffset+" name: "+gameObject.name);
}
// Update is called once per frame
void Update ()
{
UpdateSizeWithViewPort();
#if UNITY_EDITOR
HandleMouseClick();
#elif UNITY_IPHONE
HandleTouch();
#else
HandleMouseClick();
#endif
}
public void setRespondToInput(bool pResponds)
{
mbRespondsToInput = pResponds;
}
//HANDLE INPUT TOUCHES
void HandleTouch()
{
if(mCamera == null || mbDisabled || !mbRespondsToInput)
return;
int touchCount = Input.touchCount;
if(touchCount > 0)
{
if(mbDisabled)
return;
Touch touch = Input.GetTouch(touchCount-1);
//IF THE BUTTON IS NOT YET CLICKED
if (touch.phase == TouchPhase.Began && mbMouseClicked == false)
{
if (GetComponent<Image>().HitTest(touch.position-(Vector2)mViewRectPosOffset, mCamera))
{
//SET TO SELECTED TEXTURE
mbMouseClicked = true;
GetComponent<Image>().sprite = _texSelectedState;
}
}
//IF THE BUTTON IS ALREADY CLICKED
if (touch.phase == TouchPhase.Ended && mbMouseClicked == true)
{
mbMouseClicked = false;
if (GetComponent<Image>().HitTest(touch.position-(Vector2)mViewRectPosOffset, mCamera))
{
//PERFORM ACTION
GetComponent<Image>().sprite = _texNormalState;
if(_guiItemsManager !=null)
_guiItemsManager.OnSelectedEvent(this);
else if(_CallBack != null)
_CallBack();
}
}
//HIGHLITE ON HOVER
if (!mbButtonHover)
{
//CHECK IF MOUSE IS HOVERING ON BUTTON
if (GetComponent<Image>().HitTest(touch.position-(Vector2)mViewRectPosOffset, mCamera))
mbButtonHover = true;
if(mbButtonHover)
{
//HIGHLITE BUTTON (SELECTED OR HOVER MODE)
if(mbMouseClicked)
GetComponent<Image>().sprite = _texSelectedState;
}
}
//IF MOUSE IS ALREADY HOVERING ON BUTTON
else if (mbButtonHover)
{
if (!GetComponent<Image>().HitTest(touch.position-(Vector2)mViewRectPosOffset, mCamera))
{
//HAPPENS ONLY IF MOUSE MOVES AWAY FROM BUTTON
GetComponent<Image>().sprite = _texNormalState;
mbButtonHover = false;
}
}
}
else
{
mbMouseClicked = false;
GetComponent<Image>().sprite = _texNormalState;
}
}
void HandleMouseClick()
{
if(mCamera == null || mbDisabled || !mbRespondsToInput)
return;
//IF THE BUTTON IS NOT YET CLICKED
if (Input.GetMouseButtonDown(0) && mbMouseClicked == false)
{
if (GetComponent<Image>().HitTest((Input.mousePosition-mViewRectPosOffset), mCamera))
{
//SET TO SELECTED TEXTURE
//Debug.Log("Hit offset "+ (Input.mousePosition-mViewRectPosOffset));
mbMouseClicked = true;
GetComponent<Image>().sprite = _texSelectedState;
}
}
//IF THE BUTTON IS ALREADY CLICKED
if (Input.GetMouseButtonUp(0) && mbMouseClicked == true)
{
mbMouseClicked = false;
if (GetComponent<Image>().HitTest((Input.mousePosition-mViewRectPosOffset), mCamera))
{
//PERFORM ACTION
GetComponent<Image>().sprite = _texNormalState;
if(_guiItemsManager !=null)
_guiItemsManager.OnSelectedEvent(this);
else if(_CallBack != null)
_CallBack();
}
}
//HIGHLITE ON HOVER
if (!mbButtonHover)
{
//CHECK IF MOUSE IS HOVERING ON BUTTON
if (GetComponent<Image>().HitTest((Input.mousePosition-mViewRectPosOffset), mCamera))
mbButtonHover = true;
if(mbButtonHover)
{
//HIGHLITE BUTTON (SELECTED OR HOVER MODE)
if(mbMouseClicked)
GetComponent<Image>().sprite = _texSelectedState;
else if(_HighLiteOnHover)
GetComponent<Image>().sprite = _texHoverState;
}
}
//IF MOUSE IS ALREADY HOVERING ON BUTTON
else if (mbButtonHover)
{
if (!GetComponent<Image>().HitTest((Input.mousePosition-mViewRectPosOffset), mCamera))
{
//HAPPENS ONLY IF MOUSE MOVES AWAY FROM BUTTON
GetComponent<Image>().sprite = _texNormalState;
mbButtonHover = false;
}
}
}
public void setDisabled(bool pState)
{
mbDisabled = pState;
if(mbDisabled == true)
GetComponent<Image>().sprite = _texDisabledState;
else
GetComponent<Image>().sprite = _texNormalState;
}
public bool getDisabled()
{
return mbDisabled;
}
}
Is there a problem?

Error with animation component in Unity3D when adding a programming script to it to Select windows from my panels in an AR app for android

Hello I am developing an augmented reality app for android. I made animations with the Animation component of the Anchored Position type for Anchored position of my windows that are contained in different panels.When adding a script to the unity Animation component to Select a window depending on whether I'm clicking it or not; I throw the following mistakes:
This is the script that I use for programming (note that it is from the Animation component). I'm not sure if I need to import some libraries, or what's wrong with my code, why doesn't it compile? Understanding that this code is a bit old; from 2019.
This is the code and I'm relying on this youtube video: https://www.youtube.com/watch?v=WBGY5TxmjrA at minute 29.
``
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class SelecionarVentana : MonoBehaviour
{
public GameObject VentanaGuerrero;
public GameObject VentanaGuitarra;
public GameObject VentanaPiano;
public GameObject VentanaTigre;
Animation AVentanaGuerrero;
Animation AVentanaGuitarra;
Animation AVentanaPiano;
Animation AVentanaTigre;
bool VisibleVGuerrero = false;
bool VisibleVGuitarra = false;
bool VisibleVPiano = false;
bool VisibleVTigre = false;
void Start()
{
AVentanaGuerrero = VentanaGuerrero.GetComponent<Animation>();
AVentanaGuitarra = VentanaGuitarra.GetComponent<Animation>();
AVentanaPiano = VentanaPiano.GetComponent<Animation>();
AVentanaTigre = VentanaTigre.GetComponent<Animation>();
}
public void VentanaGuePulsada()
{
if (VisibleVGuerrero == false)
{
AVentanaGuerrero["Guerrero"].speed = 1;
AVentanaGuerrero.Play();
VisibleVGuerrero = true;
}
}
public void VentanaGuiPulsada()
{
if (VisibleVGuitarra == false)
{
AVentanaGuitarra["Guitarra"].speed = 1;
AVentanaGuitarra.Play();
VisibleVGuitarra = true;
}
}
public void VentanaPiaPulsada()
{
if (VisibleVPiano == false)
{
AVentanaPiano["Piano"].speed = 1;
AVentanaPiano.Play();
VisibleVPiano = true;
}
}
public void VentanaTigPulsada()
{
if (VisibleVTigre == false)
{
AVentanaTigre["Tigre"].speed = 1;
AVentanaTigre.Play();
VisibleVTigre = true;
}
}
public void VentanaNoPulsada()
{
string NombreBoton = EventSystem.current.currentSelectedGameObject.name;
if (NombreBoton != "Guerrero" & VisibleVGuerrero == true)
{
AVentanaGuerrero["Guerrero"].speed = -1;
AVentanaGuerrero["Guerrero"].time = AVentanaGuerrero["Guerrero"].length;
AVentanaGuerrero.Play();
VisibleVGuerrero = false;
}
if (NombreBoton != "Guitarra" & VisibleVGuitarra == true)
{
AVentanaGuitarra["Guitarra"].speed = -1;
AVentanaGuitarra["Guitarra"].time = AVentanaGuitarra["Guitarra"].length;
AVentanaGuitarra.Play();
VisibleVGuitarra = false;
}
if (NombreBoton != "Piano" & VisibleVPiano == true)
{
AVentanaPiano["Piano"].speed = -1;
AVentanaPiano["Piano"].time = AVentanaPiano["Piano"].length;
AVentanaPiano.Play();
VisibleVPiano = false;
}
if (NombreBoton != "Tigre" & VisibleVTigre == true)
{
AVentanaTigre["Tigre"].speed = -1;
AVentanaTigre["Tigre"].time = AVentanaTigre["Tigre"].length;
AVentanaTigre.Play();
VisibleVTigre = false;
}
}
}
``
What's wrong with this old code I try to compile it into unity. I'm on unity version 2021.3.10f1.

C# - Visual Studio and Rage

Hello I'm having some problems with a callout making I don't know if anyone here can help me but I'll try asking anyway.
Information
I'm making a CalloutPack for a game called Grand Theft Auto 5 while using RagePluginHook an add-on needed for that to make it work.
Basically, It works like this Main.cs go trough -> Handler.cs that register all the callouts (source code for main and handler down below). It uses LSPDFR.API.MOD and Rage, now i seem to get an Rage.ISpatial is invalid. at Rage.Entity.DistanceTo(ISpatial spatialObject) and I don't really know where in my code I have f up.
I'm getting a Take over Radio Tower Los Santos: Operation is not valid because the specified Rage.ISpatial is invalid. at Rage.Entity.DistanceTo(ISpatial spatialObject)
do anyone know what I did wrong?
Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rage;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using System.Drawing;
using Rage.Native;
namespace SpeedyPursuit.Callouts
{
[CalloutInfo("Take over Raido Tower Los Santos", CalloutProbability.Medium)]
public class TakeOverLS : Callout
{
private Ped Suspect;
private Ped Suspect2;
private Ped Suspect3;
private Ped Suspect4;
private Ped Suspect5;
//cops Ped
private Ped Fbisupervisor;
private Ped FbiTeamMember1;
private Ped FbiTeamMember2;
private Ped FbiTeamMember3;
private Ped FbiTeamMember4;
private LHandle Pursuit;
private bool PursuitCreated;
private Vehicle vehicle1;
private Vehicle vehicle2;
private Vehicle vehicle1p;
private Vehicle vehicle2p;
private Vehicle vehicle3p;
private Vehicle vehicle4p;
private Vector3 spawnpV1;
private Vector3 spawnpV2;
private Vector3 spawnV1;
private Vector3 spawnV2;
private Vector3 spawnV1p;
private Vector3 spawnV2p;
private Vector3 spawnV3p;
private Vector3 spawnV4p;
//Cops Spawn
private Vector3 FbisupervisorSpawn;
private Vector3 FbiTeamMember1s;
private Vector3 FbiTeamMember2s;
private Vector3 FbiTeamMember3s;
private Vector3 FbiTeamMember4s;
//locationfollow
private Vector3 followlocation;
private float followheading;
//Cops Blip
private Blip FbisupervisorBlip;
private Blip FbiTeamMember1Blip;
private Blip SuspectBlip;
private Blip SuspectBlip2;
private Blip SuspectBlip3;
private Blip SuspectBlip4;
private Blip SuspectBlip5;
private float heading;
private float headingv1;
private float headingv2;
private float headingv1p;
private float headingv2p;
private float headingv3p;
private float headingv4p;
//cops heading
private float headingfbisup;
private float FbiTeamMember1heading;
private float FbiTeamMember2heading;
private float FbiTeamMember3heading;
private float FbiTeamMember4heading;
private Vector3 Spawnpoint;
private Vector3 Spawnpoint2;
private Vector3 Spawnpoint3;
private Vector3 Spawnpoint4;
private Vector3 Spawnpoint5;
private int counter;
private int counter2;
public override bool OnBeforeCalloutDisplayed()
{
//cops spawn
FbiTeamMember1s = new Vector3(845f, 1285f, 360f);
FbiTeamMember2s = new Vector3(845f, 1283f, 360f);
FbiTeamMember3s = new Vector3(847f, 1284f, 360f);
FbiTeamMember4s = new Vector3(847f, 1286f, 360f);
followlocation = new Vector3(801f, 1276f, 360);
followheading = 86.647f;
Spawnpoint = new Vector3(778f, 1287, 360f);
Spawnpoint2 = new Vector3(779f, 1289, 360f);
Spawnpoint3 = new Vector3(778f, 1270f, 360f);
Spawnpoint4 = new Vector3(787f, 1266f, 360f);
Spawnpoint5 = new Vector3(782f, 1297f, 361f);
FbisupervisorSpawn = new Vector3(855f, 1281f, 359f);
headingv1 = 357.922f;
headingv2 = 51.345f;
// cops heading
headingfbisup = 23.187f;
FbiTeamMember1heading = 174.126f;
FbiTeamMember2heading = 354.127f;
FbiTeamMember3heading = 93.946f;
FbiTeamMember4heading = 255.905f;
headingv1p = 119.149f;
headingv2p = 66.722f;
headingv3p = 320.630f;
headingv4p = 358.971f;
spawnV1 = new Vector3(808f, 1279f, 360f);
spawnV2 = new Vector3(807f, 1272f, 360f);
spawnV1p = new Vector3(855f, 1278f, 359f);
spawnV2p = new Vector3(847f, 1276f, 359f);
spawnV3p = new Vector3(848f, 1290f, 359f);
spawnV4p = new Vector3(843f, 1283f, 359f);
ShowCalloutAreaBlipBeforeAccepting(Spawnpoint, 30f);
AddMinimumDistanceCheck(240f, Spawnpoint);
AddMaximumDistanceCheck(4000f, Spawnpoint);
CalloutMessage = "~r~Multiple suspects~w~ have taken over the Los Santos Radio Tower";
CalloutPosition = Spawnpoint;
Functions.PlayScannerAudioUsingPosition("CRIME_ASSAULT_WITH_A_DEADLY_WEAPON_01 IN_OR_AT", Spawnpoint);
PursuitCreated = false;
return base.OnBeforeCalloutDisplayed();
}
public override bool OnCalloutAccepted()
{
try
{
Game.DisplayNotification("char_call911", "char_call911", "~b~SpeedyPursuit~b~", "~r~TO ALL UNITS~w~", "~r~Dispacth:~w~ All Units responde immediately, Multiple armed suspect have forcefully taken over the radio tower in Los Santos");
Game.DisplayNotification("~r~CODE:~w~ ~Y~3 Response~w~");
Functions.PlayScannerAudio("UNITS_RESPOND_CODE_03_01");
Suspect = new Ped("MP_M_BOGDANGOON", Spawnpoint, heading);
Suspect.IsPersistent = true;
Suspect.BlockPermanentEvents = true;
Suspect2 = new Ped("MP_M_BOGDANGOON", Spawnpoint2, heading);
Suspect2.IsPersistent = true;
Suspect2.BlockPermanentEvents = true;
Suspect3 = new Ped("MP_M_BOGDANGOON", Spawnpoint3, heading);
Suspect3.IsPersistent = true;
Suspect3.BlockPermanentEvents = true;
Suspect4 = new Ped("MP_M_BOGDANGOON", Spawnpoint4, heading);
Suspect4.IsPersistent = true;
Suspect4.BlockPermanentEvents = true;
Suspect5 = new Ped("MP_M_BOGDANGOON", Spawnpoint5, heading);
Suspect5.IsPersistent = true;
Suspect5.BlockPermanentEvents = true;
//Cops ped identifer
Fbisupervisor = new Ped("S_M_Y_SWAT_01", FbisupervisorSpawn, headingfbisup);
Fbisupervisor.IsPersistent = true;
Fbisupervisor.BlockPermanentEvents = true;
FbiTeamMember1 = new Ped("S_M_Y_SWAT_01", FbiTeamMember1s, FbiTeamMember1heading);
FbiTeamMember1.IsPersistent = true;
FbiTeamMember1.BlockPermanentEvents = true;
FbiTeamMember2 = new Ped("S_M_Y_SWAT_01", FbiTeamMember2s, FbiTeamMember2heading);
FbiTeamMember2.IsPersistent = true;
FbiTeamMember2.BlockPermanentEvents = true;
FbiTeamMember3 = new Ped("S_M_Y_SWAT_01", FbiTeamMember3s, FbiTeamMember3heading);
FbiTeamMember3.IsPersistent = true;
FbiTeamMember3.BlockPermanentEvents = true;
FbiTeamMember4 = new Ped("S_M_Y_SWAT_01", FbiTeamMember4s, FbiTeamMember4heading);
FbiTeamMember4.IsPersistent = true;
FbiTeamMember4.BlockPermanentEvents = true;
//swat blip
FbiTeamMember1Blip = FbiTeamMember1.AttachBlip();
FbiTeamMember1Blip.Color = System.Drawing.Color.Green;
FbiTeamMember1Blip.IsRouteEnabled = false;
FbisupervisorBlip = Fbisupervisor.AttachBlip();
FbisupervisorBlip.Color = System.Drawing.Color.Yellow;
FbisupervisorBlip.IsRouteEnabled = true;
SuspectBlip = Suspect.AttachBlip();
SuspectBlip.Color = System.Drawing.Color.Red;
SuspectBlip.IsRouteEnabled = false;
SuspectBlip2 = Suspect.AttachBlip();
SuspectBlip2.Color = System.Drawing.Color.Red;
SuspectBlip2.IsRouteEnabled = false;
SuspectBlip3 = Suspect.AttachBlip();
SuspectBlip3.Color = System.Drawing.Color.Red;
SuspectBlip3.IsRouteEnabled = false;
SuspectBlip4 = Suspect.AttachBlip();
SuspectBlip4.Color = System.Drawing.Color.Red;
SuspectBlip4.IsRouteEnabled = false;
SuspectBlip5 = Suspect.AttachBlip();
SuspectBlip5.Color = System.Drawing.Color.Red;
SuspectBlip5.IsRouteEnabled = false;
Suspect.CanAttackFriendlies = false;
Suspect2.CanAttackFriendlies = false;
Suspect3.CanAttackFriendlies = false;
Suspect4.CanAttackFriendlies = false;
Suspect5.CanAttackFriendlies = false;
vehicle1 = new Vehicle("BURRITO", spawnV1, headingv1);
vehicle2 = new Vehicle("BURRITO", spawnV2, headingv2);
vehicle1p = new Vehicle("RIOT", spawnV1p, headingv1p);
vehicle2p = new Vehicle("RIOT", spawnV2p, headingv2p);
vehicle3p = new Vehicle("POLICE", spawnV3p, headingv3p);
vehicle4p = new Vehicle("RIOT", spawnV4p, headingv4p);
vehicle1p.IsSirenOn = true;
vehicle1p.IsSirenSilent = true;
vehicle2p.IsSirenOn = true;
vehicle2p.IsSirenSilent = true;
vehicle3p.IsSirenOn = true;
vehicle3p.IsSirenSilent = true;
vehicle4p.IsSirenOn = true;
vehicle4p.IsSirenSilent = true;
Suspect.RelationshipGroup = "ATTACKER";
Suspect2.RelationshipGroup = "ATTACKER";
Suspect3.RelationshipGroup = "ATTACKER";
Suspect4.RelationshipGroup = "ATTACKER";
Suspect5.RelationshipGroup = "ATTACKER";
FbiTeamMember1.RelationshipGroup = "COP";
FbiTeamMember2.RelationshipGroup = "COP";
FbiTeamMember3.RelationshipGroup = "COP";
FbiTeamMember4.RelationshipGroup = "COP";
Game.LocalPlayer.Character.RelationshipGroup = "COP";
Game.SetRelationshipBetweenRelationshipGroups("ATTACKER", "COP", Relationship.Hate);
Game.SetRelationshipBetweenRelationshipGroups("COP", "ATTACKER", Relationship.Hate);
Suspect.StaysInGroups = true;
Suspect2.StaysInGroups = true;
Suspect3.StaysInGroups = true;
Suspect4.StaysInGroups = true;
Suspect5.StaysInGroups = true;
FbiTeamMember1.StaysInGroups = true;
FbiTeamMember2.StaysInGroups = true;
FbiTeamMember3.StaysInGroups = true;
FbiTeamMember4.StaysInGroups = true;
FbiTeamMember1.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 400, true);
NativeFunction.Natives.SetPedCombatAttributes(FbiTeamMember1, 1, true);
FbiTeamMember2.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 400, true);
NativeFunction.Natives.SetPedCombatAttributes(FbiTeamMember2, 1, true);
FbiTeamMember3.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 400, true);
NativeFunction.Natives.SetPedCombatAttributes(FbiTeamMember3, 1, true);
FbiTeamMember4.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 400, true);
NativeFunction.Natives.SetPedCombatAttributes(FbiTeamMember4, 1, true);
Suspect.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 400, true);
NativeFunction.Natives.SetPedCombatAttributes(Suspect, 1, true);
Suspect2.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 310, true);
NativeFunction.Natives.SetPedCombatAttributes(Suspect2, 1, true);
Suspect3.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 200, true);
NativeFunction.Natives.SetPedCombatAttributes(Suspect3, 1, true);
Suspect4.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 170, true);
NativeFunction.Natives.SetPedCombatAttributes(Suspect4, 1, true);
Suspect5.Inventory.GiveNewWeapon("WEAPON_CARBINERIFLE", 130, true);
NativeFunction.Natives.SetPedCombatAttributes(Suspect5, 1, true);
}
catch
{
Game.LogTrivial("SpeedyPursuit - Something went wrong during loading section");
End();
}
return base.OnCalloutAccepted();
}
public override void Process()
{
base.Process();
if (Game.LocalPlayer.Character.DistanceTo(Fbisupervisor) <= 5f)
{
Game.DisplayHelp("Speak with the SWAT Operatin Lader, To do so press ~y~Y~w~", false);
if (Game.IsKeyDown(Handler.TalkKey))
{
counter++;
if (counter == 1)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ Alright listen closely I will only say this once");
}
if (counter == 2)
{
Game.DisplaySubtitle("~b~Offier:~w~ Yes sir");
}
if (counter == 3)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ Multiple suspects have forcefully taken over the Radio Station");
}
if (counter == 4)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ They are armed to the teeth with rifles and ammo that can last for days");
}
if (counter == 5)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ Negotiations have ended terriblely and our only last option is to lunch ~o~operation payback~w~");
}
if (counter == 6)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ We will force entry through the front gates with swat team ~o~BRAVO~w~");
}
if (counter == 7)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ Our priority is to either eliminate the targets or force them to surrender, Secondly find any hostages and free them");
}
if (counter == 8)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ You will lead team ~o~BRAVO~w~, when ready talk to your team and start the operation!");
FbiTeamMember1Blip.Flash(counter, 1);
}
if (counter == 9)
{
Game.DisplaySubtitle("~y~SWAT Opeator:~w~ Do you understand my commands!");
}
if (counter == 10)
{
Game.DisplaySubtitle("~b~Offier:~w~ Yes sir!");
}
if (counter == 11)
{
Game.DisplaySubtitle("~b~No further speech here, when ready for breach talk to your team.~w~");
Game.DisplayHelp("Speak with your ~o~swat team~w~", false);
}
}
}
if (Game.LocalPlayer.Character.DistanceTo(FbiTeamMember1) <= 5f)
{
Game.DisplayHelp("Speak with your SWAT Team, To do so press ~y~Y~w~", false);
if (Game.IsKeyDown(Handler.TalkKey))
{
counter2++;
if (counter2 == 1)
{
Game.DisplaySubtitle("~y~SWAT Member:~w~ We are ready to force entry when you are, sir!");
}
if (counter2 == 2)
{
Game.DisplaySubtitle("~b~Offier:~w~ Great, now let's do this");
}
if (counter2 == 3)
{
Game.DisplaySubtitle("~b~Offier:~w~ The gun men are armed and they won't be happy with our entrance");
}
if (counter2 == 4)
{
Game.DisplaySubtitle("~y~SWAT Member:~w~ Understood sir");
FbiTeamMember1.BlockPermanentEvents = false;
FbiTeamMember2.BlockPermanentEvents = false;
FbiTeamMember3.BlockPermanentEvents = false;
FbiTeamMember4.BlockPermanentEvents = false;
}
}
}
if (!PursuitCreated && Game.LocalPlayer.Character.DistanceTo(Suspect) <= 55f)
{
Pursuit = Functions.CreatePursuit();
Functions.AddPedToPursuit(Pursuit, Suspect);
Functions.AddPedToPursuit(Pursuit, Suspect2);
Functions.AddPedToPursuit(Pursuit, Suspect3);
Functions.AddPedToPursuit(Pursuit, Suspect4);
Functions.AddPedToPursuit(Pursuit, Suspect5);
Functions.SetPursuitIsActiveForPlayer(Pursuit, true);
Suspect.Tasks.FightAgainstClosestHatedTarget(200);
Suspect2.Tasks.FightAgainstClosestHatedTarget(200);
Suspect3.Tasks.FightAgainstClosestHatedTarget(200);
Suspect4.Tasks.FightAgainstClosestHatedTarget(200);
Suspect5.Tasks.FightAgainstClosestHatedTarget(200);
PursuitCreated = true;
}
if (PursuitCreated && !Functions.IsPursuitStillRunning(Pursuit))
{
End();
}
if (Game.LocalPlayer.Character.DistanceTo(Suspect) <= 60f)
{
Suspect.BlockPermanentEvents = false;
Suspect2.BlockPermanentEvents = false;
Suspect3.BlockPermanentEvents = false;
Suspect4.BlockPermanentEvents = false;
Suspect5.BlockPermanentEvents = false;
}
if (Game.LocalPlayer.Character.DistanceTo(vehicle1p) > 310f)
{
vehicle1p.Delete();
}
if (Game.LocalPlayer.Character.DistanceTo(vehicle2p) > 310f)
{
vehicle2p.Delete();
}
if (Game.LocalPlayer.Character.DistanceTo(vehicle3p) > 310f)
{
vehicle3p.Delete();
}
if (Game.LocalPlayer.Character.DistanceTo(vehicle4p) > 310f)
{
vehicle4p.Delete();
}
if (Rage.Game.IsKeyDown(Handler.EndCallout))
{
End();
vehicle1.Delete();
vehicle2.Delete();
Suspect.Delete();
Suspect2.Delete();
Suspect3.Delete();
Suspect4.Delete();
Suspect5.Delete();
SuspectBlip.Delete();
SuspectBlip2.Delete();
SuspectBlip3.Delete();
SuspectBlip4.Delete();
SuspectBlip5.Delete();
vehicle1p.Delete();
vehicle2p.Delete();
vehicle3p.Delete();
vehicle4p.Delete();
}
if (!Suspect.Exists() || Game.LocalPlayer.Character.IsDead || !Suspect2.Exists() || !Suspect3.Exists() || !Suspect4.Exists() || !Suspect5.Exists())
{
End();
}
}
public override void End()
{
base.End();
if (SuspectBlip.Exists())
{
SuspectBlip.Delete();
}
if (SuspectBlip2.Exists())
{
SuspectBlip2.Delete();
}
if (SuspectBlip3.Exists())
{
SuspectBlip3.Delete();
}
if (SuspectBlip4.Exists())
{
SuspectBlip4.Delete();
}
if (SuspectBlip5.Exists())
{
SuspectBlip5.Delete();
}
if (FbiTeamMember1Blip.Exists())
{
FbiTeamMember1Blip.Delete();
}
if (FbiTeamMember1Blip.Exists())
{
FbiTeamMember1Blip.Delete();
}
if (FbisupervisorBlip.Exists())
{
FbisupervisorBlip.Delete();
}
if (FbiTeamMember1.Exists())
{
FbiTeamMember1.Dismiss();
}
if (FbiTeamMember2.Exists())
{
FbiTeamMember2.Dismiss();
}
if (FbiTeamMember3.Exists())
{
FbiTeamMember3.Dismiss();
}
if (FbiTeamMember4.Exists())
{
FbiTeamMember4.Dismiss();
}
Game.LogTrivial("SpeedyPursuit - TakeOverLS cleaned up!");
Game.DisplayNotification("~b~SpeedyPursuit~w~ - ~g~Code 4~w~");
Functions.PlayScannerAudio("ATTENTION_ALL_UNITS WE_ARE_CODE 4");
}
}
}
Main.cs
using LSPD_First_Response;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rage;
using Rage.Native;
using LSPD_First_Response.Mod.API;
using LSPD_First_Response.Mod.Callouts;
using LSPD_First_Response.Engine.Scripting.Entities;
using SpeedyPursuit;
using SpeedyPursuit.Callouts;
using System.Reflection;
namespace SpeedyPursuit
{
public class Main : Plugin
{
public override void Initialize()
{
Functions.OnOnDutyStateChanged += OnOnDutyStateChangedHandler;
Game.LogTrivial("SpeedyPursuit" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " has been initialised.");
Game.LogTrivial("Go on duty to fully load SpeedyPursuit.");
}
public override void Finally()
{
Game.LogTrivial("SpeedyPursuit has been cleaned up.");
}
private static void OnOnDutyStateChangedHandler(bool OnDuty)
{
if (OnDuty)
{
Handler.Initialize();
Game.DisplayNotification("web_lossantospolicedept", "web_lossantospolicedept", "~b~SpeedyPursuit~b~", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " has loaded ~g~successfully~w~", "~o~SpeedyPursuit~w~ Is now running Update name: ~o~Proud-unit~w~");
}
}
}
}

How to make the answer appear automatically?

I made a master mind game and im stuck with the last part of it. The Question is.. How can i make the 4 small buttons on the right side to Show the answer automatically after pressing on "2nd row button" (btnRow2)? Right now, my code is working perfectly except the fact that i have to press on the answer Buttons in order to check if the Colors choosen by me are correct or not, i want them to appear automatically without pressing on the buttons.
My 2nd Row Button code
}
private void btnRow2_Click(object sender, EventArgs e)
{
btnChange1_1.Enabled = false;
btnChange1_2.Enabled = false;
btnChange1_3.Enabled = false;
btnChange1_4.Enabled = false;
btnChange2_1.Enabled = true;
btnChange2_2.Enabled = true;
btnChange2_3.Enabled = true;
btnChange2_4.Enabled = true;
btnRow2.Visible = false;
pictureBox2.Visible = true;
pictureBox1.Visible = false;
btnAnswer1_1.Visible = true;
btnAnswer1_2.Visible = true;
btnAnswer1_3.Visible = true;
btnAnswer1_4.Visible = true;
}
All small Answer boxes:
}
private void btnAnswer1_1_Click(object sender, EventArgs e)
{
if (btnChange1_1.BackColor == button1.BackColor)
{
btnAnswer1_1.BackColor = Color.Black;
}
if (btnChange1_1.BackColor == button2.BackColor)
{
btnAnswer1_1.BackColor = Color.Red;
}
if (btnChange1_1.BackColor == button3.BackColor)
{
btnAnswer1_1.BackColor = Color.Red;
}
if (btnChange1_1.BackColor == button4.BackColor)
{
}
{
btnChange1_4.Enabled = false;
btnChange1_3.Enabled = false;
btnChange1_2.Enabled = false;
btnChange1_1.Enabled = false;
}
}
private void btnAnswer1_2_Click(object sender, EventArgs e)
{
if (btnChange1_2.BackColor == button1.BackColor)
{
btnAnswer1_2.BackColor = Color.Red;
}
if (btnChange1_2.BackColor == button2.BackColor)
{
btnAnswer1_2.BackColor = Color.Black;
}
if (btnChange1_2.BackColor == button3.BackColor)
{
btnAnswer1_2.BackColor = Color.Red;
}
if (btnChange1_2.BackColor == button4.BackColor)
{
btnAnswer1_2.BackColor = Color.Red;
{
btnChange1_4.Enabled = false;
btnChange1_3.Enabled = false;
btnChange1_2.Enabled = false;
btnChange1_1.Enabled = false;
}
}
}
private void btnAnswer1_3_Click(object sender, EventArgs e)
{
if (btnChange1_3.BackColor == button1.BackColor)
{
btnAnswer1_3.BackColor = Color.Red;
}
if (btnChange1_3.BackColor == button2.BackColor)
{
btnAnswer1_3.BackColor = Color.Red;
}
if (btnChange1_3.BackColor == button3.BackColor)
{
btnAnswer1_3.BackColor = Color.Black;
}
if (btnChange1_3.BackColor == button4.BackColor)
{
btnAnswer1_3.BackColor = Color.Red;
}
{
btnChange1_4.Enabled = false;
btnChange1_3.Enabled = false;
btnChange1_2.Enabled = false;
btnChange1_1.Enabled = false;
}
}
private void btnAnswer1_4_Click(object sender, EventArgs e)
{
if (btnChange1_4.BackColor == button1.BackColor)
{
btnAnswer1_4.BackColor = Color.Red;
}
if (btnChange1_4.BackColor == button2.BackColor)
{
btnAnswer1_4.BackColor = Color.Red;
}
if (btnChange1_4.BackColor == button3.BackColor)
{
btnAnswer1_4.BackColor = Color.Red;
}
if (btnChange1_4.BackColor == button4.BackColor)
{
btnAnswer1_4.BackColor = Color.Black;
}
{
btnChange1_4.Enabled = false;
btnChange1_3.Enabled = false;
btnChange1_2.Enabled = false;
btnChange1_1.Enabled = false;
Create a method that does what your answer buttons do, and call that method when you press row 2.
That is my suggestions anyway, but I am a bit confused to what you actually want :) GL

Play three sounds simultaneously c#

I want to play three sounds simultaneously, but second sound must play after one seconds, third sound after two seconds. I have this code:
private void Play()
{
AxWindowsMediaPlayer player1 = new AxWindowsMediaPlayer();
player1.CreateControl();
AxWindowsMediaPlayer player2 = new AxWindowsMediaPlayer();
player2.CreateControl();
AxWindowsMediaPlayer player3 = new AxWindowsMediaPlayer();
player3.CreateControl();
player1.URL = "sounds\\1.wav";
player1.Ctlcontrols.play();
System.Threading.Thread.Sleep(1000);
player2.URL = "sounds\\2.wav";
player2.Ctlcontrols.play();
System.Threading.Thread.Sleep(1000);
player3.URL = "sounds\\3.wav";
player3.Ctlcontrols.play();
Why all this sounds are playing in one time after two seconds?
I ended up using SharpDX (available via NuGet packages SharpDX
and SharpDX.XAudio2.
An example of its usage can be found in one of my GitHub projects: 2DAI
You can hear the various sounds overlapping in this screen recording as well.
Playing a sound:
var backgroundMusicSound = new AudioClip(#".\Assets\Sounds\Music\Background.wav" /*Sound path*/, 1.0 /* Volumne*/, true /*Loop Forever?*/)
backgroundMusicSound.Play();
The class that I pieced together:
public class AudioClip
{
private XAudio2 _xaudio = new XAudio2();
private WaveFormat _waveFormat;
private AudioBuffer _buffer;
private SoundStream _soundstream;
private SourceVoice _singleSourceVoice;
private bool _loopForever;
private bool _isPlaying = false; //Only applicable when _loopForever == false;
private bool _isFading;
private string _wavFilePath; //For debugging.
private float _initialVolumne;
public AudioClip(string wavFilePath, float initialVolumne = 1, bool loopForever = false)
{
_loopForever = loopForever;
_wavFilePath = wavFilePath;
_initialVolumne = initialVolumne;
var masteringsound = new MasteringVoice(_xaudio); //Yes, this is required.
var nativefilestream = new NativeFileStream(wavFilePath,
NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);
_soundstream = new SoundStream(nativefilestream);
_waveFormat = _soundstream.Format;
_buffer = new AudioBuffer
{
Stream = _soundstream.ToDataStream(),
AudioBytes = (int)_soundstream.Length,
Flags = BufferFlags.EndOfStream
};
if (loopForever)
{
_buffer.LoopCount = 100;
}
}
public void Play()
{
lock (this)
{
if (_loopForever == true)
{
if (_isPlaying)
{
if (_isFading)
{
_isFading = false;
_singleSourceVoice.SetVolume(_initialVolumne);
}
return;
}
_singleSourceVoice = new SourceVoice(_xaudio, _waveFormat, true);
_singleSourceVoice.SubmitSourceBuffer(_buffer, _soundstream.DecodedPacketsInfo);
_singleSourceVoice.SetVolume(_initialVolumne);
_singleSourceVoice.Start();
_isPlaying = true;
return;
}
}
var sourceVoice = new SourceVoice(_xaudio, _waveFormat, true);
sourceVoice.SubmitSourceBuffer(_buffer, _soundstream.DecodedPacketsInfo);
sourceVoice.SetVolume(_initialVolumne);
sourceVoice.Start();
}
public void Fade()
{
if (_isPlaying && _isFading == false)
{
_isFading = true;
(new Thread(FadeThread)).Start();
}
}
private void FadeThread()
{
float volumne;
_singleSourceVoice.GetVolume(out volumne);
while (_isFading && volumne > 0)
{
volumne -= 0.25f;
volumne = volumne < 0 ? 0 : volumne;
_singleSourceVoice.SetVolume(volumne);
Thread.Sleep(100);
}
Stop();
}
public void Stop()
{
if (_loopForever == true)
{
if (_singleSourceVoice != null && _isPlaying)
{
_singleSourceVoice.Stop();
}
_isPlaying = false;
_isFading = false;
}
else
{
throw new Exception("Cannot stop overlapped audio.");
}
}
}
It should also be notes that loading the sounds can be a heavy process, so if you are doing it a lot then you might want to cache them as I did:
private Dictionary<string, AudioClip> _audioClips { get; set; } = new Dictionary<string, AudioClip>();
public AudioClip GetSoundCached(string wavFilePath, float initialVolumne, bool loopForever = false)
{
lock (_audioClips)
{
AudioClip result = null;
wavFilePath = wavFilePath.ToLower();
if (_audioClips.ContainsKey(wavFilePath))
{
result = _audioClips[wavFilePath];
}
else
{
result = new AudioClip(wavFilePath, initialVolumne, loopForever);
_audioClips.Add(wavFilePath, result);
}
return result;
}
}

Categories

Resources