How to make it in onplayerconnect
#1

heloo,
i had a problem with a stock
this stock is to create vehicle when starting the server.
i need to make it onplayerconnect . so when each player connect there vehicles will be loaded so threby less lag on server

here is the stock
PHP код:
stock AddPlayerVehicles()
{
    new 
Str[750], vTotalvehIDvehModelFloat:vehXFloat:vehYFloat:vehZFloat:vehAvehC1vehC2vehOwnedBy[24], ForSaleDefaultPricePriceLocked;
    new 
carmod[17];
    
mysql_reconnect();
 
mysql_query("SELECT * FROM `pvehicles`");
    
mysql_store_result();
    
vTotal mysql_num_rows();
    new 
carid 0;
    if(
vTotal 0)
    {
        while(
mysql_fetch_row(Str))
        {
            
sscanf(Str"p<|>dds[24]ffffdddddddddddddddddddddddd",
            
vehID,vehModel,vehOwnedBy,vehX,vehY,vehZ,vehA,vehC1,vehC2,ForSale,DefaultPrice,Price,Locked,carmod[0],carmod[1],carmod[2],carmod[3],carmod[4],carmod[5],carmod[6],carmod[7],carmod[8],carmod[9],carmod[10],carmod[11],carmod[12],carmod[13],carmod[14],carmod[15],carmod[16]);
               
carid=vehID;
            new 
carid2 CreateVehicle(vehModelvehXvehYvehZvehAvehC1vehC2, (30 60));
            
PVInfo[carid][vpID] = vehID;
            
PVInfo[carid][vpPosX] = vehX;
            
PVInfo[carid][vpPosY] = vehY;
            
PVInfo[carid][vpPosZ] = vehZ;
            
PVInfo[carid][vpPosA] = vehA;
            
PVInfo[carid][vpColor1] = vehC1;
            
PVInfo[carid][vpColor2] = vehC2;
            
PVInfo[carid][vpModel] = vehModel;
            
PVInfo[carid][vpForSale] = ForSale;
            
PVInfo[carid][vpDefaultPrice] = DefaultPrice;
            
PVInfo[carid][vpPrice] = Price;
            
PVInfo[carid][vpLocked] = Locked;
            
PVInfo[carid2][mod1] = carmod[0];
            
PVInfo[carid2][mod2] = carmod[1];
            
PVInfo[carid2][mod3] = carmod[2];
            
PVInfo[carid2][mod4] = carmod[3];
            
PVInfo[carid2][mod5] = carmod[4];
            
PVInfo[carid2][mod6] = carmod[5];
            
PVInfo[carid2][mod7] = carmod[6];
            
PVInfo[carid2][mod8] = carmod[7];
            
PVInfo[carid2][mod9] = carmod[8];
            
PVInfo[carid2][mod10] = carmod[9];
            
PVInfo[carid2][mod11] = carmod[10];
            
PVInfo[carid2][mod12] = carmod[11];
            
PVInfo[carid2][mod13] = carmod[12];
            
PVInfo[carid2][mod14] = carmod[13];
            
PVInfo[carid2][mod15] = carmod[14];
            
PVInfo[carid2][mod16] = carmod[15];
            
PVInfo[carid2][mod17] = carmod[16];
            
PVInfo[carid][vpVehicleSpawned] = carid2;
            
ModVehicle(carid2);
            
ModVehicle(carid);
            if(
ForSale == 1)
            {
                
format(Strsizeof(Str), "%s for sale!\nPrice: $%d (Seller: %s)\n/dealership to purchase!"GetVehicleFriendlyName(carid2),PricevehOwnedBy);
                
PVInfo[carid][vpVehicleText] = Create3DTextLabel(Str0xFFFFFFAAvehXvehYvehZ50.001);
            }
            else
            {
                
format(Strsizeof(Str), "%s\nOwner: %s"GetVehicleFriendlyName(carid2),vehOwnedBy);
                
PVInfo[carid][vpVehicleText] = Create3DTextLabel(Str0xFF8400FFvehXvehYvehZ50.001);
            }
            
Attach3DTextLabelToVehicle(PVInfo[carid][vpVehicleText], carid20.00.00.0);
            new 
string[64];
              
format(string,sizeof(string),"%s",vehOwnedBy);
            
strmid(PVInfo[carid][vpOwnedBy], string0strlen(string), 128);
            new 
engine,lights,alarm,doors,bonnet,boot,objective;
            
GetVehicleParamsEx(carid2,engine,lights,alarm,doors,bonnet,boot,objective);
            if(
Locked == 1) { SetVehicleParamsEx(carid2,engine,lights,alarm,1,bonnet,boot,objective); }
            else if(
Locked == 0) { SetVehicleParamsEx(carid2,engine,lights,alarm,0,bonnet,boot,objective); }
        }
    }
    
mysql_free_result();

Reply
#2

Quote:
Originally Posted by bugmenotlol
Посмотреть сообщение
heloo,
i had a problem with a stock
this stock is to create vehicle when starting the server.
i need to make it onplayerconnect . so when each player connect there vehicles will be loaded so threby less lag on server

here is the stock
PHP код:
stock AddPlayerVehicles()
{
    new 
Str[750], vTotalvehIDvehModelFloat:vehXFloat:vehYFloat:vehZFloat:vehAvehC1vehC2vehOwnedBy[24], ForSaleDefaultPricePriceLocked;
    new 
carmod[17];
    
mysql_reconnect();
 
mysql_query("SELECT * FROM `pvehicles`");
    
mysql_store_result();
    
vTotal mysql_num_rows();
    new 
carid 0;
    if(
vTotal 0)
    {
        while(
mysql_fetch_row(Str))
        {
            
sscanf(Str"p<|>dds[24]ffffdddddddddddddddddddddddd",
            
vehID,vehModel,vehOwnedBy,vehX,vehY,vehZ,vehA,vehC1,vehC2,ForSale,DefaultPrice,Price,Locked,carmod[0],carmod[1],carmod[2],carmod[3],carmod[4],carmod[5],carmod[6],carmod[7],carmod[8],carmod[9],carmod[10],carmod[11],carmod[12],carmod[13],carmod[14],carmod[15],carmod[16]);
               
carid=vehID;
            new 
carid2 CreateVehicle(vehModelvehXvehYvehZvehAvehC1vehC2, (30 60));
            
PVInfo[carid][vpID] = vehID;
            
PVInfo[carid][vpPosX] = vehX;
            
PVInfo[carid][vpPosY] = vehY;
            
PVInfo[carid][vpPosZ] = vehZ;
            
PVInfo[carid][vpPosA] = vehA;
            
PVInfo[carid][vpColor1] = vehC1;
            
PVInfo[carid][vpColor2] = vehC2;
            
PVInfo[carid][vpModel] = vehModel;
            
PVInfo[carid][vpForSale] = ForSale;
            
PVInfo[carid][vpDefaultPrice] = DefaultPrice;
            
PVInfo[carid][vpPrice] = Price;
            
PVInfo[carid][vpLocked] = Locked;
            
PVInfo[carid2][mod1] = carmod[0];
            
PVInfo[carid2][mod2] = carmod[1];
            
PVInfo[carid2][mod3] = carmod[2];
            
PVInfo[carid2][mod4] = carmod[3];
            
PVInfo[carid2][mod5] = carmod[4];
            
PVInfo[carid2][mod6] = carmod[5];
            
PVInfo[carid2][mod7] = carmod[6];
            
PVInfo[carid2][mod8] = carmod[7];
            
PVInfo[carid2][mod9] = carmod[8];
            
PVInfo[carid2][mod10] = carmod[9];
            
PVInfo[carid2][mod11] = carmod[10];
            
PVInfo[carid2][mod12] = carmod[11];
            
PVInfo[carid2][mod13] = carmod[12];
            
PVInfo[carid2][mod14] = carmod[13];
            
PVInfo[carid2][mod15] = carmod[14];
            
PVInfo[carid2][mod16] = carmod[15];
            
PVInfo[carid2][mod17] = carmod[16];
            
PVInfo[carid][vpVehicleSpawned] = carid2;
            
ModVehicle(carid2);
            
ModVehicle(carid);
            if(
ForSale == 1)
            {
                
format(Strsizeof(Str), "%s for sale!\nPrice: $%d (Seller: %s)\n/dealership to purchase!"GetVehicleFriendlyName(carid2),PricevehOwnedBy);
                
PVInfo[carid][vpVehicleText] = Create3DTextLabel(Str0xFFFFFFAAvehXvehYvehZ50.001);
            }
            else
            {
                
format(Strsizeof(Str), "%s\nOwner: %s"GetVehicleFriendlyName(carid2),vehOwnedBy);
                
PVInfo[carid][vpVehicleText] = Create3DTextLabel(Str0xFF8400FFvehXvehYvehZ50.001);
            }
            
Attach3DTextLabelToVehicle(PVInfo[carid][vpVehicleText], carid20.00.00.0);
            new 
string[64];
              
format(string,sizeof(string),"%s",vehOwnedBy);
            
strmid(PVInfo[carid][vpOwnedBy], string0strlen(string), 128);
            new 
engine,lights,alarm,doors,bonnet,boot,objective;
            
GetVehicleParamsEx(carid2,engine,lights,alarm,doors,bonnet,boot,objective);
            if(
Locked == 1) { SetVehicleParamsEx(carid2,engine,lights,alarm,1,bonnet,boot,objective); }
            else if(
Locked == 0) { SetVehicleParamsEx(carid2,engine,lights,alarm,0,bonnet,boot,objective); }
        }
    }
    
mysql_free_result();

Quote:

so threby less lag on server

rofl !

if player 1 connect then onplayerconnect it's called and created the cars
if player 2 connect then onplayerconnect it's called and create another cars in same place
.
.
.
.
if player 100 connect then onplayerconnect it's called and create another 100 cars in same place

that will make a terrible lags
just 20 cars in same place and in one place in server drop u FPS to 10 what about 100 cars in all server :O
Reply
#3

I think he means, 1 car for each player and it on next position from last one. Sounds like race spawns.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)