OnPlayerStateChange - A code screws it up ?
#1

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 ?
Reply
#2

#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
Reply
#3

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
Reply
#4

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
Reply
#5

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 
Reply
#6

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
Reply
#7

You are awesome - Thanks , Really
Reply
#8

Haha - You're welcome, really! :P

Jesse
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)