[Help] /hotwire system
#1

Hello so i got this hotwire command and i want it to be 50% chance of it starting so if i do /hotwire it would say something underdashboard and that and if it fails it will say "PlayerA tweaks with the vehicle wires and gets shocked" something like that but if the player gets it then the car will start and this is only for unowned cars or if a player leaves his car unlocked and if it starts it will say "PlayerA tweaks with the vehicle wires((Engine starts))"





Код:
command(hotwire, playerid, params[])
{
	new string[128];
    new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid,realvehicleid;
    vehicleid = GetVehicleFileIDEx(playerid, GetPlayerVehicleID(playerid));
    realvehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(realvehicleid,engine,lights,alarm,doors,bonnet,boot,objective);

    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, WHITE, "You are not in a vehicle!");
    if(engine == VEHICLE_PARAMS_ON)
    {
        return SendClientMessage(playerid, WHITE, "You cannot hotwire a vehicle that is already on.");
    }
    else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
    {
        format(string, sizeof(string), "** %s tweaks with the vehicle's wires under the dashboard.", GetName(playerid));
        NearByMessage(playerid, SCRIPTPURPLE, string);
        SetTimerEx("SetVehicleEngine", 1700, 0, "dd",  vehicleid, playerid);
        CarHotwireStatus{vehicleid} = 1;
    }
	return 1;
}
Reply
#2

You don't use the vehicle params ?
For a system of 50% chance, you can use random(2), it returns 0 or 1.
Reply
#3

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
You don't use the vehicle params ?
For a system of 50% chance, you can use random(2), it returns 0 or 1.
So what do i have to do?
Reply
#4

PHP код:
command(hotwireplayeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridWHITE"You are not in a vehicle!");
    
    new    
        
realvehicleid GetPlayerVehicleID(playerid),
        
vehicleid GetVehicleFileIDEx(playeridrealvehicleid);
    
    static 
        
engine,
        
lights,
        
alarm,
        
doors,
        
bonnet,
        
boot,
        
objective;
    
    
GetVehicleParamsEx(realvehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(
engine == VEHICLE_PARAMS_ON) return SendClientMessage(playeridWHITE"You cannot hotwire a vehicle that is already on.");
    
    if((
engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
    {        
        static
            
string[128];
    
        if(
random(2))
        {
            
// message
        
            
return 1;
        }
    
        
format(stringsizeof(string), "** %s tweaks with the vehicle's wires under the dashboard."GetName(playerid));
        
NearByMessage(playeridSCRIPTPURPLEstring);
        
        
SetTimerEx("SetVehicleEngine"17000"dd",  vehicleidplayerid);
        
        
CarHotwireStatus{vehicleid} = 1;
    }
    
    return 
1;

Reply
#5

Like Dutheil what said you can use the random function.
Example:
pawn Код:
command(hotwire, playerid, params[])
{
    new string[128];
    new engine,lights,alarm,doors,bonnet,boot,objective,vehicleid,realvehicleid;
    vehicleid = GetVehicleFileIDEx(playerid, GetPlayerVehicleID(playerid));
    realvehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(realvehicleid,engine,lights,alarm,doors,bonnet,boot,objective);

    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, WHITE, "You are not in a vehicle!");
    if(engine == VEHICLE_PARAMS_ON)
    {
        return SendClientMessage(playerid, WHITE, "You cannot hotwire a vehicle that is already on.");
    }
    else if((engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
    {
        new hwrand=random(2);
        if(hwrand==0)
        {
            format(string, sizeof(string), "** %s tweaks with the vehicle's wires under the dashboard.", GetName(playerid));
            NearByMessage(playerid, SCRIPTPURPLE, string);
            SetTimerEx("SetVehicleEngine", 1700, 0, "dd",  vehicleid, playerid);
            CarHotwireStatus{vehicleid} = 1;
            //succeeded
            return 1;
        }
        else
        {
            //failed
            //Do stuff here like a sendclientmessage(playerid,COLOR_RED,"You have failed to hotwire this vehicle");
            return 1;
        }
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
PHP код:
command(hotwireplayeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridWHITE"You are not in a vehicle!");
    
    new    
        
realvehicleid GetPlayerVehicleID(playerid),
        
vehicleid GetVehicleFileIDEx(playeridrealvehicleid);
    
    static 
        
engine,
        
lights,
        
alarm,
        
doors,
        
bonnet,
        
boot,
        
objective;
    
    
GetVehicleParamsEx(realvehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(
engine == VEHICLE_PARAMS_ON) return SendClientMessage(playeridWHITE"You cannot hotwire a vehicle that is already on.");
    
    if((
engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
    {        
        static
            
string[128];
    
        if(
random(2))
        {
            
// message
        
            
return 1;
        }
    
        
format(stringsizeof(string), "** %s tweaks with the vehicle's wires under the dashboard."GetName(playerid));
        
NearByMessage(playeridSCRIPTPURPLEstring);
        
        
SetTimerEx("SetVehicleEngine"17000"dd",  vehicleidplayerid);
        
        
CarHotwireStatus{vehicleid} = 1;
    }
    
    return 
1;

you must do switch(random(2)) and case 0 & 1.
Reply
#7

Use this code, it is optimized and it works :

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
PHP код:
command(hotwireplayeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridWHITE"You are not in a vehicle!");
    
    new    
        
realvehicleid GetPlayerVehicleID(playerid),
        
vehicleid GetVehicleFileIDEx(playeridrealvehicleid);
    
    static 
        
engine,
        
lights,
        
alarm,
        
doors,
        
bonnet,
        
boot,
        
objective;
    
    
GetVehicleParamsEx(realvehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(
engine == VEHICLE_PARAMS_ON) return SendClientMessage(playeridWHITE"You cannot hotwire a vehicle that is already on.");
    
    if((
engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET))
    {        
        static
            
string[128];
    
        if(
random(2))
        {
            
// message
        
            
return 1;
        }
    
        
format(stringsizeof(string), "** %s tweaks with the vehicle's wires under the dashboard."GetName(playerid));
        
NearByMessage(playeridSCRIPTPURPLEstring);
        
        
SetTimerEx("SetVehicleEngine"17000"dd",  vehicleidplayerid);
        
        
CarHotwireStatus{vehicleid} = 1;
    }
    
    return 
1;

Reply
#8

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
Use this code, it is optimized and it works :
Okay so when it that line that says

Код:
 if(random(2)) 
        { 
            // message 
         
            return 1; 
        }
the //message what do i use that for?
Reply
#9

Quote:
Originally Posted by BigGreen
Посмотреть сообщение
Okay so when it that line that says

PHP код:
 if(random(2)) 
        { 
            
// message 
         
            
return 1
        } 
the //message what do i use that for?
You can use this:
PHP код:
SendClientMessage(playerid,COLOR_RED,"You have failed to hotwire this vehicle."); 
Reply
#10

Dutheil, because i'm new in samp can you told me what value can return GetVehicleFileIDExgive? give me the min & max.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)