Quantcast

Jump to content

» «
Photo

[LUA][Information Request] SET_PED_AS_COP

Best Answer nm710, 10 January 2018 - 05:47 AM

I ran your code and I did find an error. Change "get_keypressed" to "get_key_pressed", I also didn't catch it at first glance. The rest works, but what I noticed was that it only trick cops that the player is not there, but not swats. Also if you bump into them they will start shooting you. I think you should combine it with PLAYER.SET_PLAYER_WANTED_LEVEL(Player playerint wantedLevelBOOL disableNoMission). disableNoMission should be set to false according to the nativedb. And right after that code use PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(Player playerBOOL p1) to have an immediate effect.

 

Although this function did work, I still think Lua has less support. For example, sometimes the names in the nativedb change but since LUA uses the outdated names it doesn't work on certain functions. I also learned lua before learning C# with the same reason as you. I think your making a good choice, I'm just advising you not to feel overwhelmed by a new coding language, I was hesitant for that reason when I started. For lua source codes you could find some on gta5-mods.com, I learned a lot from Ideo's lua codes. 

Go to the full post


6 replies to this topic
OfficerJohnson
  • OfficerJohnson

    Crackhead

  • Members
  • Joined: 07 Jan 2018
  • United-States

#1

Posted 07 January 2018 - 05:59 AM

Hello everyone. I'm new to GTA V scripting and want to make some cool mods revolving around the police in-game. My first objective is to set my player up to be a cop. I found this native: SET_PED_AS_COP and would like to use it. 

 

Currently, my script does not work and I'm not advanced enough to understand why. I'm programming in LUA ATM, so please show examples in LUA.

 

Here's what I have so far: 

 

local CopPed = {};
toggle_keycode = 121;


function CopPed.tick()
    local playerPed = PLAYER.PLAYER_PED_ID();
local player = PLAYER.GET_PLAYER_PED(playerPed);
local playerExists = ENTITY.DOES_ENTITY_EXIST(playerPed);
local pentityHealth = ENTITY.GET_ENTITY_HEALTH(playerPed);


if (get_keypressed(toggle_keycode)) then
PED.SET_PED_AS_COP(playerPed, true);


end
end


return CopPed;

I don't know why it's not working. I know it's not because, when I commit a crime, I don't have the cone of sight appear around my character and whatnot. I also get shot at by the police.

 


nm710
  • nm710

    None

  • Members
  • Joined: 15 Aug 2016
  • United-States

#2

Posted 08 January 2018 - 06:09 PM Edited by nm710, 08 January 2018 - 06:14 PM.

Everything in your code looks fine to me but LUA could be frustrating sometimes because it lacks support. I used to code in lua and was very frustrated when a simple function, like what you're trying to do, doesn't work. I suggest you start learning C#, it's a much better language and has a lot of support because of scripthookdotnet. Since I'm a beginner as well, I remember how hard it felt to even get my self to start learning C# for GTAV, so I understand if you want to continue using lua. If you do want to keep using lua, here is a little script that made it so much easier. Not sure if you have it, but it just lets reloads your lua scripts after pressing F12, it can allow you to do it ingame, however if there is an error in your code it will not . This may not solve your problem, but I hope it helps you in this code and future codes.

 

Spoiler
  • OfficerJohnson likes this

OfficerJohnson
  • OfficerJohnson

    Crackhead

  • Members
  • Joined: 07 Jan 2018
  • United-States

#3

Posted 10 January 2018 - 02:05 AM

Everything in your code looks fine to me but LUA could be frustrating sometimes because it lacks support. I used to code in lua and was very frustrated when a simple function, like what you're trying to do, doesn't work. I suggest you start learning C#, it's a much better language and has a lot of support because of scripthookdotnet. Since I'm a beginner as well, I remember how hard it felt to even get my self to start learning C# for GTAV, so I understand if you want to continue using lua. If you do want to keep using lua, here is a little script that made it so much easier. Not sure if you have it, but it just lets reloads your lua scripts after pressing F12, it can allow you to do it ingame, however if there is an error in your code it will not . This may not solve your problem, but I hope it helps you in this code and future codes.
 

