SA-MP Forums Archive
OnPlayerStateChange - A code screws it up ? - 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: OnPlayerStateChange - A code screws it up ? (/showthread.php?tid=387767)



OnPlayerStateChange - A code screws it up ? - Black Axe - 26.10.2012

Well.. Once I Add this :

PHP код:
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new 
vehicleid GetPlayerVehicleID(playerid),
            
playingid v_VehicleInfo[vehicleid][RadioPlaying];
        
#if USE_TEXTDRAW_SET == 2
            
new string[50];
            
format(string,sizeof(string),"Listening to: ~n~~w~%s",r_RadioInfo[playingid][r_Name]);
            
TextDrawSetString(v_VehicleInfo[vehicleid][r_Draw],string);
        
#else
            
TextDrawSetString(v_VehicleInfo[vehicleid][r_Draw],r_RadioInfo[playingid][r_Name]);
        
#endif
        
TextDrawShowForPlayer(playerid,v_VehicleInfo[vehicleid][r_Draw]);
        
SetPVarInt(playerid,"ID_HideRadioTextdraw",SetTimerEx("HideRadioTextdraw",TEXTDRAW_DISAPPEAR_TIME,false,"ii",playerid,vehicleid));
        
PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
        
SetPVarInt(playerid,"ID_OldVehicle",vehicleid);
        return 
1;
    }
    if(
oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
    {
        new 
vehicleid GetPVarInt(playerid,"ID_OldVehicle"),
            
timer GetPVarInt(playerid,"ID_HideRadioTextdraw");
        if(
timer != -1)
        {
            
TextDrawHideForPlayer(playerid,v_VehicleInfo[vehicleid][r_Draw]);
            
KillTimer(timer);
        }
        
StopAudioStreamForPlayer(playerid);
    } 
Under OnPlayerStateChange..


Everything UNDER this code Never works again :S.. I Thought it would be because of return 1;.. And ye - That was the problem... But removing return 1; ****s up the code itself.. Any ideas ?


Re: OnPlayerStateChange - A code screws it up ? - Glad2BeHere - 26.10.2012

#endif are u making a filterscript? move that and if it should be at the bottom of the script if itz a filterscript if not move it

PHP код:
#endif
and #if ??
use if(textdraw stuff



Re: OnPlayerStateChange - A code screws it up ? - Black Axe - 26.10.2012

Edit : Nevermind - I made it in a FS First then moved it to the script - Thanks xD

Edit 2 : Agh.. Sorry but I Don't get it - Can you explain more how to fix it ? xD - I am still a newbie


Re: OnPlayerStateChange - A code screws it up ? - jessejanssen - 26.10.2012

I made the code a little easier to read for you.

I don't see why removing the "return 1;" should give any errors, this code should work perfectly fine.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
        {
        new vehicleid = GetPlayerVehicleID(playerid),
        playingid = v_VehicleInfo[vehicleid][RadioPlaying];
        if(USE_TEXTDRAW_SET == 2)
            {
            new string[50];
            format(string,sizeof(string),"Listening to: ~n~~w~%s",r_RadioInfo[playingid][r_Name]);
            TextDrawSetString(v_VehicleInfo[vehicleid][r_Draw],string);
            }
        else
            {
            TextDrawSetString(v_VehicleInfo[vehicleid][r_Draw],r_RadioInfo[playingid][r_Name]);
            }
        TextDrawShowForPlayer(playerid,v_VehicleInfo[vehicleid][r_Draw]);
        SetPVarInt(playerid,"ID_HideRadioTextdraw",SetTimerEx("HideRadioTextdraw",TEXTDRAW_DISAPPEAR_TIME,false,"ii",playerid,vehicleid));
        PlayAudioStreamForPlayer(playerid,r_RadioInfo[playingid][r_Link]);
        SetPVarInt(playerid,"ID_OldVehicle",vehicleid);
        }
    if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
        new vehicleid = GetPVarInt(playerid,"ID_OldVehicle"),
            timer = GetPVarInt(playerid,"ID_HideRadioTextdraw");
        if(timer != -1)
            {
            TextDrawHideForPlayer(playerid,v_VehicleInfo[vehicleid][r_Draw]);
            KillTimer(timer);
            }
        StopAudioStreamForPlayer(playerid);
        }
}
Jesse

EDIT:
Just seen the replies, FML xD


Re: OnPlayerStateChange - A code screws it up ? - Black Axe - 26.10.2012

Jesse - Your code is showing those 2 warnings

PHP код:
D:\Folder\gamemodes\MyScript.pwn(27724) : warning 206redundant testconstant expression is non-zero
D
:\Folder\gamemodes\MyScript.pwn(27726) : warning 219local variable "string" shadows a variable at a preceding level 



Re: OnPlayerStateChange - A code screws it up ? - jessejanssen - 26.10.2012

Quote:
Originally Posted by Black Axe
Посмотреть сообщение
Jesse - Your code is showing those 2 warnings

PHP код:
D:\Folder\gamemodes\MyScript.pwn(27724) : warning 206redundant testconstant expression is non-zero
D
:\Folder\gamemodes\MyScript.pwn(27726) : warning 219local variable "string" shadows a variable at a preceding level 
I am guessing line 27724 is: " if(USE_TEXTDRAW_SET == 2)"
And if I am right I am also guessing that "USE_TEXTDRAW_SET" is a "#define" instead of an variable ( "new USE_TEXTDRAW_SET;" )
Because it's defined and not a variable ( A number which can change. ) it's a constant number ( It will always be the same. ) so the warning tells you that the "if" statement isn't needed and doesn't work as it will always be true or false.

For the second warning, that probably means that you have a global variable ( A variable created somewhere in the script out of the functions and publics etc etc. ) or that there's another "new string[number here];" in your OnPlayerKeyStateChange.

Jesse


Re: OnPlayerStateChange - A code screws it up ? - Black Axe - 26.10.2012

You are awesome - Thanks , Really


Re: OnPlayerStateChange - A code screws it up ? - jessejanssen - 26.10.2012

Haha - You're welcome, really! :P

Jesse