Variable returns value 0 ?
#1

Hello all!

I was making myself a new command yesterday, when i noticed something strange, actually very strange. I dont know if i put anything wrong, but here is the code:

pawn Код:
CMD:passenger (playerid,params[])
{
    new driver;
    new string123[165];
    new veh = GetPlayerVehicleID(driver);  // ------- Thats the Variable i used in PutPlayerInVehicle, to get vehicle ID...
   
    if (PlayerInfo[playerid][aLevel] < 1)
        return SendClientMessage(playerid, RED, "Only Administrators level 1+ can use this command");
    if(sscanf(params, "i",driver))
        return SendClientMessage(playerid, RED, "Hello Admin! Usage: "corange"/PASSENGER [Playerid]");
        //Is he connected?
    if(!IsPlayerConnected(driver))
        return SendClientMessage(playerid, RED, "Player is not found.");
        //Check if it is yourself
    if(driver == playerid)
        return SendClientMessage(playerid, RED, "You cant do this command on yourself!");
        //Check if he is in vehicle
    if(!IsPlayerInAnyVehicle(driver))
        return SendClientMessage(playerid, RED, "Selected player is not in any vehicle.");
    if((GetPlayerState(driver) == PLAYER_STATE_DRIVER) == false)
        return SendClientMessage(playerid, RED, "Selected player is not the Vehicle driver.");
    if(GetTeam{playerid} == CLASS_COPS ||GetTeam{playerid} == CLASS_CIA || GetTeam{playerid} == CLASS_FBI
            && GetTeam{driver} == CLASS_CIV && GetPlayerWantedLevel(driver) >=1)
                return SendClientMessage(playerid, RED, "Selected Player is currently wanted, and you are a Cop. Function is Disabled, try again later (prevent abusing)");//Check if you are a cop AND that the entered player is wanted.
   
    //If nothing of above stopped the admin from doing the command, below is the continuos script for the command. Spunky.
    // put him in seat 1, passenger, in the drivers vehicle id
   
    PutPlayerInVehicle(playerid, veh, 1); // Here it is
   
    //DEBUGGING;
    new string11[128];
    new string111[128];
    format(string11, sizeof(string11), "Variable veh = %d", veh);
    SendClientMessageToAll(RED, string11);
    format(string111, sizeof(string111), "Variable driver id = %d", driver);
    SendClientMessageToAll(RED, string111);
    //____________________________________________________________________
   
    //If it didnt work correctly, this message will appear:
    if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
        return SendClientMessage(playerid, RED, "An error occured. Please contact the Scripter");
        //successful:
    else if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        format(string123, sizeof(string123), "You have now successfully entered the car as a passenger with player id %s", driver);
        SendClientMessage(playerid, GREEN, string123);//message
    }
    return 1;
}
As you can see, i used a Variable named "veh" in the script, to get the player vehicle ID. I was having trouble with the code, so i started debugging the values if the "veh" and the "driver" were correct.

Suprisingly enough, the driver ID was correct, but the value for the "Veh" variable was 0 all the time, on everyone i tested. (They was in a car, i added a check in the code)

So, is this a bug, or did i put my variable the wrong way? Please explain if so.


Thanks.



-
Reply
#2

pawn Код:
new driver = params[0];
You never assigned the driver variable meaning it always stayed 0
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
airplanesimen: That's not how variables work - just because two have the same name doesn't make them the same! It's like two people called "Mark" are not the same person, and if you make a new person and call it Mark, it doesn't instantly become the other two.

park4bmx: That's not how "params" works!
Okay, thanks for reply. I have scripted quite a few codes lately, and i simply didnt notice this before now. So, what could the correct solution be? Could i do it like this:

pawn Код:
new veh;
if(sscanf(params,"u",driver) return ...................
veh = GetPlayerVehicleID(driver);
?
Reply
#4

Why don't you just try it and see for yourself? Also: Unless you intend to use this with bots, you may use 'r' instead of 'u'.
Reply
#5

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Why don't you just try it and see for yourself? Also: Unless you intend to use this with bots, you may use 'r' instead of 'u'.
I could try yes, but that would be later cause i am behind a school proxy

And thanks Larzi, will do

Regards!

[SOLVED]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)