[Tutorial] Vehicle Ownership With Mysql & SScanf
#21

Good job. Though.. what if there is 1..2..3..4k Cars being reloaded.. Going to cause lag regardless. But minimize it some by changing "for(new i; i < SCRIPT_CARS; i++)" to "foreach(customthing, i)" Not sure if it applies to this. Might remove some lag. Might not.

Other then that. Great job.
Reply
#22

Quote:
Originally Posted by iTorran
View Post
I did it all and when i go ingame and type /createveh 562 my server closes..
There is no reports on the server log.
I'm not sure if thats related to this tutorial, as when i made it, it worked perfectly for me.

Quote:
Originally Posted by DiddyBop
View Post
Good job. Though.. what if there is 1..2..3..4k Cars being reloaded.. Going to cause lag regardless. But minimize it some by changing "for(new i; i < SCRIPT_CARS; i++)" to "foreach(customthing, i)" Not sure if it applies to this. Might remove some lag. Might not.

Other then that. Great job.
I'm Having about 600 cars loaded from mysql, don't notice lagg at all.. And the max limit for cars is 2k.

Thanks anyway
Reply
#23

Ok ive got it working but ive hit a problem..
I'd normally know how to do this but i just cant think of anything atm.
Anyway i dont know how to restrict a car i created to 1 name.
I tried this:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(strcmp(GetName(playerid), VehicleInfo[vehicleid][Owner], true) == 0)
        {
            return 1;
        }
        else
        {
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
But that kicks me out no-matter.
Do anyone know how?
Reply
#24

pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
     if(strmatch(VehicleInfo[vehicleid][Owner], GetName(playerid)))
     {
          return 1;
     }
     else
     {
          // clear animations, cant be bothered searching it up x))
     }
     return 1;
}

stock strmatch(const String1[], const String2[])
{
    if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
    {
        return true;
    }
    else
    {
        return false;
    }
}
Should work.
Reply
#25

Quote:
Originally Posted by Cameltoe
View Post
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
     if(strmatch(VehicleInfo[vehicleid][Owner], GetName(playerid)))
     {
          return 1;
     }
     else
     {
          // clear animations, cant be bothered searching it up x))
     }
     return 1;
}

stock strmatch(const String1[], const String2[])
{
    if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
    {
        return true;
    }
    else
    {
        return false;
    }
}
Should work.
Getting the same result..
Reply
#26

Try printf("%s",VehicleInfo[vehicleid][Owner]) to see if the owner actually gets loaded.
Reply
#27

When i do: /createveh Torran

I edited it btw to save owner not model,
Anyway when i do that i get sscanf warning and it dosent show the print that i told it to.
And when i get in the vehicle where its supposed to print i also get the sscanf error.
And when i /reloadvehicles it shows the vehicle owner name.
Reply
#28

Whats the problem ?

pawn Code:
sscanf(Query, "p<|>e<is[25]iiffffiii>", VehicleInfo[id]); //78
pawn Code:
enum vInfo
{
     vId,
     vOwner[25],
     vModel,
     vPrice,
     vFloat:X,
     vFloat:Y,
     vFloat:Z,
     vFloat:A,
     vColor1,
     vColor2,
     vLocked,
}
new VehicleInfo[MAX_VEH][vInfo];
pawn Code:
C:\Documents and Settings\XP4ever\Asztal\samp\filterscripts\carsystem.pwn(78) : error 017: undefined symbol "VehicleInfo"
C:\Documents and Settings\XP4ever\Asztal\samp\filterscripts\carsystem.pwn(78) : warning 215: expression has no effect
C:\Documents and Settings\XP4ever\Asztal\samp\filterscripts\carsystem.pwn(78) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\XP4ever\Asztal\samp\filterscripts\carsystem.pwn(78) : error 029: invalid expression, assumed zero
C:\Documents and Settings\XP4ever\Asztal\samp\filterscripts\carsystem.pwn(78) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Reply
#29

@iTorran try this:
pawn Code:
public OnPlayerStateChange(playerid)
{
    new playername[MAX_PLAYERNAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new namestring = strfind(playername,VehicleInfo[vehicleid][Owner],true);
        if(namestring == -1)
        {
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Reply
#30

Can someone post an example.pwn cause i cant get it right :/ Im noob to mysql and pwn.
Reply
#31

I had some errors, but it was helpful
hopefully figuring out them soon..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)