Just for people trying to get into scripting and wondering why peoples mods can control other peoples cars, heres some functions to do with getting control of cars
first add these to your natives.h file, they arent all needed for this, but there just a few useful ones added
how i get control of a network idCode:extern bool REQUEST_CONTROL_OF_NETWORK_ID(int netid); extern void GET_PED_FROM_NETWORK_ID(int netid, Ped *ped); extern void GET_VEHICLE_FROM_NETWORK_ID(int netid, Vehicle *vehicle); extern void GET_OBJECT_FROM_NETWORK_ID(int netid, Object *obj); extern void GET_NETWORK_ID_FROM_PED(Ped ped, int *netid); extern void GET_NETWORK_ID_FROM_OBJECT(Object obj, int *netid); extern void GET_NETWORK_ID_FROM_VEHICLE(Vehicle vehicle, int *netid); extern bool DOES_OBJECT_EXIST_WITH_NETWORK_ID(int netid); extern bool DOES_VEHICLE_EXIST_WITH_NETWORK_ID(int netid); extern bool DOES_PED_EXIST_WITH_NETWORK_ID(int netid); extern bool HAS_CONTROL_OF_NETWORK_ID(int netid); extern void SET_NETWORK_ID_CAN_MIGRATE(int netid, bool value); extern bool IS_NETWORK_SESSION(void); extern void SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(int netid, bool value); extern void SET_PED_EXISTS_ON_ALL_MACHINES(Ped ped, bool exists); extern void SET_OBJECT_EXISTS_ON_ALL_MACHINES(Object obj, bool exists); extern void SET_CAR_EXISTS_ON_ALL_MACHINES(Vehicle vehicle, bool exists); extern bool DOES_PLAYER_HAVE_CONTROL_OF_NETWORK_ID(Player player, int netid);
then to use this on other players cars use this or similar, note im not showing how to get the handle for another players vehicle here(for noobs what pVehicle is)Code:bool getconrtol(int networkid){ if (!IS_NETWORK_SESSION())return true; //included so the script will also work offline if (HAS_CONTROL_OF_NETWORK_ID(networkid))return true; int count; while(!HAS_CONTROL_OF_NETWORK_ID(networkid) && count <1000){ REQUEST_CONTROL_OF_NETWORK_ID(networkid); count++; WAIT(0); } return HAS_CONTROL_OF_NETWORK_ID(networkid); }
note this will work for ped/object handles, but you cant take control of a players ped using this method, and things like GET_CLOSEST_CHAR dont work for spawned peds and grabbing object handles is rather confusing, but possible. but if you figure it out the natives are pretty similar GET_NETWORK_ID_FROM_OBJECT(object, &netid); GET_NETWORK_ID_FROM_PED(ped, &netid);Code:Vehicle pVehicle; int netid; GET_NETWORK_ID_FROM_VEHICLE(pVehicle, &netid); if (getcontrol(netid)){ SET_NETWORK_ID_CAN_MIGRATE(netid, 0);//only necessary if you wanna do things that take a while, like apply a force to their car, wait, then delete it or similar //insert all the crap stuff you wanna do to it SET_CAR_VISIBLE(pVehicle, 0);//just to see it working SET_NETWORK_ID_CAN_MIGRATE(netid, 1);//same with line above, if that isnt included, dont include this }
how to protect yourself from this happening to your car, best run on each cycle so it refreshes itself when you get in another car, and lets other people drive the car when you leave it
rather not use that all the time and want to find out who is taking control of your car and trying to abuse their mods instead, use this then which will print the name of the person who has control of a car that you are in the driver seat ofCode:int vehicle, id, driver, you; bool protect; void protection(void){ you = GetPlayerPed(); GET_CAR_CHAR_IS_USING(you,&vehicle); if(DOES_VEHICLE_EXIST(vehicle)){ if(!protect){ GET_DRIVER_OF_CAR(vehicle,&driver); if(driver == you){ GET_NETWORK_ID_FROM_VEHICLE(vehicle,&id); if(HAS_CONTROL_OF_NETWORK_ID(id)){ SET_NETWORK_ID_CAN_MIGRATE(id,false); protect = true; } } } } else if(protect && HAS_CONTROL_OF_NETWORK_ID(id)){ SET_NETWORK_ID_CAN_MIGRATE(id,true); protect = false; } }
Code:void checkcar(void){ int vehicle, you = GetPlayerPed(), driver, netid, player; GET_CAR_CHAR_IS_USING(you, &vehicle); if (!DOES_VEHICLE_EXIST(vehicle))return; GET_DRIVER_OF_CAR(vehicle, &driver); if (driver != you)return; GET_NETWORK_ID_FROM_VEHICLE(vehicle, &netid); if (HAS_CONTROL_OF_NETWORK_ID(netid))return; for(player=0;player<16;player++){ if (!IS_NETWORK_PLAYER_ACTIVE(player))continue; if (player == you)continue; if (DOES_PLAYER_HAVE_CONTROL_OF_NETWORK_ID(player, netid)){ PRINT_STRING_WITH_TWO_LITERAL_STRINGS_NOW("STRING", GET_PLAYER_NAME(player), " has taken control of your car", 2500, 1);//some people seem to have trouble with this native, i never have but if you do, use the one below instead, it just shows their name, nothing else //PRINT_STRING_WITH_LITERAL_STRING_NOW("STRING", GET_PLAYER_NAME(player), 2500, 1); return;} } }


13Likes
LinkBack URL
About LinkBacks






...thanks zorg93