Spoiler

I appreciate the reply. I have something similar to this but I'll use yours you supplied instead because it's a bit more robust. The only reason I'm starting with LUA is because the source is bit easier to obtain and learn from. With C# it is not. However, I have been looking at C# code and it is much more supported.

So you think LUA may just not support what I'm trying to do? I have used it on spawned Peds and it worked just fine (aiming at them gave me wanted level).

nm710
  • nm710

    None

  • Members
  • Joined: 15 Aug 2016
  • United-States

#4

Posted 10 January 2018 - 05:47 AM   Best Answer Edited by nm710, 10 January 2018 - 05:48 AM.

I ran your code and I did find an error. Change "get_keypressed" to "get_key_pressed", I also didn't catch it at first glance. The rest works, but what I noticed was that it only trick cops that the player is not there, but not swats. Also if you bump into them they will start shooting you. I think you should combine it with PLAYER.SET_PLAYER_WANTED_LEVEL(Player playerint wantedLevelBOOL disableNoMission). disableNoMission should be set to false according to the nativedb. And right after that code use PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(Player playerBOOL p1) to have an immediate effect.

 

Although this function did work, I still think Lua has less support. For example, sometimes the names in the nativedb change but since LUA uses the outdated names it doesn't work on certain functions. I also learned lua before learning C# with the same reason as you. I think your making a good choice, I'm just advising you not to feel overwhelmed by a new coding language, I was hesitant for that reason when I started. For lua source codes you could find some on gta5-mods.com, I learned a lot from Ideo's lua codes. 


OfficerJohnson
  • OfficerJohnson

    Crackhead

  • Members
  • Joined: 07 Jan 2018
  • United-States

#5

Posted 10 January 2018 - 06:58 AM

I ran your code and I did find an error. Change "get_keypressed" to "get_key_pressed", I also didn't catch it at first glance. The rest works, but what I noticed was that it only trick cops that the player is not there, but not swats. Also if you bump into them they will start shooting you. I think you should combine it with PLAYER.SET_PLAYER_WANTED_LEVEL(Player playerint wantedLevelBOOL disableNoMission). disableNoMission should be set to false according to the nativedb. And right after that code use PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(Player playerBOOL p1) to have an immediate effect.

 

Although this function did work, I still think Lua has less support. For example, sometimes the names in the nativedb change but since LUA uses the outdated names it doesn't work on certain functions. I also learned lua before learning C# with the same reason as you. I think your making a good choice, I'm just advising you not to feel overwhelmed by a new coding language, I was hesitant for that reason when I started. For lua source codes you could find some on gta5-mods.com, I learned a lot from Ideo's lua codes. 

Thanks for running it.

Good eye. Thank you.

For some reason, SWAT and Army are like different groups or something. What I think happens is that they are not truly part of the law enforcement group. I think they are given the same native or something. IDK. It's too complex for me to understand rn, but I have noticed that particular thing since you could soft-mod your player model on consoles. 

Okay. I will try the two you suggested. Thanks for all your help.

  • nm710 likes this

nm710
  • nm710

    None

  • Members
  • Joined: 15 Aug 2016
  • United-States

#6

Posted 10 January 2018 - 04:15 PM

No problem, glad to help. 


Fun 2
  • Fun 2

    Boss

  • Members
  • Joined: 30 Sep 2013
  • None
  • Best Contributor in GTA Online 2017
    Most Knowledgeable in GTA 2015
    Most Helpful Member 2015
    Coolest Member 2015

#7

Posted 11 January 2018 - 10:43 PM

You have to use
SET_PED_RELATIONSHIP_GROUP_HASH
Check out this thread:
http://gtaforums.com...s-from-fleeing/

Set your relationship group to "cop"





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users