Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    2. News

    1. Red Dead Redemption 2

    1. GTA Online

      1. After Hours
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

OfficerJohnson

[LUA][Information Request] SET_PED_AS_COP

Recommended Posts

OfficerJohnson

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)) thenPED.SET_PED_AS_COP(playerPed, true);endendreturn 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.

 

Share this post


Link to post
Share on other sites
nm710
Posted (edited)

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.

 

 

 

local Reload = {}function Reload.tick()	if(get_key_pressed(123)) then		loadAddIns()		loadLibs() -- this can let you experiment with the libs folder		wait(999)		Reload.text("Lua Script Reloaded", 0.4, 0.4, 0.5)	endendfunction Reload.text(text,x,y,scale)      UI.SET_TEXT_FONT(0)      UI.SET_TEXT_SCALE(scale, scale)      UI.SET_TEXT_COLOUR(1, 1, 255, 255)      UI.SET_TEXT_CENTRE(false)      UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)      UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)      UI._SET_TEXT_ENTRY("STRING")      UI._ADD_TEXT_COMPONENT_STRING(text)      UI._DRAW_TEXT(x,y)endreturn Reload

 

 

 

 

Edited by nm710

Share this post


Link to post
Share on other sites
OfficerJohnson

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.

 

 

 

 

 

 

local Reload = {}function Reload.tick()	if(get_key_pressed(123)) then		loadAddIns()		loadLibs() -- this can let you experiment with the libs folder		wait(999)		Reload.text("Lua Script Reloaded", 0.4, 0.4, 0.5)	endendfunction Reload.text(text,x,y,scale)      UI.SET_TEXT_FONT(0)      UI.SET_TEXT_SCALE(scale, scale)      UI.SET_TEXT_COLOUR(1, 1, 255, 255)      UI.SET_TEXT_CENTRE(false)      UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)      UI.SET_TEXT_EDGE(0, 0, 0, 0, 0)      UI._SET_TEXT_ENTRY("STRING")      UI._ADD_TEXT_COMPONENT_STRING(text)      UI._DRAW_TEXT(x,y)endreturn Reload

 

 

 

 

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).

Share this post


Link to post
Share on other sites
nm710

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 player, int wantedLevel, BOOL disableNoMission). disableNoMission should be set to false according to the nativedb. And right after that code use PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(Player player, BOOL 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.

Edited by nm710

Share this post


Link to post
Share on other sites
OfficerJohnson

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 player, int wantedLevel, BOOL disableNoMission). disableNoMission should be set to false according to the nativedb. And right after that code use PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(Player player, BOOL 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.

Share this post


Link to post
Share on other sites
nm710

No problem, glad to help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.