OnPlayerStateChange won't trigger.
#1

So i have this code:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
        if( newstate != PLAYER_STATE_PASSENGER && newstate != PLAYER_STATE_DRIVER )
        {
            StopAudioStreamForPlayer(playerid);
        }
        if( newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER )
        {
                        PlayAudioStreamForPlayer( playerid, "radiolink" );
    }
     return 1;
}
When i enter a vehicle (passenger or driver) the callback is called and the music starts. But when i teleport out of the vehicle the music won't stop.

I tried to check the states with
pawn Код:
if( newstate == PLAYER_STATE_ONFOOT )
{
    StopAudioStreamForPlayer(playerid);
}
if( oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER )
{
    StopAudioStreamForPlayer(playerid);
}
but still nothing. The State is changing, i verified, but the callback isn't triggering when i change from driver or passenger to onfoot.
pawn Код:
CMD:getstate(playerid, params[])
{
        new string[10];
        format(string, sizeof(string), "%d", GetPlayerState(playerid));
        SendClientMessage(playerid, COLOR_WHITE, string);
        return 1;
}
Any ideas?
Reply
#2

check this:
pawn Код:
if( oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
{
    StopAudioStreamForPlayer(playerid);
}
Reply
#3

Nope, i tried that too. Tried now again, still nothing. It just won't trigger .
Reply
#4

Bump.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
        new string[50];
        format(sting, sizeof(string), "Changed from %d to %d", oldstate, newstate);
        return 1;
}
This will tell me "Changed from 1 to 2" when i enter as a driver in a vehicle. When i exit the vehicle it won't tell me anything and when i am teleporting from one vehicle to another vehicle directly it will tell me "Changed from 2 to 1"

I mention that i am using fixes.inc by ****** but even if i am commenting the part with OnPlayerStateChange it will still won't work, just that it won't work to teleport from one vehicle to another either. I verified all my other includes and not even one(except fixes and a_samp, a_npc) contains OnPlayerStateChange.
If anyone have any idea of what could possibly prevent the CallBack from triger please post here.
Reply
#5

Is this in your gamemode or a filterscript?
Reply
#6

My gamemode.

I tried to remove some of my includes, the onunocuppiedvehicle,onplayerexit callback and all the other instructions under OnPlayerStateChange.

Still no result... Bump
Reply
#7

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_PASSENGER || oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        StopAudioStreamForPlayer(playerid);
    }
    if( newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER && oldstate== PLAYER_STATE_ONFOOT)
    {
        PlayAudioStreamForPlayer( playerid, "radiolink" );
    }
    return 1;
}
Also, make sure your Radio Volume is actually turned up In-game: Esc > Options > Audio Setup
If it's all the way down, it won't stream any audio for you.
Reply
#8

I'm so disappointed of me... I tried almost everything but i didn't even looked on what's up from the "sendclientmessage change state...".

I had:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
        new vehicleid=GetPlayerVehicleID(playerid), vehiclename[31], string[300], Float:x, Float:y, Float:z;
        format(vehiclename, 30, "%s", GetVehicleName(vehicleid));
        .
        .
        .
        return 1;
}

stock GetVehicleName(vehicleid)
{
    new String[200];
    format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return String;
}
And GetPlayerVehicleID returns 0 if the player is not in a vehicle.
And GetVehicleModel returns 0 if the vehicle doesn't exist.
And my function was doing: format(String,sizeof(String),"%s",VehicleNames[0 - 400]);
And the array index was negative.
And this was causing the callback to crash.
And this was bugging me like hell and i didn't even noticed this till' now. I'm so so so disappointed that i can't even be happy that i fixed this. Shame on me...

Edit: Sorry for bothering you all. I'll rep all who tried to help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)